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] class Meta: model = Settings fields = "__all__"
[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 ExaminationForm(forms.ModelForm):
[docs] class Meta: model = Examination fields = "__all__"
[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 RefusalForm(ExaminationDependentForm):
[docs] class Meta: model = Refusal fields = [ "material_name", "value", ]
[docs] class ReductionForm(forms.ModelForm):
[docs] class Meta: model = Reduction fields = [ "reduction_type", "value", ]
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 PhotoForm(forms.ModelForm):
[docs] class Meta: model = Photo fields = [ "image_file", ]
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)