from django import forms from django.db import models from django.contrib.auth.models import User from users.models import AgencyGroup, Agency, Profile, AgencyJob from PIL import Image # Change logged Users Data (Usernamen an Email) NUR HIER MÖGLICH! class UsersSelfChangeForm(forms.ModelForm): email = forms.EmailField() class Meta: model = User fields = ['email'] # Form für die Benachrichtigungseinstellungen class UsersNotificationForm(forms.ModelForm): class Meta: model = Profile labels = { "news_mail" : "Agentur-News", "user_standard_public_mail" : "Veröffentlichung meiner Standards", "agency_new_standard_mail" : "Neue Agentur-Standards", 'add_new_group_mail' : "Gruppenmitgliedschaften", 'add_task_mail' : "Tätigkeitsbereich" } fields = ['news_mail', 'news_push', 'user_standard_public_mail', 'user_standard_public_push', 'agency_new_standard_mail', 'agency_new_standard_push', 'add_new_group_mail', 'add_new_group_push', 'add_task_mail', 'add_task_push'] # PERMISSION GROUPS FORM class AgencyGroupPerms(forms.Form): ''' Permission-System Persmissions werden im Model gesetzt, hier automatisch als Form ausgegeben. Hat der Nutzer eine der genannten Rechte, wird die Checkbox automatisch TRUE gesetzt. Die erstellen Felder werden entsprechend den Feldern hinzugefügt und ausgegeben. @param: user - User ist der aufgerufene User! ''' def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) temprof = AgencyGroup for ele in temprof._meta.permissions: self.fields[ele[0]] = forms.BooleanField(required=False, initial=False, help_text=(ele[1])) # LOADING ALL MODUL-OPTIONS class AgencyModulsForm(forms.ModelForm): class Meta: model = Agency labels = { 'module_news' : "Agentur-News", 'module_quicklinks' : "Quicklinks", 'module_files' : "Dateien", 'module_organigramm' : "Organigramm", } fields = ['module_news','module_quicklinks','module_files','module_organigramm'] # NEW USER FORM class UserNewUserForm(forms.ModelForm): class Meta: model = User fields = ["first_name", "last_name", "email"] # NEW USER PROFILE FORM class UserProfileForm(forms.ModelForm): x = forms.FloatField(widget=forms.HiddenInput()) y = forms.FloatField(widget=forms.HiddenInput()) width = forms.FloatField(widget=forms.HiddenInput()) height = forms.FloatField(widget=forms.HiddenInput()) rotation = forms.FloatField(widget=forms.HiddenInput()) class Meta: model = Profile labels = { "persnumber" : "Personalnummer", "visible" : "Im Organigramm sichtbar", "phonemobile" : "Mobilnummer", "phoneland" : "Festnetznummer", "image": "Profilbild", "func" : "Agenturfunktion", "compfunc" : "Tätigkeit" } widgets = {"parent" : forms.HiddenInput()} fields = ["parent", "func", "compfunc", "visible", "phoneland", "phonemobile", "persnumber", "image" ] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['func'].queryset = AgencyJob.objects.filter(agency__pk=self.instance.agency.pk) def save(self): photo = super(UserProfileForm, self).save() try: x = self.cleaned_data.get('x') y = self.cleaned_data.get('y') w = self.cleaned_data.get('width') h = self.cleaned_data.get('height') rotation = self.cleaned_data.get('rotation') image = Image.open(photo.image) rotatet_image = image.rotate(rotation, expand=True) cropped_image = rotatet_image.crop((x, y, w+x, h+y)) resized_image = cropped_image.resize((300, 300), Image.ANTIALIAS) resized_image.save(photo.image.path) return photo except: print("no photo")