templatetags: introduce |has_role_uuid (#64495)
This commit is contained in:
parent
6ded861e97
commit
2d04e39274
|
@ -359,9 +359,7 @@ if PROJECT_NAME != 'wcs':
|
|||
if 'authentic2' not in INSTALLED_APPS:
|
||||
MELLON_ADAPTER = ('hobo.multitenant.mellon.MellonAdapter',)
|
||||
|
||||
if PROJECT_NAME in ('wcs', 'combo'):
|
||||
TEMPLATES[0]['OPTIONS'].setdefault('builtins', []).append('hobo.templatetags.hobo')
|
||||
|
||||
TEMPLATES[0]['OPTIONS'].setdefault('builtins', []).append('hobo.templatetags.hobo')
|
||||
|
||||
if 'authentic2' not in INSTALLED_APPS:
|
||||
MELLON_DEFAULT_ASSERTION_CONSUMER_BINDING = 'artifact'
|
||||
|
|
|
@ -144,7 +144,7 @@ def theme_base(request):
|
|||
# * theme_base will get evaluated when encountered in a template and return
|
||||
# a template string downloaded from settings.THEME_SKELETON_URL.
|
||||
#
|
||||
# * theme_404 is identical but dedicated to 404 erorr pages.
|
||||
# * theme_404 is identical but dedicated to 404 error pages.
|
||||
#
|
||||
# Both those variables are to be used by "slave" sites, authentic,
|
||||
# w.c.s., etc.
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import decimal
|
||||
import sys
|
||||
|
||||
from django import template
|
||||
from django.utils.translation import get_language
|
||||
|
@ -59,3 +60,14 @@ def as_numeral_currency(number):
|
|||
return num2words(unlazy(number), lang=get_language(), to='currency')
|
||||
except (TypeError, ValueError, decimal.InvalidOperation):
|
||||
return ''
|
||||
|
||||
|
||||
@register.filter
|
||||
def has_role_uuid(user, role_uuid):
|
||||
if not user or not user.is_authenticated:
|
||||
return False
|
||||
if 'authentic2' in sys.modules:
|
||||
return user.roles.filter(uuid=role_uuid).exists()
|
||||
elif 'wcs' in sys.modules:
|
||||
return role_uuid in user.roles
|
||||
return user.groups.filter(role__uuid=role_uuid).exists()
|
||||
|
|
Loading…
Reference in New Issue