Digital Rights Management für elektronische Patientenakten
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

forms.py 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from django import forms
  2. from .models import License
  3. from django.db.models import Q
  4. from django.contrib.auth.models import User
  5. from health_view.models import Permission
  6. class CreateLicenseForm(forms.ModelForm):
  7. class Meta:
  8. model = License
  9. fields = ('patient', 'justified', 'exp_date', 'folder_parts', 'permissions', 'signature',)
  10. def __init__(self, current_user, *args, **kwargs):
  11. super(CreateLicenseForm, self).__init__(*args, **kwargs)
  12. license = License.objects.filter(justified=current_user).order_by('patient')
  13. conditions = Q(id='0')
  14. for li in license:
  15. print(li.patient_id)
  16. conditions |= Q(id=li.patient_id)
  17. self.fields['permissions'] = forms.ModelMultipleChoiceField(queryset=Permission.objects.all())
  18. if License.objects.filter(justified=current_user).exists() and License.objects.filter(license_creator=current_user).exists():
  19. self.fields['patient'].queryset = User.objects.filter(conditions).distinct()
  20. elif License.objects.filter(justified=current_user).exists():
  21. conditions |= Q(username=current_user.username)
  22. self.fields['patient'].queryset = User.objects.filter(conditions).distinct()
  23. elif License.objects.filter(license_creator=current_user).exists():
  24. self.fields['patient'].queryset = User.objects.filter(username="-")
  25. else:
  26. self.fields['patient'].queryset = User.objects.filter(username=current_user.username)
  27. class CreateLicenseForm_filled(forms.Form):
  28. patient = forms.CharField()
  29. justified = forms.CharField()
  30. license_creator = forms.CharField()
  31. exp_date = forms.CharField()
  32. folder_parts = forms.CharField()
  33. permissions = forms.CharField()
  34. signature = forms.CharField()