Code

#18991 closed New feature (fixed)

Allow the use of 'app_name.perm_name' in perms in templates

Reported by: akaariai Owned by: nobody
Component: Template system Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Now that we have smart if tag, it seems natural to look up permissions by

{% if 'someapp.someperm' in perms %}
  Permission found!
{% endif %}

In addition to feeling more natural to me, this has two additional benefits:

  • If is possible to look up permissions containing characters which aren't allowed by template variable resoultion: if perms.someapp.some-perm doesn't work for example.
  • The exact same syntax is likely to work in other template engines, too (think Jinja2).

I have implemented this in https://github.com/akaariai/django/compare/perm_in_perms

I hope to push this into 1.5.

Attachments (0)

Change History (3)

comment:1 Changed 22 months ago by akaariai

I forgot to mention that the above branch contains the fix for #18979, too. So, that is the !EQLimiterObject stuff in the patch...

comment:2 Changed 22 months ago by akaariai

A pull created: https://github.com/django/django/pull/404

BTW, there is another benefit of the alternate syntax: permission lookups using variables.

There isn't support for perm_obj in perms, only the string syntax is supported. Using Permission objects directly would be a natural extensions to this feature...

comment:3 Changed 22 months ago by Anssi Kääriäinen <akaariai@…>

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

In d5a4f209c3889a76a23a19f3212ab2d7b5c62e1c:

Fixed #18991 -- Allowed permission lookup by "if in"

When looking permissions from PermWrapper it is now possible to use
{% if "someapp.someperm" in perms %} instead of
{% if perms.someapp.someperm %}.

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.