Пример #1
0
 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)
Пример #2
0
 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
Пример #3
0
    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
Пример #6
0
 def save(self, commit=True):
     place = PlaceService.create(name=self.cleaned_data[NAME])
     return place
Пример #7
0
 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()
Пример #8
0
 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)
Пример #9
0
 def delete(self, request: HttpRequest, id: str):
     id = self.parse_int_pk(id)
     PlaceService.delete(id)
     return ApiResponse.success()
Пример #10
0
 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))
Пример #11
0
 def get(self, request: HttpRequest, id: str):
     id = self.parse_int_pk(id)
     place = PlaceService.get(id)
     return ApiResponse.success(PlaceOutDto.from_place(place))
Пример #12
0
 def post(self, request: HttpRequest, dto: PlaceInDto):
     place = PlaceService.create(dto.name)
     return ApiResponse.success(PlaceOutDto.from_place(place))
Пример #13
0
 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)
Пример #14
0
 def save(self, commit=True):
     place = PlaceService.update(id=self.cleaned_data[ID],
                                 name=self.cleaned_data[NAME])
     return place
Пример #15
0
 def get_queryset(self):
     try:
         return PlaceService.get_doors(id=self.kwargs[ID])
     except:
         raise Http404
Пример #16
0
class PlaceMultipleChoiceForm(forms.Form):
    door_id = forms.IntegerField(widget=forms.HiddenInput)
    places = forms.ModelMultipleChoiceField(queryset=PlaceService.get_none(),
                                            widget=CheckboxSelectMultiple)
Пример #17
0
 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)
Пример #18
0
 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)
Пример #19
0
class PlaceRuleForm(forms.Form):
    places = forms.ModelMultipleChoiceField(queryset=PlaceService.get_all(),
                                            widget=CheckboxSelectMultiple)