And ... yes there does seem to be a better way.

Define own version of "changelist_view" e.g.:

    def changelist_view(self, request, extra_context=None):
        extra_context={ 'has_delete_permission': self.has_delete_permission
(request) }
        return super(MyCommentsAdmin, self).changelist_view(request,
extra_context)

However - as this post suggests - http://bit.ly/7ZrKHl - is this
thread safe?
Thanks for any thoughts anyone.

R






On Nov 20, 5:02 pm, rd-london <roland.d...@gmail.com> wrote:
> Right, I've worked out why this is:
>
> django/contrib/admin/options.py - def changelist_view(self, request,
> extra_context=None): contains the line:
>
>         context = {
>             'title': cl.title,
>             'is_popup': cl.is_popup,
>             'cl': cl,
>             'media': media,
>             'has_add_permission': self.has_add_permission(request),
>             'root_path': self.admin_site.root_path,
>             'app_label': app_label,
>             'action_form': action_form,
>             'actions_on_top': self.actions_on_top,
>             'actions_on_bottom': self.actions_on_bottom,
>         }
>
> So, it doesn't add "has_delete_permission" to the context (nor
> "has_change_permission") for that matter. Simple fix:
>
>         context = {
>             'title': cl.title,
>             'is_popup': cl.is_popup,
>             'cl': cl,
>             'media': media,
>             'has_add_permission': self.has_add_permission(request),
> addedhere     --->       'has_delete_permission':
> self.has_delete_permission(request),         <----- added here
>             'root_path': self.admin_site.root_path,
>             'app_label': app_label,
>             'action_form': action_form,
>             'actions_on_top': self.actions_on_top,
>             'actions_on_bottom': self.actions_on_bottom,
>         }
>
> ... but ... but ... surely that comes from the land of Harry the
> Hacker?
> Isn't there a better way to do this, or is this a genuine bug?
>
> Any help or thoughts very welcome,
>
> Cheers
> R
>
> On Nov 20, 3:18 pm, rd-london <roland.d...@gmail.com> wrote:
>
> > Hi,
> > Wonder if anyone can help.
>
> > Have following chunk in my own change_list.html template:
>
> >     {% block object-tools %}
> >         <ul class="object-tools">
> >           {% if has_add_permission %}
> >           <li>
> >             <a href="add/{% if is_popup %}?_popup=1{% endif %}"
> > title="Add Comment" class="addlink">
> >               {% blocktrans with cl.opts.verbose_name as name %}Add
> > {{ name }}{% endblocktrans %}
> >             </a>
> >           </li>
> >           {% endif %}
> >           {% if has_delete_permission %}
> >           <li>
> > My thing goes here</li>
> >           </li>
> >           {% endif %}
> >         </ul>
>
> >     {% endblock %}
>
> > Created a user that has delete permissions. Got my own ModelAdmin and
> > have checked using the debugger that the user does indeed have delete
> > permissions.
>
> > The "def has_add_permission" fn in contrib/admin/options.py *is* being
> > called (I've put "import pdb;pdb.set_trace()" there to check), whereas
> > def has_delete_permission is not - and I can't work out for the life
> > of me why not.
>
> > Anyone help at all?
>
> > Thanks,
> > R

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=.


Reply via email to