Commits

Mark Lavin committed 65f9af3

Adding templatetags and more example work.

Comments (0)

Files changed (8)

 docs/_build/*
 dist/*
 *.egg-info/*
+example/media/*
+example/static/*

example/settings.py

     'django.contrib.messages',
     'django.contrib.admin',
     'staticfiles',
+    'imagekit',
     'photobook',
 )

example/templates/admin/base_site.html

+{% extends "admin/base.html" %}
+{% load i18n %}
+
+{% block extrahead %}
+    {{ block.super }}
+    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/themes/base/jquery-ui.css" type="text/css" media="screen">
+    <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/themes/ui-lightness/jquery-ui.css" type="text/css" media="screen">
+    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
+    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/jquery-ui.min.js"></script>
+    <script type="text/javascript" src="{{ STATIC_URL }}js/pixlr.js"></script>
+{% endblock %}
+
+{% block title %}{{ title }} | {% trans 'Django site admin' %}{% endblock %}
+
+{% block branding %}
+<h1 id="site-name">{% trans 'Django administration' %}</h1>
+{% endblock %}
+
+{% block nav-global %}{% endblock %}

example/templates/base.html

     <body>
         {% block content %}
             {% block content-main %}
-
             {% endblock %}
             {% block content-related %}
-
             {% endblock %}
         {% endblock %}
     </body>
+from django.conf import settings
 from django.conf.urls.defaults import *
 from django.contrib import admin
 
     (r'^sitemap-(?P<section>.+)\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps}),
 )
 
-urlpatterns += staticfiles_urlpatterns()
+if settings.DEBUG:
+    urlpatterns += patterns('',
+        (r'^%s(?P<path>.*)' % settings.MEDIA_URL.lstrip('/'),
+          'django.views.static.serve',
+          {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}))
+    urlpatterns += staticfiles_urlpatterns()

photobook/models.py

     use_for_related_fields = True
     
     def published(self):
-        return self.filter(status=STATUS_PUBLIC, publish__lt=datetime.now())
+        return self.filter(status=STATUS_PUBLIC, publish__lte=datetime.now())
 
 
 class Gallery(models.Model):

photobook/templatetags/__init__.py

Empty file added.

photobook/templatetags/photobook_tags.py

+import datetime
+from django import template
+
+from photobook.models import Gallery
+
+register = template.Library()
+
+
+class MonthListNode(template.Node):
+    def __init__(self, var_name):
+        self.var_name = var_name
+
+    def render(self, context):
+        context[self.var_name] = list(Gallery.objects.published().dates("publish", "month", order="DESC"))
+        return ''
+
+
+@register.tag
+def get_gallery_month_list(parser, token):
+    """Gets month list that have galleries and populates the template context
+    with a variable containing that value, whose name is defined by the 'as'
+    clause.
+
+    Syntax::
+
+        {% get_gallery_month_list as [var_name] %}
+
+    Example usage::
+
+        {% get_gallery_month_list as archive %}
+
+        {% get_gallery_month_list as gallery_months %}
+    """
+    bits = token.contents.split()
+    if len(bits) != 3:
+        raise template.TemplateSyntaxError, "'%s' tag takes three arguments" % bits[0]
+    if bits[1] != 'as':
+        raise template.TemplateSyntaxError, "First argument to '%s' tag must be 'as'" % bits[0]
+    return MonthListNode(bits[2])