Code

Opened 7 years ago

Closed 4 years ago

#5392 closed (fixed)

[newforms-admin] - hooks for template names

Reported by: Petr Marhoun <petr.marhoun@…> Owned by: nobody
Component: contrib.admin Version: newforms-admin
Severity: Keywords: nfa-someday
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: UI/UX:

Description

I think it is possible to have more admin sites in one project. And it would be nice to have different default templates for these two sites - these templates should be independent on application.

So I would like to have some hooks as changelist_templates, add_templates and so on. For example this code could be changed:

class ModelAdmin(BaseModelAdmin):

    def changelist_view(self, request):
        ### ...
        return render_to_response(['admin/%s/%s/change_list.html' % (app_label, opts.object_name.lower()),
                                'admin/%s/change_list.html' % app_label,
                                'admin/change_list.html'], context_instance=c)

New variant:

class ModelAdmin(BaseModelAdmin):

    def changelist_view(self, request):
        ### ...
        return render_to_response(self.changelist_templates(app_label, opts.object_name.lower()), context_instance=c)

    def changelist_templates(self, app_label, object_label):
        return ['admin/%s/%s/change_list.html' % (app_label, opts.object_name.lower()),
            'admin/%s/change_list.html' % app_label,
            'admin/change_list.html']


I haven't need it yet so I have no patch. But it is no problem for me to create it - if you think it is a good idea.

Attachments (2)

04-admin-template-names.diff (7.9 KB) - added by Petr Marhoun <petr.marhoun@…> 6 years ago.
02-admin-template-names.diff (8.0 KB) - added by Petr Marhoun <petr.marhoun@…> 6 years ago.
new version depends on #6002 and on #6010 - they change the same places

Download all attachments as: .zip

Change History (7)

comment:1 Changed 7 years ago by Petr Marhoun <petr.marhoun@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Why is the function render_change_form in views/main.py? I think it could be a method of ModelAdmin. This move would be usefull for this ticket.

> grep render_change_form django/contrib/admin/** --line-number 
django/contrib/admin/options.py:411:        from django.contrib.admin.views.main import render_change_form
django/contrib/admin/options.py:462:        return render_change_form(self, model, model.AddManipulator(), c, add=True)
django/contrib/admin/options.py:466:        from django.contrib.admin.views.main import render_change_form
django/contrib/admin/options.py:540:        return render_change_form(self, model, model.ChangeManipulator(object_id), c, change=True)
django/contrib/admin/views/main.py:113:def render_change_form(model_admin, model, manipulator, context, add=False, change=False, form_url=''):

comment:2 Changed 7 years ago by Simon G. <dev@…>

  • Triage Stage changed from Unreviewed to Design decision needed

Changed 6 years ago by Petr Marhoun <petr.marhoun@…>

comment:3 Changed 6 years ago by Petr Marhoun <petr.marhoun@…>

I am sorry, my patch depends on some other patches - it is for simple merging. So my patch can't be applied without problem. But I would like to prepare proper patch, if it would be accepted.

comment:4 Changed 6 years ago by brosner

  • Keywords nfa-someday added; newforms, admin, templates removed
  • Patch needs improvement set

This functionality is not critical before the merge to trunk. Tagging with nfa-someday.

Changed 6 years ago by Petr Marhoun <petr.marhoun@…>

new version depends on #6002 and on #6010 - they change the same places

comment:5 Changed 4 years ago by mtredinnick

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

This is now possible to you things like ModelAdmin.change_list_template in the current admin.

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.