Source code for ferrosoft.apps.befundung.forms
from django import forms
from django.forms import formset_factory
from django.utils.translation import gettext_lazy as _
from ferrosoft.apps.befundung.models import (
Settings,
Examination,
Refusal,
Reduction,
Photo,
)
[docs]
class SettingsForm(forms.ModelForm):
_REQUIRED_SFTP_SETTINGS = [
"sftp_hostname",
"sftp_username",
"sftp_remote_dir",
"sftp_client_key",
"sftp_host_key",
]
[docs]
def clean(self):
data = super().clean()
upload_enabled = (
data["sftp_enable_document_upload"] or data["sftp_enable_image_upload"]
)
if upload_enabled:
for required_setting in self._REQUIRED_SFTP_SETTINGS:
if data[required_setting] == "":
self.add_error(
required_setting,
_("This field is required in order to enable DMS upload"),
)
[docs]
class ExaminationDependentForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
self.examination = kwargs.pop("examination", None)
super().__init__(*args, **kwargs)
[docs]
def save(self, commit=True):
self.instance.examination = self.examination
super().save(commit)
[docs]
class ReductionForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
self.examination = kwargs.pop("examination", None)
super().__init__(*args, **kwargs)
[docs]
def save(self, commit=True):
self.instance.examination = self.examination
super().save(commit)