def save(self): if self.cleaned_data[PLACE_ID]: place_id = self.cleaned_data[PLACE_ID] doors = self.cleaned_data[DOORS] for door in doors: PlaceService.detach_door(place_id=place_id, door_id=door.id) if self.cleaned_data[CONTROLLER_ID]: controller_id = self.cleaned_data[CONTROLLER_ID] doors = self.cleaned_data[DOORS] for door in doors: ControllerService.detach_door(controller_id=controller_id, door_id=door.id)
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): place_id = kwargs.pop(PLACE_ID, None) super(DoorAttachToPlaceForm, self).__init__(*args, **kwargs) if place_id: self.fields[PLACE_ID].initial = place_id doors = PlaceService.get_untouched_doors(id=place_id) self.fields[DOORS].queryset = doors self.fields[DOORS].empty_label = None
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
def person_allow_place(person_id: int, place_id: int) -> PersonACLEntry: person = PersonService.get(person_id) place = PlaceService.get(place_id) if PersonACLEntry.objects.filter( person=person, place=place, type=AclType.ACL_ALLOW).count() > 0: raise exceptions.AclAlreadyAdded try: return PersonACLEntry.objects.create(person=person, place=place, type=AclType.ACL_ALLOW) except: raise exceptions.ACLManageFailed
def save(self, commit=True): place = PlaceService.create(name=self.cleaned_data[NAME]) return place
def delete(self, request: HttpRequest, place_id: str, door_id: str): place_id = self.parse_int_pk(place_id) door_id = self.parse_int_pk(door_id) PlaceService.detach_door(place_id, door_id) return ApiResponse.success()
def get(self, request: HttpRequest, id: str): id = self.parse_int_pk(id) doors = PlaceService.get_doors(id) door_dtos = list([DoorOutDto.from_door(d) for d in doors]) return ApiResponse.success(door_dtos)
def delete(self, request: HttpRequest, id: str): id = self.parse_int_pk(id) PlaceService.delete(id) return ApiResponse.success()
def put(self, request: HttpRequest, id: str, dto: PlaceInDto): id = self.parse_int_pk(id) place = PlaceService.update(id, dto.name) return ApiResponse.success(PlaceOutDto.from_place(place))
def get(self, request: HttpRequest, id: str): id = self.parse_int_pk(id) place = PlaceService.get(id) return ApiResponse.success(PlaceOutDto.from_place(place))
def post(self, request: HttpRequest, dto: PlaceInDto): place = PlaceService.create(dto.name) return ApiResponse.success(PlaceOutDto.from_place(place))
def get(self, request: HttpRequest): places = PlaceService.get_all() place_dtos = list([PlaceOutDto.from_place(p) for p in places]) return ApiResponse.success(place_dtos)
def save(self, commit=True): place = PlaceService.update(id=self.cleaned_data[ID], name=self.cleaned_data[NAME]) return place
def get_queryset(self): try: return PlaceService.get_doors(id=self.kwargs[ID]) except: raise Http404
class PlaceMultipleChoiceForm(forms.Form): door_id = forms.IntegerField(widget=forms.HiddenInput) places = forms.ModelMultipleChoiceField(queryset=PlaceService.get_none(), widget=CheckboxSelectMultiple)
def save(self): place_id = self.cleaned_data[PLACE_ID] doors = self.cleaned_data[DOORS] for door in doors: PlaceService.attach_door(place_id=place_id, door_id=door.id)
def save(self): places = self.cleaned_data['places'] door_id = self.cleaned_data['door_id'] for place in places: PlaceService.detach_door(place_id=place.id, door_id=door_id)
class PlaceRuleForm(forms.Form): places = forms.ModelMultipleChoiceField(queryset=PlaceService.get_all(), widget=CheckboxSelectMultiple)