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 get_table() -> Table: persons = PersonService.get_all() data = [] for person in persons: data.append({ 'person': person, 'keys': PersonService.get_keys(id=person.id), 'roles': PersonService.get_roles(id=person.id) }) return PersonHomePageTable(data=data)
class KeyCreateForm(forms.ModelForm): name = forms.CharField(widget=TextInput, help_text='Key name') access_key = forms.CharField(widget=TextInput, help_text='Access key') person = forms.ModelChoiceField(queryset=PersonService.get_all(), help_text='Choose person for key', empty_label='Choose person', widget=forms.Select) class Meta: model = Key fields = ['name', 'access_key', 'person'] def save(self, commit=True): key = KeyService.create(name=self.cleaned_data['name'], access_key=self.cleaned_data['access_key'], person_id=self.cleaned_data['person'].id) return key
def get(self, request: HttpRequest): personnel = PersonService.get_all() person_dtos = list([PersonOutDto.from_person(p) for p in personnel]) return ApiResponse.success(person_dtos)