Skip to content

Commit

Permalink
Add context_keys to TemplatesGenerator for Django 1.5 support
Browse files Browse the repository at this point in the history
MODEL_NAME_archive_year.html uses 'year' the context of YearArchiveView.

But, on Django 1.5, it is returned as a date object.

So the template must use 'year.year'.

In order to maintain backward compatibility, add context_keys and
set proper key depending on the version of Django.
  • Loading branch information
drillbits committed Mar 8, 2013
1 parent 2d11bca commit 09450ff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions generate_scaffold/generators/templates.py
@@ -1,5 +1,6 @@
import os

from django import VERSION as DJANGO_VERSION
from django.template import Context
from django.template.defaultfilters import slugify
from django.template.loader import get_template
Expand Down Expand Up @@ -27,6 +28,10 @@ def render_templates(
model, timestamp_fieldname)
is_timestamped = True if timestamp_field else False

context_keys = {
'year': 'year.year' if DJANGO_VERSION >= (1, 5) else 'year'
}

for template_template in template_templates:

if not is_timestamped and '_archive' in template_template:
Expand All @@ -44,6 +49,7 @@ def render_templates(
'class_name': class_name,
'filename': dst_abspath,
'is_timestamped': is_timestamped,
'context_keys': context_keys
}
if is_timestamped:
c['timestamp_field'] = timestamp_field.name
Expand Down
Expand Up @@ -20,15 +20,15 @@
</span>
</li>
<li>
<a href='{% templatetag openblock %} url '{{ app_name }}_{{ model_slug }}_year_archive' year=year {% templatetag closeblock %}'>
<a href='{% templatetag openblock %} url '{{ app_name }}_{{ model_slug }}_year_archive' year={{ context_keys.year }} {% templatetag closeblock %}'>
{% templatetag openblock %} trans "{% trans "Year Archive" %}" {% templatetag closeblock %}
</a>
</li>
</ul>
{% templatetag openblock %} endblock {% templatetag closeblock %}

{% templatetag openblock %} block header-link {% templatetag closeblock %}
<a href='{% templatetag openblock %} url '{{ app_name }}_{{ model_slug }}_year_archive' year=year {% templatetag closeblock %}'>
<a href='{% templatetag openblock %} url '{{ app_name }}_{{ model_slug }}_year_archive' year={{ context_keys.year }} {% templatetag closeblock %}'>
{% templatetag openblock %} trans "{% blocktrans %}{{ class_name }} Year Archive{% endblocktrans %}" {% templatetag closeblock %}
</a>
{% templatetag openblock %} endblock {% templatetag closeblock %}
Expand Down

0 comments on commit 09450ff

Please sign in to comment.