From 91099dc315acfbd403ac4fe0f183fbb0c372e5f1 Mon Sep 17 00:00:00 2001
From: Antonio Cavedoni
by {{ item.channel_author }} on
{{ item.date }} ยท
- permalink
+ permalink
now
tag.
++ Please note that Django, and therefore Venus' Django support, + requires at least Python 2.3. +
+XSLT is a paradox: it actually
makes some simple things easier to do than htmltmpl, and certainly can
From 7cd69ce7d7bf6341abf70bc4a0df6822405642ad Mon Sep 17 00:00:00 2001
From: Antonio Cavedoni
All the standard Django template tags and filter are supposed to
- work, with the notable exception of the date
filter and
- the now
tag.
+ work, with the notable exception of the date
filter on
+ the updated and published dates of an item (it works on the main
+ {{ date }}
variable).
diff --git a/planet/shell/dj.py b/planet/shell/dj.py
index d728313..7724902 100644
--- a/planet/shell/dj.py
+++ b/planet/shell/dj.py
@@ -1,30 +1,47 @@
import os.path
import urlparse
+import datetime
+import tmpl
from planet import config
-from tmpl import template_info
+
+def DjangoPlanetDate(value):
+ return datetime.datetime(*value[:6])
+
+# remap PlanetDate to be a datetime, so Django template authors can use
+# the "date" filter on these values
+tmpl.PlanetDate = DjangoPlanetDate
def run(script, doc, output_file=None, options={}):
- """process a Django template file """
+ """process a Django template file"""
# this is needed to use the Django template system as standalone
# I need to re-import the settings at every call because I have to
# set the TEMPLATE_DIRS variable programmatically
from django.conf import settings
- settings.configure(
- DEBUG=True, TEMPLATE_DEBUG=True,
- TEMPLATE_DIRS=(os.path.dirname(script),)
- )
+ try:
+ settings.configure(
+ DEBUG=True, TEMPLATE_DEBUG=True,
+ TEMPLATE_DIRS=(os.path.dirname(script),)
+ )
+ except EnvironmentError:
+ pass
from django.template import Context
from django.template.loader import get_template
+ # set up the Django context by using the default htmltmpl
+ # datatype converters
context = Context()
- context.update(template_info(doc))
-
- reluri = os.path.splitext(os.path.basename(output_file))[0]
- context['url'] = urlparse.urljoin(config.link(),reluri)
-
+ context.update(tmpl.template_info(doc))
t = get_template(script)
- f = open(output_file, 'w')
- f.write(t.render(context))
- f.close()
+
+ if output_file:
+ reluri = os.path.splitext(os.path.basename(output_file))[0]
+ context['url'] = urlparse.urljoin(config.link(),reluri)
+ f = open(output_file, 'w')
+ f.write(t.render(context))
+ f.close()
+ else:
+ # @@this is useful for testing purposes, but does it
+ # belong here?
+ return t.render(context)
diff --git a/tests/data/filter/django/test.ini b/tests/data/filter/django/test.ini
new file mode 100644
index 0000000..e4be897
--- /dev/null
+++ b/tests/data/filter/django/test.ini
@@ -0,0 +1,2 @@
+[Planet]
+name: Django on Venus
diff --git a/tests/data/filter/django/test.xml b/tests/data/filter/django/test.xml
new file mode 100644
index 0000000..18ab87a
--- /dev/null
+++ b/tests/data/filter/django/test.xml
@@ -0,0 +1,20 @@
+
+