Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added some stylishness to the search pages.

  • Loading branch information...
commit f98eae0d67df2f3cd6574f5a137e2b2aaa25af7d 1 parent 981fe4b
@jacobian jacobian authored
View
15 django_website/docs/forms.py
@@ -2,15 +2,18 @@
from django import forms
from .models import DocumentRelease
+# Right now this just does version because we don't really have
+# multiple languages. If we get them, we'll need to deal with that.
+
class DocSearchForm(haystack.forms.SearchForm):
def __init__(self, *args, **kwargs):
super(DocSearchForm, self).__init__(*args, **kwargs)
- self.fields['release'] = forms.ModelChoiceField(
- queryset = DocumentRelease.objects.all(),
+ self.fields['q'].widget = SearchInput()
+ self.fields['release'] = DocumentReleaseChoiceField(
+ queryset = DocumentRelease.objects.all().order_by('version'),
initial = DocumentRelease.objects.default(),
empty_label = None,
- widget = forms.RadioSelect,
)
def search(self):
@@ -18,3 +21,9 @@ def search(self):
rel = self.cleaned_data['release']
return sqs.filter(lang=rel.lang, version=rel.version)
+class DocumentReleaseChoiceField(forms.ModelChoiceField):
+ def label_from_instance(self, obj):
+ return obj.human_version
+
+class SearchInput(forms.TextInput):
+ input_type = 'search'
View
3  django_website/docs/management/commands/update_docs.py
@@ -89,7 +89,7 @@ def handle_noargs(self, **kwargs):
with open(built_doc) as fp:
json_doc = json.load(fp)
try:
- body = strip_tags(json_doc['body'])
+ ignored = json_doc['body'] # Just to make sure it exists.
title = strip_tags(json_doc['title'])
except KeyError, ex:
if verbosity >= 2:
@@ -98,7 +98,6 @@ def handle_noargs(self, **kwargs):
doc = documents.pop(path, Document(path=path, release=release))
doc.title = title
- doc.body = body
if verbosity >= 2:
print "Indexing:", doc
doc.save()
View
40 django_website/docs/migrations/0003_fix_document_model.py
@@ -0,0 +1,40 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Deleting field 'Document.content'
+ db.delete_column('docs_document', 'content')
+
+
+ def backwards(self, orm):
+
+ # Adding field 'Document.content'
+ db.add_column('docs_document', 'content', self.gf('django.db.models.fields.TextField')(default=''), keep_default=False)
+
+
+ models = {
+ 'docs.document': {
+ 'Meta': {'object_name': 'Document'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'path': ('django.db.models.fields.CharField', [], {'max_length': '500'}),
+ 'release': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'documents'", 'to': "orm['docs.DocumentRelease']"}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '500'})
+ },
+ 'docs.documentrelease': {
+ 'Meta': {'object_name': 'DocumentRelease'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_default': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'lang': ('django.db.models.fields.CharField', [], {'default': "'en'", 'max_length': '2'}),
+ 'scm': ('django.db.models.fields.CharField', [], {'max_length': '10'}),
+ 'scm_url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
+ 'version': ('django.db.models.fields.CharField', [], {'max_length': '20'})
+ }
+ }
+
+ complete_apps = ['docs']
View
11 django_website/docs/models.py
@@ -35,14 +35,21 @@ def save(self, *args, **kwargs):
DocumentRelease.objects.update(is_default=False)
super(DocumentRelease, self).save(*args, **kwargs)
+ @property
+ def human_version(self):
+ """
+ Return a "human readable" version of the version.
+ """
+ return "Development trunk" if self.version == 'dev' \
+ else "Django %s" % self.version
+
class Document(models.Model):
"""
An individual document. Used mainly as a hook point for Haystack.
"""
release = models.ForeignKey(DocumentRelease, related_name='documents')
path = models.CharField(max_length=500)
- title = models.TextField(max_length=500)
- content = models.TextField()
+ title = models.CharField(max_length=500)
def __unicode__(self):
return "/".join([self.release.lang, self.release.version, self.path])
View
3  django_website/docs/search_indexes.py
@@ -1,5 +1,6 @@
import json
from django.conf import settings
+from django.utils.html import strip_tags
import haystack
import haystack.indexes
from . import utils
@@ -20,6 +21,6 @@ def prepare_text(self, obj):
docpath = utils.get_doc_path(root, obj.path)
with open(docpath) as fp:
doc = json.load(fp)
- return doc['body']
+ return strip_tags(doc['body'])
haystack.site.register(Document, DocumentIndex)
View
59 django_website/docs/templates/docs/search.html
@@ -9,28 +9,47 @@
{% block last-update-wrapper %}{% endblock %}
{% block body %}
- <h2>Search</h2>
- <form method="get" action=".">
- {{ form.as_p }}
- <input type="submit" value="Search">
- </form>
+ <form method="get" action="." id="page_search">
+ <p>
+ <label for="{{ form.q.auto_id }}">Search for:</label>
+ {{ form.q }}
+ <label for="{{ form.release.auto_id }}">in version:</label>
+ {{ form.release }}
+ <input type="submit" class="submit" value="Search" />
+ </p>
+ </form>
+</form>
- {% if query %}
- <h3>Results</h3>
- {% for result in page.object_list %}
- <p>
- <a href="{{ result.object.get_absolute_url }}">{{ result.object.title }}</a>
- </p>
- {% empty %}
- <p>No results found.</p>
- {% endfor %}
+{% if query %}
+ {% load highlight %}
+ <h2>Results</h2>
+ <div id="search-results">
+ {% for result in page.object_list %}
+ <h3>
+ <a href="{{ result.object.get_absolute_url }}">{{ result.object.title }}</a>
+ </h3>
+ <p>{% highlight result.text with query max_length 200 %}</p>
+ {% empty %}
+ <h3>No results found.</h3>
+ {% endfor %}
+ </div>
- {% if page.has_previous or page.has_next %}
- <div>
- {% if page.has_previous %}<a href="?q={{ query }}&amp;page={{ page.previous_page_number }}">{% endif %}&laquo; Previous{% if page.has_previous %}</a>{% endif %}
- |
- {% if page.has_next %}<a href="?q={{ query }}&amp;page={{ page.next_page_number }}">{% endif %}Next &raquo;{% if page.has_next %}</a>{% endif %}
- </div>
+ {% if page.has_previous or page.has_next %}
+ <div>
+ {% with "q={{ query }}&amp;release={{ release.id }}" as q %}
+ {% if page.has_previous %}
+ <a href="?{{ q }}&amp;page={{ page.previous_page_number }}">
{% endif %}
+ &laquo; Previous
+ {% if page.has_previous %}</a>{% endif %}
+ |
+ {% if page.has_next %}
+ <a href="?{{ q }}&amp;page={{ page.next_page_number }}">
+ {% endif %}
+ Next &raquo;
+ {% if page.has_next %}</a>{% endif %}
+ {% endwith %}
+ </div>
{% endif %}
+{% endif %}
{% endblock %}
View
12 django_website/docs/templates/docs/search_form.html
@@ -1,6 +1,14 @@
<form action="{% url document-search %}" id="{{ search_form_id }}" class="search">
<div>
- {{ form.as_p }}
- <input type="submit" class="submit" value="Search" />
+ <p>
+ {{ form.q }}
+ </p>
+ <p>
+ <label for="{{ form.release.auto_id }}">Version:</label>
+ {{ form.release }}
+ </p>
+ <p>
+ <input type="submit" class="submit" value="Search" />
+ </p>
</div>
</form>
View
3  django_website/docs/templatetags/docs.py
@@ -8,11 +8,12 @@
register = template.Library()
@register.inclusion_tag('docs/search_form.html', takes_context=True)
-def search_form(context, search_form_id='search'):
+def search_form(context, search_form_id='sidebar_search'):
request = context['request']
auto_id = 'id_%s_%%s' % search_form_id
return {
'form': DocSearchForm(initial=request.GET, auto_id=auto_id),
+ 'search_form_id': search_form_id,
}
@register.tag
View
1  django_website/docs/views.py
@@ -73,5 +73,6 @@ def extra_context(self):
return {
'lang': default_release.lang,
'version': default_release.version,
+ 'release': default_release,
}
View
19 media/css/docs/docs.css
@@ -1,7 +1,14 @@
-#docs-search { color: #000; float: right; }
-#docs-search form { font-size: 92%; margin: 0; padding: 1em 1em 0; white-space: nowrap; }
-form.search ul { list-style: none; margin: 0; padding: 0; }
-form.search li { display: inline; padding-right: 1em; }
-form.search .query { width: 18em; }
+/* A few fixups */
+
#content-main .jump_links { font-size: 1.2em; margin-left: 0px; }
-.synopsis { padding-left: 10px; color: #222;}
+.synopsis { padding-left: 10px; color: #222;}
+
+/* Search form - sidebar */
+#sidebar_search #id_sidebar_search_q { width: 100%; }
+
+/* Search form - search page */
+#page_search { font-size: 150%; margin-top: 1.4em; margin-bottom: 1em; color: #092E20; }
+#page_search .submit { float: right; font-size: 150%; }
+
+/* Search results */
+#search-results span.highlighted { background-color: #ffe761; font-weight: bold; }
Please sign in to comment.
Something went wrong with that request. Please try again.