From 91099dc315acfbd403ac4fe0f183fbb0c372e5f1 Mon Sep 17 00:00:00 2001 From: Antonio Cavedoni Date: Thu, 15 Feb 2007 20:56:01 +0100 Subject: [PATCH 1/3] Changed permalink from item.id to item.link in default django theme. Thanks, Amit Chakradeo! --- themes/django/index.html.dj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/django/index.html.dj b/themes/django/index.html.dj index 57f9a81..632a527 100644 --- a/themes/django/index.html.dj +++ b/themes/django/index.html.dj @@ -39,7 +39,7 @@

by {{ item.channel_author }} on {{ item.date }} ยท - permalink + permalink

{% endfor %} From 49180c707127b84d86be9300f5b648835fdecb66 Mon Sep 17 00:00:00 2001 From: Antonio Cavedoni Date: Thu, 15 Feb 2007 23:02:55 +0100 Subject: [PATCH 2/3] Added note on Django requiring at least Python 2.3 --- docs/templates.html | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/templates.html b/docs/templates.html index f33be70..5aff9d6 100644 --- a/docs/templates.html +++ b/docs/templates.html @@ -132,6 +132,11 @@ Item.

the now tag.

+

+ Please note that Django, and therefore Venus' Django support, + requires at least Python 2.3. +

+

xslt

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 Date: Fri, 16 Feb 2007 00:51:53 +0100 Subject: [PATCH 3/3] Started testing Django integration, somewhat improved documentation --- docs/templates.html | 5 +-- planet/shell/dj.py | 45 ++++++++++++++++++-------- tests/data/filter/django/test.ini | 2 ++ tests/data/filter/django/test.xml | 20 ++++++++++++ tests/data/filter/django/title.html.dj | 1 + tests/test_filter_django.py | 33 +++++++++++++++++++ 6 files changed, 90 insertions(+), 16 deletions(-) create mode 100644 tests/data/filter/django/test.ini create mode 100644 tests/data/filter/django/test.xml create mode 100644 tests/data/filter/django/title.html.dj create mode 100644 tests/test_filter_django.py diff --git a/docs/templates.html b/docs/templates.html index 5aff9d6..748c956 100644 --- a/docs/templates.html +++ b/docs/templates.html @@ -128,8 +128,9 @@ Item.

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 @@ + + + + Example Feed + + 2003-12-13T18:30:02Z + + John Doe + + urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6 + + + Atom-Powered Robots Run Amok + + urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a + 2003-12-13T18:30:02Z +

Some text. + + + diff --git a/tests/data/filter/django/title.html.dj b/tests/data/filter/django/title.html.dj new file mode 100644 index 0000000..144794a --- /dev/null +++ b/tests/data/filter/django/title.html.dj @@ -0,0 +1 @@ +{% for item in Items %}{{ item.title }}{% endfor %} diff --git a/tests/test_filter_django.py b/tests/test_filter_django.py new file mode 100644 index 0000000..2a4c233 --- /dev/null +++ b/tests/test_filter_django.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python + +import os.path +import unittest, xml.dom.minidom, datetime + +from planet import config, logger +from planet.shell import dj + +class DjangoFilterTests(unittest.TestCase): + + def test_django_filter(self): + config.load('tests/data/filter/django/test.ini') + results = dj.tmpl.template_info("") + self.assertEqual(results['name'], 'Django on Venus') + + def test_django_date_type(self): + config.load('tests/data/filter/django/test.ini') + results = dj.tmpl.template_info("") + self.assertEqual(type(results['date']), datetime.datetime) + + def test_django_item_title(self): + config.load('tests/data/filter/django/test.ini') + feed = open('tests/data/filter/django/test.xml') + input = feed.read(); feed.close() + results = dj.run( + os.path.realpath('tests/data/filter/django/title.html.dj'), input) + self.assertEqual(results, "Atom-Powered Robots Run Amok\n") + +try: + from django.conf import settings +except ImportError: + logger.warn("Django is not available => can't test django filters") + del DjangoFilterTests.test_django_filter