diff --git a/django/contrib/admin/templates/admin/search_form.html b/django/contrib/admin/templates/admin/search_form.html
index d9126c3ec5..445cca3089 100644
--- a/django/contrib/admin/templates/admin/search_form.html
+++ b/django/contrib/admin/templates/admin/search_form.html
@@ -7,7 +7,7 @@
{% if show_result_count %}
- {% blocktrans count cl.result_count as counter %}1 result{% plural %}{{ counter }} results{% endblocktrans %} ({% blocktrans with cl.full_result_count as full_result_count %}{{ full_result_count }} total{% endblocktrans %})
+ {% blocktrans count cl.result_count as counter %}1 result{% plural %}{{ counter }} results{% endblocktrans %} ({% blocktrans with cl.full_result_count as full_result_count %}{{ full_result_count }} total{% endblocktrans %})
{% endif %}
{% for pair in cl.params.items %}
{% ifnotequal pair.0 search_var %}{% endifnotequal %}
diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py
index 2312b320ec..d251c95625 100644
--- a/django/contrib/admin/views/main.py
+++ b/django/contrib/admin/views/main.py
@@ -227,7 +227,7 @@ index = staff_member_required(never_cache(index))
def add_stage(request, app_label, model_name, show_delete=False, form_url='', post_url=None, post_url_continue='../%s/', object_id_override=None):
model = models.get_model(app_label, model_name)
if model is None:
- raise Http404, "App %r, model %r, not found" % (app_label, model_name)
+ raise Http404("App %r, model %r, not found" % (app_label, model_name))
opts = model._meta
if not has_permission(request.user, opts.get_add_permission()):
@@ -307,7 +307,7 @@ def change_stage(request, app_label, model_name, object_id):
model = models.get_model(app_label, model_name)
object_id = unquote(object_id)
if model is None:
- raise Http404, "App %r, model %r, not found" % (app_label, model_name)
+ raise Http404("App %r, model %r, not found" % (app_label, model_name))
opts = model._meta
if request.POST and request.POST.has_key("_saveasnew"):
@@ -315,8 +315,8 @@ def change_stage(request, app_label, model_name, object_id):
try:
manipulator = model.ChangeManipulator(object_id)
- except ObjectDoesNotExist:
- raise Http404
+ except model.DoesNotExist:
+ raise Http404('%s object with primary key %r does not exist' % (model_name, escape(object_id)))
if not has_permission(request.user, opts.get_change_permission(), manipulator.original_object):
raise PermissionDenied
@@ -492,7 +492,7 @@ def delete_stage(request, app_label, model_name, object_id):
model = models.get_model(app_label, model_name)
object_id = unquote(object_id)
if model is None:
- raise Http404, "App %r, model %r, not found" % (app_label, model_name)
+ raise Http404("App %r, model %r, not found" % (app_label, model_name))
opts = model._meta
obj = get_object_or_404(model, pk=object_id)
if not has_permission(request.user, opts.get_delete_permission(), obj):
@@ -529,7 +529,7 @@ def history(request, app_label, model_name, object_id):
model = models.get_model(app_label, model_name)
object_id = unquote(object_id)
if model is None:
- raise Http404, "App %r, model %r, not found" % (app_label, model_name)
+ raise Http404("App %r, model %r, not found" % (app_label, model_name))
action_list = LogEntry.objects.filter(object_id=object_id,
content_type__id__exact=ContentType.objects.get_for_model(model).id).select_related().order_by('action_time')
# If no history was found, see whether this object even exists.
@@ -745,7 +745,7 @@ class ChangeList(object):
def change_list(request, app_label, model_name):
model = models.get_model(app_label, model_name)
if model is None:
- raise Http404, "App %r, model %r, not found" % (app_label, model_name)
+ raise Http404("App %r, model %r, not found" % (app_label, model_name))
# There isn't a specific object to check here, so don't pass one to
# has_permission. There should be a has_permission implementation
# registered that knows when the obj arg is missing.
diff --git a/django/contrib/contenttypes/management.py b/django/contrib/contenttypes/management.py
index de3a685477..f492f54303 100644
--- a/django/contrib/contenttypes/management.py
+++ b/django/contrib/contenttypes/management.py
@@ -3,9 +3,9 @@ Creates content types for all installed models.
"""
from django.dispatch import dispatcher
-from django.db.models import get_models, signals
+from django.db.models import get_apps, get_models, signals
-def create_contenttypes(app, created_models, verbosity):
+def create_contenttypes(app, created_models, verbosity=2):
from django.contrib.contenttypes.models import ContentType
app_models = get_models(app)
if not app_models:
@@ -22,4 +22,11 @@ def create_contenttypes(app, created_models, verbosity):
if verbosity >= 2:
print "Adding content type '%s | %s'" % (ct.app_label, ct.model)
+def create_all_contenttypes(verbosity=2):
+ for app in get_apps():
+ create_contenttypes(app, None, verbosity)
+
dispatcher.connect(create_contenttypes, signal=signals.post_syncdb)
+
+if __name__ == "__main__":
+ create_all_contenttypes()
diff --git a/django/contrib/formtools/__init__.py b/django/contrib/formtools/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/django/contrib/formtools/preview.py b/django/contrib/formtools/preview.py
new file mode 100644
index 0000000000..9a9371b5f8
--- /dev/null
+++ b/django/contrib/formtools/preview.py
@@ -0,0 +1,160 @@
+"""
+Formtools Preview application.
+
+This is an abstraction of the following workflow:
+
+ "Display an HTML form, force a preview, then do something with the submission."
+
+Given a django.newforms.Form object that you define, this takes care of the
+following:
+
+ * Displays the form as HTML on a Web page.
+ * Validates the form data once it's submitted via POST.
+ * If it's valid, displays a preview page.
+ * If it's not valid, redisplays the form with error messages.
+ * At the preview page, if the preview confirmation button is pressed, calls
+ a hook that you define -- a done() method.
+
+The framework enforces the required preview by passing a shared-secret hash to
+the preview page. If somebody tweaks the form parameters on the preview page,
+the form submission will fail the hash comparison test.
+
+Usage
+=====
+
+Subclass FormPreview and define a done() method:
+
+ def done(self, request, clean_data):
+ # ...
+
+This method takes an HttpRequest object and a dictionary of the form data after
+it has been validated and cleaned. It should return an HttpResponseRedirect.
+
+Then, just instantiate your FormPreview subclass by passing it a Form class,
+and pass that to your URLconf, like so:
+
+ (r'^post/$', MyFormPreview(MyForm)),
+
+The FormPreview class has a few other hooks. See the docstrings in the source
+code below.
+
+The framework also uses two templates: 'formtools/preview.html' and
+'formtools/form.html'. You can override these by setting 'preview_template' and
+'form_template' attributes on your FormPreview subclass. See
+django/contrib/formtools/templates for the default templates.
+"""
+
+from django.conf import settings
+from django.core.exceptions import ImproperlyConfigured
+from django.http import Http404
+from django.shortcuts import render_to_response
+import cPickle as pickle
+import md5
+
+AUTO_ID = 'formtools_%s' # Each form here uses this as its auto_id parameter.
+
+class FormPreview(object):
+ preview_template = 'formtools/preview.html'
+ form_template = 'formtools/form.html'
+
+ # METHODS SUBCLASSES SHOULDN'T OVERRIDE ###################################
+
+ def __init__(self, form):
+ # form should be a Form class, not an instance.
+ self.form, self.state = form, {}
+
+ def __call__(self, request, *args, **kwargs):
+ stage = {'1': 'preview', '2': 'post'}.get(request.POST.get(self.unused_name('stage')), 'preview')
+ self.parse_params(*args, **kwargs)
+ try:
+ method = getattr(self, stage + '_' + request.method.lower())
+ except AttributeError:
+ raise Http404
+ return method(request)
+
+ def unused_name(self, name):
+ """
+ Given a first-choice name, adds an underscore to the name until it
+ reaches a name that isn't claimed by any field in the form.
+
+ This is calculated rather than being hard-coded so that no field names
+ are off-limits for use in the form.
+ """
+ while 1:
+ try:
+ f = self.form.fields[name]
+ except KeyError:
+ break # This field name isn't being used by the form.
+ name += '_'
+ return name
+
+ def preview_get(self, request):
+ "Displays the form"
+ f = self.form(auto_id=AUTO_ID)
+ return render_to_response(self.form_template, {'form': f, 'stage_field': self.unused_name('stage'), 'state': self.state})
+
+ def preview_post(self, request):
+ "Validates the POST data. If valid, displays the preview page. Else, redisplays form."
+ f = self.form(request.POST, auto_id=AUTO_ID)
+ context = {'form': f, 'stage_field': self.unused_name('stage'), 'state': self.state}
+ if f.is_valid():
+ context['hash_field'] = self.unused_name('hash')
+ context['hash_value'] = self.security_hash(request, f)
+ return render_to_response(self.preview_template, context)
+ else:
+ return render_to_response(self.form_template, context)
+
+ def post_post(self, request):
+ "Validates the POST data. If valid, calls done(). Else, redisplays form."
+ f = self.form(request.POST, auto_id=AUTO_ID)
+ if f.is_valid():
+ if self.security_hash(request, f) != request.POST.get(self.unused_name('hash')):
+ return self.failed_hash(request) # Security hash failed.
+ return self.done(request, f.clean_data)
+ else:
+ return render_to_response(self.form_template, {'form': f, 'stage_field': self.unused_name('stage'), 'state': self.state})
+
+ # METHODS SUBCLASSES MIGHT OVERRIDE IF APPROPRIATE ########################
+
+ def parse_params(self, *args, **kwargs):
+ """
+ Given captured args and kwargs from the URLconf, saves something in
+ self.state and/or raises Http404 if necessary.
+
+ For example, this URLconf captures a user_id variable:
+
+ (r'^contact/(?P Security hash: {{ hash_value }} s."
+ return self._html_output(u' %(label)s %(field)s %sPlease correct the following errors
{% else %}Submit
{% endif %}
+
+
+
+{% endblock %}
diff --git a/django/contrib/formtools/templates/formtools/preview.html b/django/contrib/formtools/templates/formtools/preview.html
new file mode 100644
index 0000000000..c7955d46e1
--- /dev/null
+++ b/django/contrib/formtools/templates/formtools/preview.html
@@ -0,0 +1,36 @@
+{% extends "base.html" %}
+
+{% block content %}
+
+Preview your submission
+
+
+{% for field in form %}
+
+
+
+
+{% endfor %}
+{{ field.verbose_name }}:
+{{ field.data|escape }}
+Or edit it again
+
+
+
+{% endblock %}
diff --git a/django/contrib/sitemaps/__init__.py b/django/contrib/sitemaps/__init__.py
index 2c76e13c22..44ede4460a 100644
--- a/django/contrib/sitemaps/__init__.py
+++ b/django/contrib/sitemaps/__init__.py
@@ -29,7 +29,7 @@ def ping_google(sitemap_url=None, ping_url=PING_URL):
from django.contrib.sites.models import Site
current_site = Site.objects.get_current()
- url = "%s%s" % (current_site.domain, sitemap)
+ url = "%s%s" % (current_site.domain, sitemap_url)
params = urllib.urlencode({'sitemap':url})
urllib.urlopen("%s?%s" % (ping_url, params))
diff --git a/django/core/servers/fastcgi.py b/django/core/servers/fastcgi.py
index fccb7bf087..649dd6942d 100644
--- a/django/core/servers/fastcgi.py
+++ b/django/core/servers/fastcgi.py
@@ -118,6 +118,8 @@ def runfastcgi(argset=[], **kwargs):
else:
return fastcgi_help("ERROR: Implementation must be one of prefork or thread.")
+ wsgi_opts['debug'] = False # Turn off flup tracebacks
+
# Prep up and go
from django.core.handlers.wsgi import WSGIHandler
diff --git a/django/newforms/fields.py b/django/newforms/fields.py
index b3d44c24ae..d676a1c58b 100644
--- a/django/newforms/fields.py
+++ b/django/newforms/fields.py
@@ -2,7 +2,8 @@
Field classes
"""
-from util import ValidationError, DEFAULT_ENCODING, smart_unicode
+from django.utils.translation import gettext
+from util import ValidationError, smart_unicode
from widgets import TextInput, CheckboxInput, Select, SelectMultiple
import datetime
import re
@@ -50,7 +51,7 @@ class Field(object):
Raises ValidationError for any errors.
"""
if self.required and value in EMPTY_VALUES:
- raise ValidationError(u'This field is required.')
+ raise ValidationError(gettext(u'This field is required.'))
return value
class CharField(Field):
@@ -64,9 +65,9 @@ class CharField(Field):
if value in EMPTY_VALUES: value = u''
value = smart_unicode(value)
if self.max_length is not None and len(value) > self.max_length:
- raise ValidationError(u'Ensure this value has at most %d characters.' % self.max_length)
+ raise ValidationError(gettext(u'Ensure this value has at most %d characters.') % self.max_length)
if self.min_length is not None and len(value) < self.min_length:
- raise ValidationError(u'Ensure this value has at least %d characters.' % self.min_length)
+ raise ValidationError(gettext(u'Ensure this value has at least %d characters.') % self.min_length)
return value
class IntegerField(Field):
@@ -81,7 +82,7 @@ class IntegerField(Field):
try:
return int(value)
except (ValueError, TypeError):
- raise ValidationError(u'Enter a whole number.')
+ raise ValidationError(gettext(u'Enter a whole number.'))
DEFAULT_DATE_INPUT_FORMATS = (
'%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y', # '2006-10-25', '10/25/2006', '10/25/06'
@@ -113,7 +114,7 @@ class DateField(Field):
return datetime.date(*time.strptime(value, format)[:3])
except ValueError:
continue
- raise ValidationError(u'Enter a valid date.')
+ raise ValidationError(gettext(u'Enter a valid date.'))
DEFAULT_DATETIME_INPUT_FORMATS = (
'%Y-%m-%d %H:%M:%S', # '2006-10-25 14:30:59'
@@ -149,7 +150,7 @@ class DateTimeField(Field):
return datetime.datetime(*time.strptime(value, format)[:6])
except ValueError:
continue
- raise ValidationError(u'Enter a valid date/time.')
+ raise ValidationError(gettext(u'Enter a valid date/time.'))
class RegexField(Field):
def __init__(self, regex, error_message=None, required=True, widget=None):
@@ -162,7 +163,7 @@ class RegexField(Field):
if isinstance(regex, basestring):
regex = re.compile(regex)
self.regex = regex
- self.error_message = error_message or u'Enter a valid value.'
+ self.error_message = error_message or gettext(u'Enter a valid value.')
def clean(self, value):
"""
@@ -185,7 +186,7 @@ email_re = re.compile(
class EmailField(RegexField):
def __init__(self, required=True, widget=None):
- RegexField.__init__(self, email_re, u'Enter a valid e-mail address.', required, widget)
+ RegexField.__init__(self, email_re, gettext(u'Enter a valid e-mail address.'), required, widget)
url_re = re.compile(
r'^https?://' # http:// or https://
@@ -203,7 +204,7 @@ except ImportError:
class URLField(RegexField):
def __init__(self, required=True, verify_exists=False, widget=None,
validator_user_agent=URL_VALIDATOR_USER_AGENT):
- RegexField.__init__(self, url_re, u'Enter a valid URL.', required, widget)
+ RegexField.__init__(self, url_re, gettext(u'Enter a valid URL.'), required, widget)
self.verify_exists = verify_exists
self.user_agent = validator_user_agent
@@ -223,9 +224,9 @@ class URLField(RegexField):
req = urllib2.Request(value, None, headers)
u = urllib2.urlopen(req)
except ValueError:
- raise ValidationError(u'Enter a valid URL.')
+ raise ValidationError(gettext(u'Enter a valid URL.'))
except: # urllib2.URLError, httplib.InvalidURL, etc.
- raise ValidationError(u'This URL appears to be a broken link.')
+ raise ValidationError(gettext(u'This URL appears to be a broken link.'))
return value
class BooleanField(Field):
@@ -254,7 +255,7 @@ class ChoiceField(Field):
return value
valid_values = set([str(k) for k, v in self.choices])
if value not in valid_values:
- raise ValidationError(u'Select a valid choice. %s is not one of the available choices.' % value)
+ raise ValidationError(gettext(u'Select a valid choice. %s is not one of the available choices.') % value)
return value
class MultipleChoiceField(ChoiceField):
@@ -266,11 +267,11 @@ class MultipleChoiceField(ChoiceField):
Validates that the input is a list or tuple.
"""
if self.required and not value:
- raise ValidationError(u'This field is required.')
+ raise ValidationError(gettext(u'This field is required.'))
elif not self.required and not value:
return []
if not isinstance(value, (list, tuple)):
- raise ValidationError(u'Enter a list of values.')
+ raise ValidationError(gettext(u'Enter a list of values.'))
new_value = []
for val in value:
val = smart_unicode(val)
@@ -279,7 +280,7 @@ class MultipleChoiceField(ChoiceField):
valid_values = set([k for k, v in self.choices])
for val in new_value:
if val not in valid_values:
- raise ValidationError(u'Select a valid choice. %s is not one of the available choices.' % val)
+ raise ValidationError(gettext(u'Select a valid choice. %s is not one of the available choices.') % val)
return new_value
class ComboField(Field):
diff --git a/django/newforms/forms.py b/django/newforms/forms.py
index 4bc6173249..e0b3d500b5 100644
--- a/django/newforms/forms.py
+++ b/django/newforms/forms.py
@@ -6,7 +6,7 @@ from django.utils.datastructures import SortedDict
from django.utils.html import escape
from fields import Field
from widgets import TextInput, Textarea, HiddenInput
-from util import ErrorDict, ErrorList, ValidationError
+from util import StrAndUnicode, ErrorDict, ErrorList, ValidationError
NON_FIELD_ERRORS = '__all__'
@@ -32,7 +32,7 @@ class DeclarativeFieldsMetaclass(type):
attrs['fields'] = SortedDictFromList(fields)
return type.__new__(cls, name, bases, attrs)
-class Form(object):
+class Form(StrAndUnicode):
"A collection of Fields, plus their associated data."
__metaclass__ = DeclarativeFieldsMetaclass
@@ -43,7 +43,7 @@ class Form(object):
self.clean_data = None # Stores the data after clean() has been called.
self.__errors = None # Stores the errors after clean() has been called.
- def __str__(self):
+ def __unicode__(self):
return self.as_table()
def __iter__(self):
@@ -72,41 +72,44 @@ class Form(object):
"""
return not self.ignore_errors and not bool(self.errors)
- def as_table(self):
- "Returns this form rendered as HTML s -- excluding the ."
- output = []
- if self.errors.get(NON_FIELD_ERRORS):
- # Errors not corresponding to a particular field are displayed at the top.
- output.append(u'
' % self.non_field_errors())
+ def _html_output(self, normal_row, error_row, row_ender, errors_on_separate_row):
+ "Helper function for outputting HTML. Used by as_table(), as_ul(), as_p()."
+ top_errors = self.non_field_errors() # Errors that should be displayed above all fields.
+ output, hidden_fields = [], []
for name, field in self.fields.items():
bf = BoundField(self, field, name)
+ bf_errors = bf.errors # Cache in local variable.
if bf.is_hidden:
- if bf.errors:
- new_errors = ErrorList(['(Hidden field %s) %s' % (name, e) for e in bf.errors])
- output.append(u'%s ' % new_errors)
- output.append(str(bf))
+ if bf_errors:
+ top_errors.extend(['(Hidden field %s) %s' % (name, e) for e in bf_errors])
+ hidden_fields.append(unicode(bf))
else:
- if bf.errors:
- output.append(u'%s ' % bf.errors)
- output.append(u'%s ' % (bf.label_tag(escape(bf.verbose_name+':')), bf))
+ if errors_on_separate_row and bf_errors:
+ output.append(error_row % bf_errors)
+ output.append(normal_row % {'errors': bf_errors, 'label': bf.label_tag(escape(bf.verbose_name+':')), 'field': bf})
+ if top_errors:
+ output.insert(0, error_row % top_errors)
+ if hidden_fields: # Insert any hidden fields in the last row.
+ str_hidden = u''.join(hidden_fields)
+ if output:
+ last_row = output[-1]
+ # Chop off the trailing row_ender (e.g. '') and insert the hidden fields.
+ output[-1] = last_row[:-len(row_ender)] + str_hidden + row_ender
+ else: # If there aren't any rows in the output, just append the hidden fields.
+ output.append(str_hidden)
return u'\n'.join(output)
+ def as_table(self):
+ "Returns this form rendered as HTML %s %s s -- excluding the ."
+ return self._html_output(u'
', u'%(label)s %(field)s ', '', True)
+
def as_ul(self):
"Returns this form rendered as HTML %s ."
- output = []
- if self.errors.get(NON_FIELD_ERRORS):
- # Errors not corresponding to a particular field are displayed at the top.
- output.append(u'
First name:
+Last name:
+Birthday:
With auto_id set, a HiddenInput still gets an ID, but it doesn't get a label. >>> p = Person(auto_id='id_%s') >>> print pFirst name:
+Last name:
+Birthday:
+ +A corner case: It's possible for a form to have only HiddenInputs. +>>> class TestForm(Form): +... foo = CharField(widget=HiddenInput) +... bar = CharField(widget=HiddenInput) +>>> p = TestForm() +>>> print p.as_table() + +>>> print p.as_ul() + +>>> print p.as_p() + A Form's fields are displayed in the same order in which they were defined. >>> class TestForm(Form): diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py index 3c31bb0604..0a41f5b5b7 100644 --- a/tests/regressiontests/templates/tests.py +++ b/tests/regressiontests/templates/tests.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- from django.conf import settings if __name__ == '__main__': @@ -62,6 +63,11 @@ class OtherClass: def method(self): return "OtherClass.method" +class UnicodeInStrClass: + "Class whose __str__ returns a Unicode object." + def __str__(self): + return u'ŠĐĆŽćžšđ' + class Templates(unittest.TestCase): def test_templates(self): # NOW and NOW_tz are used by timesince tag tests. @@ -173,6 +179,10 @@ class Templates(unittest.TestCase): # Empty strings can be passed as arguments to filters 'basic-syntax36': (r'{{ var|join:"" }}', {'var': ['a', 'b', 'c']}, 'abc'), + # If a variable has a __str__() that returns a Unicode object, the value + # will be converted to a bytestring. + 'basic-syntax37': (r'{{ var }}', {'var': UnicodeInStrClass()}, '\xc5\xa0\xc4\x90\xc4\x86\xc5\xbd\xc4\x87\xc5\xbe\xc5\xa1\xc4\x91'), + ### COMMENT SYNTAX ######################################################## 'comment-syntax01': ("{# this is hidden #}hello", {}, "hello"), 'comment-syntax02': ("{# this is hidden #}hello{# foo #}", {}, "hello"), @@ -328,18 +338,18 @@ class Templates(unittest.TestCase): 'ifchanged05': ('{% for n in num %}{% ifchanged %}{{ n }}{% endifchanged %}{% for x in numx %}{% ifchanged %}{{ x }}{% endifchanged %}{% endfor %}{% endfor %}', { 'num': (1, 1, 1), 'numx': (1, 2, 3)}, '1123123123'), 'ifchanged06': ('{% for n in num %}{% ifchanged %}{{ n }}{% endifchanged %}{% for x in numx %}{% ifchanged %}{{ x }}{% endifchanged %}{% endfor %}{% endfor %}', { 'num': (1, 1, 1), 'numx': (2, 2, 2)}, '1222'), 'ifchanged07': ('{% for n in num %}{% ifchanged %}{{ n }}{% endifchanged %}{% for x in numx %}{% ifchanged %}{{ x }}{% endifchanged %}{% for y in numy %}{% ifchanged %}{{ y }}{% endifchanged %}{% endfor %}{% endfor %}{% endfor %}', { 'num': (1, 1, 1), 'numx': (2, 2, 2), 'numy': (3, 3, 3)}, '1233323332333'), - + # Test one parameter given to ifchanged. 'ifchanged-param01': ('{% for n in num %}{% ifchanged n %}..{% endifchanged %}{{ n }}{% endfor %}', { 'num': (1,2,3) }, '..1..2..3'), 'ifchanged-param02': ('{% for n in num %}{% for x in numx %}{% ifchanged n %}..{% endifchanged %}{{ x }}{% endfor %}{% endfor %}', { 'num': (1,2,3), 'numx': (5,6,7) }, '..567..567..567'), - + # Test multiple parameters to ifchanged. 'ifchanged-param03': ('{% for n in num %}{{ n }}{% for x in numx %}{% ifchanged x n %}{{ x }}{% endifchanged %}{% endfor %}{% endfor %}', { 'num': (1,1,2), 'numx': (5,6,6) }, '156156256'), - + # Test a date+hour like construct, where the hour of the last day # is the same but the date had changed, so print the hour anyway. 'ifchanged-param04': ('{% for d in days %}{% ifchanged %}{{ d.day }}{% endifchanged %}{% for h in d.hours %}{% ifchanged d h %}{{ h }}{% endifchanged %}{% endfor %}{% endfor %}', {'days':[{'day':1, 'hours':[1,2,3]},{'day':2, 'hours':[3]},] }, '112323'), - + # Logically the same as above, just written with explicit # ifchanged for the day. 'ifchanged-param04': ('{% for d in days %}{% ifchanged d.day %}{{ d.day }}{% endifchanged %}{% for h in d.hours %}{% ifchanged d.day h %}{{ h }}{% endifchanged %}{% endfor %}{% endfor %}', {'days':[{'day':1, 'hours':[1,2,3]},{'day':2, 'hours':[3]},] }, '112323'),