Code

Opened 8 years ago

Closed 8 years ago

Last modified 7 years ago

#1399 closed enhancement (fixed)

[patch] [magic removal branch] Add 'template_model_name' to generic view list_detail.py

Reported by: ChaosKCW Owned by: jacob
Component: Generic views Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

the generic views currently in the Magic-removal branch reference the the object or objects with the keyword 'object' or 'object_list' represetivly. This makes the templates rendering the page more obscure.

Example:

{% if survey_list %}
   ...
    {% for survey in survey_list %}
       ....
    {% endfor %}
....
{% endif %}

vs

{% if object_list %}
   ...
    {% for survey in object_list %}
       ....
    {% endfor %}
....
{% endif %}

I propose adding a new parameter called 'template_model_name' to the generic view. This will enable templates to be far more elegant and intutive. I also feel this would make generic templates more 'Djangoified' ie I think it fits with Django philsophies on creating a amzingly simple to use and clean web development framework.

An Example of how this can be called in the URLConf is as follows:

!#python
urlpatterns = patterns('',
    (r'^survey/(?P<object_id>\d+)/$', 'django.views.generic.list_detail.object_detail', {'queryset': Survey.objects.all(), 'template_model_name': 'survey'}),
    (r'^list/$', 'django.views.generic.list_detail.object_list', {'queryset': Survey.objects.all(), 'template_model_name': 'survey', 'template_name': 'survey/index'})
)

Please see the attach patch.

Notice that I have included the a default on the argument 'template_model_name' and set it to 'object'. This means this patch can go in and never effect any code which doesnt want to use it. It will only come into effect if you add the extra argument into the URLConf setup, else everything works as before.

Attachments (1)

django_template_model_name.diff (2.1 KB) - added by ChaosKCW 8 years ago.
A Patch to add 'template_model_name' to generic views

Download all attachments as: .zip

Change History (2)

Changed 8 years ago by ChaosKCW

A Patch to add 'template_model_name' to generic views

comment:1 Changed 8 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

(In [2453]) Fixed #1399 -- Added template_object_name hook to generic views. Thanks, ChaosKCW

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.