Open markherringer opened 8 years ago
Hi @meomancer, have a look at this code that I got from another project:
def has_group(user, group):
return user.groups.filter(name=group).exists()
def has_group_X(user):
return has_group(user, 'X')
__author__ = 'Christian Christelis <christian@kartoza.com>'
__date__ = '09/05/16'
from django import template
from django.contrib.auth.models import Group
register = template.Library()
@register.filter(name='has_group')
def has_group(user, group_name):
#See more at: http://www.abidibo.net/blog/2014/05/22/check-if-user-belongs-group-django-templates/#sthash.Xvt0mtkv.dpuf
group = Group.objects.get(name=group_name)
return True if group in user.groups.all() else False
In views:
@user_passes_test(has_group_approval)
In templates
{% if user|has_group:"X" %}
{% endif %}
@cchristelis it seems that models has already "is_datacaptor", "is_admin" should we just use that? and /healthsites is already restrict to just datacaptor and admin i am not sure how to do it
@meomancer, restricting the 'model' is a bit of a misnomer, I think. The things that you can restrict are views and template sections.
https://docs.google.com/spreadsheets/d/1afgU-U5q1uMTkq1Ash2ELogQkPhNzHaK1BUJHXQxMS4/edit?usp=sharing