moved library list generation into a template tag

previously, if you created or updated a library, the list
(/libraryauth/list/ )would not get updated
pull/1/head
eric 2013-12-13 14:25:18 -05:00
parent 8091ba1846
commit 8c974ca343
4 changed files with 20 additions and 4 deletions

View File

@ -1,4 +1,5 @@
{% extends "base.html" %} {% extends "base.html" %}
{% load librarylist %}
{% block title %} Libraries {% endblock %} {% block title %} Libraries {% endblock %}
{% block extra_css %} {% block extra_css %}
<link type="text/css" rel="stylesheet" href="/static/css/supporter_layout.css" /> <link type="text/css" rel="stylesheet" href="/static/css/supporter_layout.css" />
@ -33,6 +34,7 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
{% librarylist %}
<div id="main-container"> <div id="main-container">
<div class="js-main"> <div class="js-main">
<div id="js-leftcol"> <div id="js-leftcol">

View File

View File

@ -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 ''

View File

@ -14,11 +14,11 @@ urlpatterns = patterns(
url(r"^libraryauth/create/$", login_required(views.CreateLibraryView.as_view()), name="library_create"), url(r"^libraryauth/create/$", login_required(views.CreateLibraryView.as_view()), name="library_create"),
url(r"^libraryauth/list/$", direct_to_template, { url(r"^libraryauth/list/$", direct_to_template, {
'template':'libraryauth/list.html', 'template':'libraryauth/list.html',
'extra_context':{'libraries':models.Library.objects.filter(approved=True).order_by('name')} 'extra_context':{'libraries_to_show':'approved'}},
}, name="library_list"), name="library_list"),
url(r"^libraryauth/unapproved/$", direct_to_template, { url(r"^libraryauth/unapproved/$", direct_to_template, {
'template':'libraryauth/list.html', 'template':'libraryauth/list.html',
'extra_context':{'libraries':models.Library.objects.filter(approved=False).order_by('name')} 'extra_context':{'libraries_to_show':'new'}},
}, name="new_libraries"), name="new_libraries"),
url(r'^accounts/superlogin/$', views.superlogin, name='superlogin'), url(r'^accounts/superlogin/$', views.superlogin, name='superlogin'),
) )