Code

Opened 9 years ago

Closed 6 years ago

#541 closed enhancement (fixed)

[patch] Making generic views use other templates like Zope3 ZPT

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

Description (last modified by jacob)

Hi!

I was wondering if it is possible to use other template engines with generic views.

I think making template_loader a parameter of object_list at file list_detail.py, with default value django.core.template_loader should make it flexible enough to use any template engine.

The user could, then, switch to zope3 zpt by adding a key on the dict of the url patterns parameter, like this:

from django.contrib.pagetemplate import pagetemplate

info_dict = {
  'app_label': 'myapp',
  'app_module': 'mymodule',
  'template_loader': pagetemplate,
}

Hope this will be helpful.

--
João Paulo Fernandes Farias

Attachments (1)

template_loader_for_direct_to_template.patch (1005 bytes) - added by burp_ 6 years ago.
template_loader argument for direct_to_template in simple.py

Download all attachments as: .zip

Change History (11)

comment:1 Changed 9 years ago by jacob

  • Description modified (diff)
  • Status changed from new to assigned

Sounds like a great idea. I'll add this when I get a moment, but if you want to write a patch that will make it happen quicker.

comment:2 Changed 9 years ago by jpaulofarias@…

Patch bellow!

Index: django/views/generic/list_detail.py
===================================================================
--- django/views/generic/list_detail.py (revisão 661)
+++ django/views/generic/list_detail.py (cópia de trabalho)
@@ -7,7 +7,8 @@
 from django.core.exceptions import Http404, ObjectDoesNotExist

 def object_list(request, app_label, module_name, paginate_by=None, allow_empty=False,
-                template_name=None, extra_lookup_kwargs={}, extra_context={}):
+                template_name=None, template_loader=template_loader,
+                extra_lookup_kwargs={}, extra_context={}):
     """
     Generic list of objects.

@@ -76,7 +77,8 @@

 def object_detail(request, app_label, module_name, object_id=None, slug=None,
                   slug_field=None, template_name=None, template_name_field=None,
-                  extra_lookup_kwargs={}, extra_context={}):
+                  template_loader=template_loader, extra_lookup_kwargs={},
+                  extra_context={}):
     """
     Generic list of objects.

comment:3 Changed 9 years ago by jacob

  • milestone set to Version 1.0
  • Summary changed from Making generic views use other templates like Zope3 ZPT to [patch] Making generic views use other templates like Zope3 ZPT

comment:4 Changed 9 years ago by jacob

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

(In [734]) Fixed #541 - generic views now may take a template_loader argument so they can use a different template loader than Django's own. Thanks, Joao.

comment:5 Changed 7 years ago by anonymous

  • milestone Version 1.0 deleted

Milestone Version 1.0 deleted

comment:6 Changed 6 years ago by burp_

  • Needs tests set
  • Patch needs improvement set
  • Resolution fixed deleted
  • Status changed from closed to reopened
  • Version set to 1.0

Since the integration of simple.py in revision @1247 jacob did not include the template_loader argument in direct_to_template. This dead simple patch does it ;)

Changed 6 years ago by burp_

template_loader argument for direct_to_template in simple.py

comment:7 Changed 6 years ago by burp_

PS: It would be nice to have this also in django.contrib.auth.views: http://code.djangoproject.com/ticket/4247

In my case I could reuse these view functions and use my own template system. Otherwise I'd just to copy these views functions over and replace the render_to_response things with my own one.

comment:8 Changed 6 years ago by mtredinnick

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

Please open a new ticket for new feature requests. This ticket was already fixed ages ago and you're essentially asking for a new feature. That way we can keep the history of this ticket clean and decide independently if we want to add the new feature or not.

comment:9 Changed 6 years ago by burp_

  • Resolution fixed deleted
  • Status changed from closed to reopened

I was asking for a "feature" in my PS, but not before (I made 3 posts/changes in total). The change before asks for consistency in generic views.

Just as the template_loader argument is in _all_ other generic views, it should also be in direct_to_template. It's clear why it hasn't this feature. In revision 743 when this extra argument was introduced direct_to_template did not exist, and later when direct_to_template was added in revision 1247 jacob simply forgot to make it consistent with the other generic views.

comment:10 Changed 6 years ago by mtredinnick

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

Once again, this particular ticket was closed over three years ago. If something has changed since then, please open a new ticket so that we can track it appropriately. If we decide to "wontfix" your particular changes, for example, it would currently require setting "wontfix" on a ticket that has already been marked as fixed.

Please do not reopen this one.

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.