diff --git a/frontend/templates/libraryauth/list.html b/frontend/templates/libraryauth/list.html index 600a25ee..19a06891 100644 --- a/frontend/templates/libraryauth/list.html +++ b/frontend/templates/libraryauth/list.html @@ -1,4 +1,5 @@ {% extends "base.html" %} +{% load librarylist %} {% block title %} Libraries {% endblock %} {% block extra_css %} @@ -33,6 +34,7 @@ {% endblock %} {% block content %} +{% librarylist %}
diff --git a/libraryauth/templatetags/__init__.py b/libraryauth/templatetags/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/libraryauth/templatetags/librarylist.py b/libraryauth/templatetags/librarylist.py new file mode 100644 index 00000000..84927fea --- /dev/null +++ b/libraryauth/templatetags/librarylist.py @@ -0,0 +1,14 @@ +from django import template +from .. import models +register = template.Library() + +@register.simple_tag(takes_context=True) +def librarylist(context): + libraries_to_show = context.get('libraries_to_show', 'approved') + if libraries_to_show == 'approved': + context['libraries'] = models.Library.objects.filter(approved=True).order_by('name') + elif libraries_to_show == 'new': + context['libraries'] = models.Library.objects.filter(approved=False).order_by('name') + else: + context['libraries'] = models.Library.objects.order_by('name') + return '' diff --git a/libraryauth/urls.py b/libraryauth/urls.py index 50b72583..abb64ae1 100644 --- a/libraryauth/urls.py +++ b/libraryauth/urls.py @@ -14,11 +14,11 @@ urlpatterns = patterns( url(r"^libraryauth/create/$", login_required(views.CreateLibraryView.as_view()), name="library_create"), url(r"^libraryauth/list/$", direct_to_template, { 'template':'libraryauth/list.html', - 'extra_context':{'libraries':models.Library.objects.filter(approved=True).order_by('name')} - }, name="library_list"), + 'extra_context':{'libraries_to_show':'approved'}}, + name="library_list"), url(r"^libraryauth/unapproved/$", direct_to_template, { 'template':'libraryauth/list.html', - 'extra_context':{'libraries':models.Library.objects.filter(approved=False).order_by('name')} - }, name="new_libraries"), + 'extra_context':{'libraries_to_show':'new'}}, + name="new_libraries"), url(r'^accounts/superlogin/$', views.superlogin, name='superlogin'), )