1
0
mirror of https://github.com/django/django.git synced 2025-07-04 17:59:13 +00:00

Templatised date_hierarchy.

git-svn-id: http://code.djangoproject.com/svn/django/branches/new-admin@1129 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Robert Wittams 2005-11-08 23:31:47 +00:00
parent 24cdaa77fa
commit 29cce749fa
3 changed files with 47 additions and 25 deletions

View File

@ -0,0 +1,8 @@
<div class="xfull">
<ul class="toplinks">
{% if back %}<li class="date-back"><a href="{{back.link}}">&lsaquo; {{back.title}}</a></li>{% endif %}
{% for choice in choices %}
<li> {% if choice.link%}<a href="{{choice.link}}">{%endif%}{{choice.title}}{%if choice.link%}</a>{%endif%}</li>
{% endfor %}
</ul><br class="clear" />
</div>

View File

@ -222,12 +222,11 @@ def result_list(cl):
result_list = inclusion_tag("admin/change_list_results")(result_list)
#@simple_tag
#@inclusion_tag("admin/date_hierarchy")
def date_hierarchy(cl):
lookup_opts, params, lookup_params, lookup_mod = \
cl.lookup_opts, cl.params, cl.lookup_params, cl.lookup_mod
raw_template = []
if lookup_opts.admin.date_hierarchy:
field_name = lookup_opts.admin.date_hierarchy
@ -238,35 +237,52 @@ def date_hierarchy(cl):
year_lookup = params.get(year_field)
month_lookup = params.get(month_field)
day_lookup = params.get(day_field)
raw_template.append('<div class="xfull">\n<ul class="toplinks">\n')
def link(d):
return cl.get_query_string(d, [field_generic])
def get_dates(unit, params):
return getattr(lookup_mod, 'get_%s_list' % field_name)(unit, **params)
if year_lookup and month_lookup and day_lookup:
raw_template.append('<li class="date-back"><a href="%s">&lsaquo; %s %s </a></li>' % \
(cl.get_query_string( {year_field: year_lookup, month_field: month_lookup}, [field_generic]), MONTHS[int(month_lookup)], year_lookup))
raw_template.append('<li>%s %s</li>' % (MONTHS[int(month_lookup)], day_lookup))
month_name = MONTHS[int(month_lookup)]
return { 'back':
{ 'link' : link({year_field: year_lookup, month_field: month_lookup}),
'title': "%s %s" % ( month_name, year_lookup),
},
'choices': [ {'title': "%s %s" % ( month_name, day_lookup)} ]
}
elif year_lookup and month_lookup:
raw_template.append('<li class="date-back"><a href="%s">&lsaquo; %s</a></li>' % \
(cl.get_query_string( {year_field: year_lookup}, [field_generic]), year_lookup))
date_lookup_params = lookup_params.copy()
date_lookup_params.update({year_field: year_lookup, month_field: month_lookup})
for day in getattr(lookup_mod, 'get_%s_list' % field_name)('day', **date_lookup_params):
raw_template.append('<li><a href="%s">%s</a></li>' % \
(cl.get_query_string({year_field: year_lookup, month_field: month_lookup, day_field: day.day}, [field_generic]), day.strftime('%B %d')))
days = get_dates('day', date_lookup_params)
return { 'back':
{ 'link' : link({year_field: year_lookup}),
'title' : year_lookup
},
'choices':
[ { 'link' : link({year_field: year_lookup, month_field: month_lookup, day_field: day.day}),
'title': day.strftime('%B %d') } for day in days ]
}
elif year_lookup:
raw_template.append('<li class="date-back"><a href="%s">&lsaquo; %s</a></li>' % \
cl.get_query_string( {}, [year_field]), _('All dates'))
date_lookup_params = lookup_params.copy()
date_lookup_params.update({year_field: year_lookup})
for month in getattr(lookup_mod, 'get_%s_list' % field_name)('month', **date_lookup_params):
raw_template.append('<li><a href="%s">%s %s</a></li>' % \
(cl.get_query_string( {year_field: year_lookup, month_field: month.month}, [field_generic]), month.strftime('%B'), month.year))
months = get_dates('month', date_lookup_params)
return { 'back':
{ 'link' : link({}),
'title': _('All dates')
},
'choices':
[ { 'link': link( {year_field: year_lookup, month_field: month.month}),
'title': "%s %s" % (month.strftime('%B') , month.year) } for month in months ]
}
else:
for year in getattr(lookup_mod, 'get_%s_list' % field_name)('year', **lookup_params):
raw_template.append('<li><a href="%s">%s</a></li>\n' % \
(cl.get_query_string( {year_field: year.year}, [field_generic]), year.year))
raw_template.append('</ul><br class="clear" />\n</div>\n')
return ''.join(raw_template)
date_hierarchy = simple_tag(date_hierarchy)
years = get_dates('year', lookup_params)
return { 'choices':
[ { 'link': link( {year_field: year.year}),
'title': year.year } for year in years ]
}
date_hierarchy = inclusion_tag('admin/date_hierarchy')(date_hierarchy)
#@inclusion_tag('admin/search_form')
def search_form(cl):

View File

@ -120,7 +120,6 @@ class RelatedFilterSpec(FilterSpec):
FilterSpec.register(lambda f: bool(f.rel), RelatedFilterSpec)
class ChoicesFilterSpec(FilterSpec):
def __init__(self, f, request, params):
super(ChoicesFilterSpec, self).__init__(f, request, params)
self.lookup_kwarg = '%s__exact' % f.name
@ -173,7 +172,6 @@ class DateFieldFilterSpec(FilterSpec):
FilterSpec.register(lambda f: isinstance(f, meta.DateField), DateFieldFilterSpec)
class BooleanFieldFilterSpec(FilterSpec):
def __init__(self, f, request, params):
super(BooleanFieldFilterSpec, self).__init__(f, request, params)
self.lookup_kwarg = '%s__exact' % f.name