From 8c974ca3433ee9edbb00ef3ebac69f422f28160e Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 13 Dec 2013 14:25:18 -0500 Subject: [PATCH] moved library list generation into a template tag previously, if you created or updated a library, the list (/libraryauth/list/ )would not get updated --- frontend/templates/libraryauth/list.html | 2 ++ libraryauth/templatetags/__init__.py | 0 libraryauth/templatetags/librarylist.py | 14 ++++++++++++++ libraryauth/urls.py | 8 ++++---- 4 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 libraryauth/templatetags/__init__.py create mode 100644 libraryauth/templatetags/librarylist.py 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'), )