base for allowing locationgroups in access
This commit is contained in:
parent
6d1083ecd7
commit
45b5e82d22
1 changed files with 23 additions and 2 deletions
|
@ -1,12 +1,12 @@
|
|||
from django.forms import ModelForm, MultipleChoiceField
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import ugettext_lazy as _, ungettext_lazy
|
||||
|
||||
from c3nav.access.models import AccessToken, AccessUser
|
||||
from c3nav.mapdata.models import AreaLocation
|
||||
|
||||
|
||||
def get_permissions_field(request):
|
||||
locations = AreaLocation.objects.filter(routing_inclusion='needs_permission')
|
||||
locations = AreaLocation.objects.filter(routing_inclusion='needs_permission').order_by('name')
|
||||
|
||||
has_operator = True
|
||||
try:
|
||||
|
@ -26,6 +26,27 @@ def get_permissions_field(request):
|
|||
else:
|
||||
locations = []
|
||||
|
||||
if can_full:
|
||||
OPTIONS.append((':full', _('Full Permissions')))
|
||||
|
||||
locationgroups = {}
|
||||
locationgroups_count = {}
|
||||
for location in locations:
|
||||
for group in location.groups.all():
|
||||
if group.location_id not in locationgroups:
|
||||
locationgroups[group.location_id] = group
|
||||
locationgroups_count[group.location_id] = 0
|
||||
locationgroups_count[group.location_id] += 1
|
||||
|
||||
locationgroup_options = []
|
||||
for location_id, group in locationgroups.items():
|
||||
locationgroup_options.append((location_id, _('%(grouptitle)s (%(count)s nonpublic locations)') % {
|
||||
'grouptitle': group.title,
|
||||
'count': locationgroups_count[location_id]
|
||||
}))
|
||||
|
||||
OPTIONS += sorted(locationgroup_options)
|
||||
|
||||
if can_full:
|
||||
OPTIONS.append((':full', _('Full Permissions')))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue