Skip to content
Browse files

Dynamic docs version in header

  • Loading branch information...
1 parent a4c4994 commit a9425fbe6f6fddc162dffc630314e26166a7c450 @coagulant coagulant committed Jul 30, 2011
View
2 djangodocs/livedocs/models.py
@@ -25,7 +25,7 @@ def __unicode__(self):
return self.title
def get_absolute_url(self):
- return self.path
+ return '/'+self.path
def get_breadcrumbs(self):
return self.get_ancestors()
View
17 djangodocs/livedocs/templates/livedocs/_search_form.html
@@ -0,0 +1,17 @@
+<header class="b-header">
+ <div class="l-wrapper">
+ <form action="/search" method="get" class="b-search">
+ {% for field in search_form.visible_fields %}
+ {{ field }}
+ {% endfor %}
+ <input type="submit" class="b-search__sumbit" value="Search" />
+ </form>
+ <nav class="b-version">
+ {% for version in avaliable_versions %}
+ <a class="b-version__link
+ g-systemlink{% if version.selected %} b-version__link_active{% endif %}" href="">{{ version }}</a>
+ {% endfor %}
+ </nav>
+ </div>
+</header>
+
View
17 djangodocs/livedocs/templates/livedocs/layout/layout.html
@@ -1,22 +1,7 @@
{% extends 'livedocs/layout/body.html' %}
-
{% block layout %}
- <header class="b-header">
- <div class="l-wrapper">
- <form action="/search" method="get" class="b-search">
- {% for field in search_form.visible_fields %}
- {{ field }}
- {% endfor %}
- <input type="submit" class="b-search__sumbit" value="Search" />
- </form>
- <nav class="b-version">
- <a class="b-version__link g-systemlink" href="">1.2</a>
- <a class="b-version__link b-version__link_active g-systemlink" href="">1.3</a>
- <a class="b-version__link g-systemlink" href="">dev</a>
- </nav>
- </div>
- </header>
+ {% include 'livedocs/_search_form.html' %}
<div class="l-wrapper l-header-spacer b-section">
<aside class="l-results b-results">
{% block results %}
View
26 djangodocs/livedocs/templates/livedocs/search.html
@@ -0,0 +1,26 @@
+{% extends 'livedocs/layout/layout.html' %}
+
+{% block results %}
+ Search for {{ query }}.<br/>
+ Found {{ found_count }} items:
+
+ <h1 class="b-results__header">Search results</h1>
+
+ <nav class="b-results__nav">
+ {% for item in items %}
+ <article class="b-results__item">
+ <div class="b-results__breadcrumbs">
+ {% for crumb in item.get_breadcrumbs %}
+ <span class="b-results__breadcrumbs-item">{{ crumb.title }}</span>
+ {% if not forloop.last %}
+ <span class="b-results__breadcrumbs-separator">></span>
+ {% endif %}
+ {% endfor %}
+ </div>
+ <a class="b-results__link" href="{{ item.get_absolute_url }}">{{ item.title }}</a>
+ </article>
+ {% endfor %}
+ </nav>
+
+{% endblock %}
+
View
11 djangodocs/livedocs/views.py
@@ -1,18 +1,25 @@
from annoying.decorators import render_to
from django.db.models.query_utils import Q
from forms import SearchForm
-from models import Item
+from models import Item, Version
@render_to('livedocs/search.html')
-def search(request):
+def search(request, current_version):
""" Backend url for searching items"""
search_form = SearchForm(request.GET)
if search_form.is_valid():
query = search_form.cleaned_data['query']
items = Item.objects.filter(Q(title__icontains=query) | Q(content__icontains=query))
+
+ avaliable_versions = Version.objects.all().order_by('name')
+ for version in avaliable_versions:
+ if version.name == current_version:
+ version.selected = True
return {'search_form': search_form,
+ 'version': version,
+ 'avaliable_versions': avaliable_versions,
'query': query,
'items': items,
'found_count': len(items)}
View
2 djangodocs/urls.py
@@ -9,7 +9,7 @@
urlpatterns = patterns('',
- url(r'', include('livedocs.urls')),
+ url(r'(?P<current_version>[^/]+?)/', include('livedocs.urls')),
(r'^data/(?P<path>.*)', 'django.views.static.serve', {'document_root': os.path.join(ROOT_PATH, 'data'),
'show_indexes': True}),

0 comments on commit a9425fb

Please sign in to comment.
Something went wrong with that request. Please try again.