remove AccessUserForm
This commit is contained in:
parent
f13fb0a899
commit
281f01b8a0
1 changed files with 27 additions and 30 deletions
|
@ -1,44 +1,41 @@
|
||||||
from django.forms import ModelForm, MultipleChoiceField
|
from django.forms import ModelForm, MultipleChoiceField
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from c3nav.access.models import AccessToken, AccessUser
|
from c3nav.access.models import AccessToken
|
||||||
from c3nav.mapdata.models import AreaLocation
|
from c3nav.mapdata.models import AreaLocation
|
||||||
|
|
||||||
|
|
||||||
class AccessUserForm(ModelForm):
|
def get_permissions_field(request):
|
||||||
class Meta:
|
locations = AreaLocation.objects.filter(routing_inclusion='needs_permission')
|
||||||
model = AccessUser
|
|
||||||
fields = ['user_url', 'description']
|
has_operator = True
|
||||||
|
try:
|
||||||
|
request.user.operator
|
||||||
|
except:
|
||||||
|
has_operator = False
|
||||||
|
|
||||||
|
OPTIONS = []
|
||||||
|
can_full = False
|
||||||
|
if request.user.is_superuser:
|
||||||
|
can_full = True
|
||||||
|
elif has_operator:
|
||||||
|
can_award = request.user.operator.can_award_permissions.split(';')
|
||||||
|
can_full = ':full' in can_award
|
||||||
|
locations = locations.filter(name__in=can_award)
|
||||||
|
else:
|
||||||
|
locations = []
|
||||||
|
|
||||||
|
if can_full:
|
||||||
|
OPTIONS.append((':full', _('Full Permissions')))
|
||||||
|
|
||||||
|
OPTIONS += [(location.name, location.title) for location in locations]
|
||||||
|
return MultipleChoiceField(choices=OPTIONS, required=True)
|
||||||
|
|
||||||
|
|
||||||
class AccessTokenForm(ModelForm):
|
class AccessTokenForm(ModelForm):
|
||||||
def __init__(self, *args, request, **kwargs):
|
def __init__(self, *args, request, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
locations = AreaLocation.objects.filter(routing_inclusion='needs_permission')
|
self.fields['permissions'] = get_permissions_field(request)
|
||||||
|
|
||||||
has_operator = True
|
|
||||||
try:
|
|
||||||
request.user.operator
|
|
||||||
except:
|
|
||||||
has_operator = False
|
|
||||||
|
|
||||||
OPTIONS = []
|
|
||||||
can_full = False
|
|
||||||
if request.user.is_superuser:
|
|
||||||
can_full = True
|
|
||||||
elif has_operator:
|
|
||||||
can_award = request.user.operator.can_award_permissions.split(';')
|
|
||||||
can_full = ':full' in can_award
|
|
||||||
locations = locations.filter(name__in=can_award)
|
|
||||||
else:
|
|
||||||
locations = []
|
|
||||||
|
|
||||||
if can_full:
|
|
||||||
OPTIONS.append((':full', _('Full Permissions')))
|
|
||||||
|
|
||||||
OPTIONS += [(location.name, location.title) for location in locations]
|
|
||||||
print(OPTIONS)
|
|
||||||
self.fields['permissions'] = MultipleChoiceField(choices=OPTIONS, required=True)
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = AccessToken
|
model = AccessToken
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue