def get_context_data(self, **kwargs): context = super(Home, self).get_context_data(**kwargs) context['table'] = self.get_table() context['person_count'] = PersonService.get_all().count() context['keys_count'] = KeyService.get_all().count() context['roles_count'] = RoleService.get_all().count() context['places_count'] = PlaceService.get_all().count() return context
def __init__(self, *args, **kwargs): role_id = kwargs.pop(ROLE_ID, None) super(PersonDetachForm, self).__init__(*args, **kwargs) if role_id: self.fields[ROLE_ID].initial = role_id persons = RoleService.get_persons(id=role_id) self.fields[PERSONS].queryset = persons self.fields[PERSONS].empty_label = None
def detach_role(person_id: int, role_id: int): person = get(person_id) role = RoleService.get(role_id) if person.roles.filter(id=role_id).count() == 0: raise exceptions.RoleNotFound try: person.roles.remove(role) except: raise exceptions.PersonManageFailed
def role_deny_place(role_id: int, place_id: int) -> RoleACLEntry: role = RoleService.get(role_id) place = PlaceService.get(place_id) if RoleACLEntry.objects.filter( role=role, place=place, type=AclType.ACL_DENY).count() > 0: raise exceptions.AclAlreadyAdded try: return RoleACLEntry.objects.create(role=role, place=place, type=AclType.ACL_DENY) except: raise exceptions.ACLManageFailed
class RoleDetachForm(forms.Form): person_id = forms.IntegerField(widget=forms.HiddenInput) roles = forms.ModelMultipleChoiceField(queryset=RoleService.get_none(), widget=CheckboxSelectMultiple) def __init__(self, *args, **kwargs): person_id = kwargs.pop('person_id', None) super(RoleDetachForm, self).__init__(*args, **kwargs) if person_id: self.fields['person_id'].initial = person_id roles = PersonService.get_roles(id=person_id) self.fields['roles'].queryset = roles self.fields['roles'].empty_label = None def save(self): person_id = self.cleaned_data['person_id'] roles = self.cleaned_data['roles'] for role in roles: PersonService.detach_role(person_id=person_id, role_id=role.id)
def get_queryset(self): try: return RoleService.get_persons(id=self.get_obj_id()) except: raise Http404
def save(self, commit=True): role = RoleService.update(id=self.cleaned_data['id'], name=self.cleaned_data['name']) return role
def save(self, commit=True): role = RoleService.create(name=self.cleaned_data['name']) return role
def get_role_acls(role_id: int) -> List[RoleACLEntry]: role = RoleService.get(role_id) try: return list(role.roleaclentry_set.all()) except: raise exceptions.SomethingWrong