Removed 'use_numeric_months' parameter in generic date views (from [308]) in favor of something more powerful -- you can now provide month_format and day_format, which are format strings that specify how you expect the month and day to be formatted in the URL.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@312 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
48441f467f
commit
7d574e8f76
|
@ -85,8 +85,8 @@ def archive_year(request, year, app_label, module_name, date_field,
|
|||
return HttpResponse(t.render(c))
|
||||
|
||||
def archive_month(request, year, month, app_label, module_name, date_field,
|
||||
use_numeric_months=False, template_name=None,
|
||||
extra_lookup_kwargs={}, extra_context={}):
|
||||
month_format='%b', template_name=None, extra_lookup_kwargs={},
|
||||
extra_context={}):
|
||||
"""
|
||||
Generic monthly archive view.
|
||||
|
||||
|
@ -97,14 +97,8 @@ def archive_month(request, year, month, app_label, module_name, date_field,
|
|||
object_list:
|
||||
list of objects published in the given month
|
||||
"""
|
||||
if use_numeric_months:
|
||||
try:
|
||||
date = datetime.date(int(year), int(month), 1)
|
||||
except (ValueError, TypeError):
|
||||
raise Http404
|
||||
else:
|
||||
try:
|
||||
date = datetime.date(*time.strptime(year+month, '%Y%b')[:3])
|
||||
date = datetime.date(*time.strptime(year+month, '%Y'+month_format)[:3])
|
||||
except ValueError:
|
||||
raise Http404
|
||||
|
||||
|
@ -143,8 +137,8 @@ def archive_month(request, year, month, app_label, module_name, date_field,
|
|||
return HttpResponse(t.render(c))
|
||||
|
||||
def archive_day(request, year, month, day, app_label, module_name, date_field,
|
||||
use_numeric_months=False, template_name=None, extra_lookup_kwargs={},
|
||||
extra_context={}, allow_empty=False):
|
||||
month_format='%b', day_format='%d', template_name=None,
|
||||
extra_lookup_kwargs={}, extra_context={}, allow_empty=False):
|
||||
"""
|
||||
Generic daily archive view.
|
||||
|
||||
|
@ -159,14 +153,8 @@ def archive_day(request, year, month, day, app_label, module_name, date_field,
|
|||
next_day
|
||||
(datetime) the next day, or None if the current day is today
|
||||
"""
|
||||
if use_numeric_months:
|
||||
try:
|
||||
date = datetime.date(int(year), int(month), int(day))
|
||||
except (ValueError, TypeError):
|
||||
raise Http404
|
||||
else:
|
||||
try:
|
||||
date = datetime.date(*time.strptime(year+month+day, '%Y%b%d')[:3])
|
||||
date = datetime.date(*time.strptime(year+month+day, '%Y'+month_format+day_format)[:3])
|
||||
except ValueError:
|
||||
raise Http404
|
||||
|
||||
|
@ -211,9 +199,9 @@ def archive_today(request, **kwargs):
|
|||
return archive_day(request, **kwargs)
|
||||
|
||||
def object_detail(request, year, month, day, app_label, module_name, date_field,
|
||||
use_numeric_months=False, object_id=None, slug=None, slug_field=None,
|
||||
template_name=None, template_name_field=None, extra_lookup_kwargs={},
|
||||
extra_context={}):
|
||||
month_format='%b', day_format='%d', object_id=None, slug=None,
|
||||
slug_field=None, template_name=None, template_name_field=None,
|
||||
extra_lookup_kwargs={}, extra_context={}):
|
||||
"""
|
||||
Generic detail view from year/month/day/slug or year/month/day/id structure.
|
||||
|
||||
|
@ -222,14 +210,8 @@ def object_detail(request, year, month, day, app_label, module_name, date_field,
|
|||
object:
|
||||
the object to be detailed
|
||||
"""
|
||||
if use_numeric_months:
|
||||
try:
|
||||
date = datetime.date(int(year), int(month), int(day))
|
||||
except (ValueError, TypeError):
|
||||
raise Http404
|
||||
else:
|
||||
try:
|
||||
date = datetime.date(*time.strptime(year+month+day, '%Y%b%d')[:3])
|
||||
date = datetime.date(*time.strptime(year+month+day, '%Y'+month_format+day_format)[:3])
|
||||
except ValueError:
|
||||
raise Http404
|
||||
|
||||
|
|
|
@ -126,9 +126,13 @@ The date-based generic functions are:
|
|||
|
||||
``archive_month``
|
||||
Monthly archive. Requires that ``year`` and ``month`` arguments be given.
|
||||
You may pass the additional option ``use_numeric_months`` if you'd like to
|
||||
use URLs that use numbers instead of names for months (i.e. ``/2005/01/15/``
|
||||
instead of ``/2005/jan/15/``.
|
||||
You can pass the additional option ``month_format`` if you'd like to change
|
||||
the way months are specified in the URL.
|
||||
|
||||
``month_format`` is a format string in the same syntax accepted by Python's
|
||||
``time.strftime``. (See the `strftime docs`_.) It's set to ``"%b"`` by
|
||||
default, which is a three-letter month abbreviation. To change it to use
|
||||
numbers, use ``"%m"``.
|
||||
|
||||
Uses the template ``app_label/module_name__archive_month`` by default.
|
||||
|
||||
|
@ -143,6 +147,10 @@ The date-based generic functions are:
|
|||
Daily archive. Requires that ``year``, ``month``, and ``day`` arguments be
|
||||
given.
|
||||
|
||||
As in ``archive_month``, you can pass an optional ``month_format``. You can
|
||||
also pass ``day_format``, which defaults to ``"%d"`` (day of the month as a
|
||||
decimal number, 1-31).
|
||||
|
||||
Uses the template ``app_label/module_name__archive_day`` by default.
|
||||
|
||||
Has the following template context:
|
||||
|
@ -177,6 +185,11 @@ The date-based generic functions are:
|
|||
You can also pass the ``template_name_field`` argument to indicate that the
|
||||
the object stores the name of its template in a field on the object itself.
|
||||
|
||||
As in ``archive_day``, ``object_detail`` takes optional ``month_format``
|
||||
and ``day_format`` parameters.
|
||||
|
||||
.. _strftime docs: http://www.python.org/doc/current/lib/module-time.html#l2h-1941
|
||||
|
||||
Using list/detail generic views
|
||||
===============================
|
||||
|
||||
|
|
Loading…
Reference in New Issue