Django search for static parts of the site - django

I am planning to use Django-Haystack to add a search component to my site. This will take care of the data I have in my models.py. I however also want data which is not in a model, but part of templates to be searchable. How can I get this.

There is a django app called haystack-static-pages that should help here. It's not been updated for a while so I doubt it will work with haystack 2.0, but I hope this might be of some help to you:
https://github.com/trapeze/haystack-static-pages

Related

how to implement django haystack elasticsearch static webpages

I have a tutorial site [say JavaScript tutorial] with multiple webpages. I want to implement a search functionality for this site so that i can search for keywords and filter links [say query=callback. So filter links/pages that i have this keyword]
I have already implemented haystack+woosh this can index all the models that i have in my models.py in Django. I want to implement indexing for the webpages so that i can search through them. I know elasticsearch [i will implement models in elasticsearch as well instead of woosh. This i know how to do] can be used for this. I was looking for specific example for how to index STATIC PAGES in a site to search through them. I have gone through some tutorial and git code but don't have a clear understanding of how to implement this. Can anyone please provide links/ tutorials on how to implement elasticsearch in django TO INDEX WEBPAGES.
Thanks,
there is an extension for haystack that does exactly this: https://github.com/trapeze/haystack-static-pages
It is pretty old and no longer maintained, but you might get it to work with a little extra effort. I think this is a good solution.
Another solution would be to include all text in a simple Content Management System like Wagtail or Mezzanine. In the most basic implementation, you can refactor your static files to templates and just replace the text with placeholders. Wagtail works nicely with haystack.
I hope this helps,
Felix

Display uploaded gpx points and lines on map

I want to create simple upload form on my django site where users could upload their gpx files but I want to give them possibility to preview their points and lines on map before they proceed with submiting it.
I have some basic knowledge of working with django forms but I'm not sure how to convert that gpx data and display it on map.
I hope you can tell me at least where to start because I'm completely out of ideas.
Thanks
Well, if you use Django then you could probably extend it with Geodjango which provides you easy and nice way to create geometry fields for your models (points,lines, poligons).
In case you decide to use Geodjango for this purpose then please check my blog post http://ipasic.com/article/uploading-parsing-and-saving-gpx-data-postgis-geodjango/
I've described there process of uploading,parsing and saving gpx file to spatial database (like Postgis).It could help you to get an idea.
I didn't describe how to display it on map but it shouldn't be problem. I would recommend you to use Leaflet or some other javascript mapping library for it.
However, that's to much for writing right now.
I hope that helps.

Single model for storing django application-wide options

I have a set of top-level configuration data fields that I want to be able to set within django admin for each deployment of my django app. I only want one set of these.
Example fields: site_logo, contact_person, address, facebook_url, twitter_url
The problem is that Django Admin is geared towards tables (lists) of models, so its not a good fit for this type of singular configuration model. I really only want one of these models to exist for the whole site, and to be able to click into it from admin and edit the various fields.
It seems i've come across a 3rd party app in the past to accomplish this but can't find it anywhere. Part of the problem is I'm finding it difficult to find the right words to google. Any ideas?
It looks like django-values will do what you're looking for.
Other possible contenders:
http://github.com/sciyoshi/django-dbsettings (doesn't look maintained)
http://github.com/jqb/django-settings
Have a look at django-livesettings it sounds like it might fit.
Not that i have used it, but i have heard good things about django-constance.
And there are even some more options listed in the Configuration-Grid on Django Packages.

django==1.4 support for html5

I have a small blog app I have built using Django 1.4 and recently, I have been learning "bits and pieces" of html5 and css3. I am about the start transitioning my site to html5/css3 and I was wondering if Django widgets support html5(?)
My blog is nothing special - a few forms, a few tables etc.. For example when I do,
{{form_as_p}}
I was wondering if django would generate the required html5 markup(?) I read the docs, and it says the admin pages support html5, but I could not find any docs for regular apps.
If html5 is not supported by Django, what is the best way going about achieving this?
Thanks for your time.
Django's form output is XHTML. Django does not snip with support for the new HTML5 input types such as number, email, url, etc but it is not difficult to add them. See https://code.djangoproject.com/ticket/16630 or https://github.com/rhec/django-html5 That being said I don't know any place where Django generates markup that is invalid for HTML5.
"If html5 is not supported by Django, what is the best way going about achieving this?"
I have been trying a monkeypatch approach with very encouraging results so far, the big bonus for me is that there is no need to change your existing code, or for modifying third party apps, or Django admin. This keeps things very clean and central and there is no need for hairy and repetitive admin.site.register(...)/admin.site.register(...).
https://github.com/danielsokolowski/django-html5monkeypatch

Django strategy for automatically suggesting matching content

I'm looking at porting a custom-written PHP CMS into Django. One of the features the CMS currently has is an image upload function. I write an article, tag it with information, then choose a photo for it. If the system has any photos which have been added to articles with tags in common with the new one, it will suggest the photo for that article too. If there are no matches then a new image can be added.
In case this doesn't make sense, let's say I tag an article as Bruce Springsteen, The Beatles and Led Zeppelin. Next time I add an article with the tag The Beatles, it should suggest I use the image added for the first article.
What would be the best Django-applicable way to implement this? I've looked at the Photologue app and have integrated it, and I know it has tagging support (the problem here is that I'm using django-taggit, whereas Photologue supports django-tagging). One approach could be simply building it myself -- when a user uploads an article, I run a hook after they save it to associate the tags with the image. I'm just not sure how to then autosuggest an image in the admin tools based on that info.
Any ideas/approaches greatly appreciated.
This is almost certainly something you're going to have to build yourself. Django has a moderate number of libraries out there (that you've clearly already found). Unlike other solutions, it doesn't have a lot of things that get you 100% to your desired solution (whereas something like Drupal might get you 100% of the way there).
What you will probably need to do (at a high level) is something like this:
Create an AJAX view that takes the current tags as an argument and does a query on the existing posts to see what tags match and returns images from those posts.
Use jQuery/javascript on your view to call your AJAX view on the page as tags are added
Use jQuery to update a <div> on your page and show all the images that your view returned
Here is a similar example that might help get you started.
You might look into django-ajax as a helper library for your requests, but it definitely isn't necessary.
The hook between the your image module and any other django module can be implemented using django's contenttypes framework which also provides some useful instance methods for returning related/hooked objects.