vkk.workhours.accounting.projects.project.forms

A collection of forms used in this module.

 1"""
 2A collection of forms used in this module.
 3"""
 4
 5from django import forms
 6from django.core.exceptions import ValidationError
 7from django.utils.translation import gettext_lazy as _
 8from vkk.workhours.models import ProjectAssignment, WorkHours, WorkHoursCorrection
 9
10
11class ContributorDeleteForm(forms.ModelForm):
12    """
13    A `ModelForm` subclass for deleting a `ProjectAssignment`.
14    """
15    id = None
16    class Meta:
17        model = ProjectAssignment
18        fields = []
19
20    def __init__(self, id, *args, **kwargs):
21        """
22        Initializes and returns an object of this class. An `id` of a `ProjectAssignment` must be provided.
23        """
24        self.id = id
25        super().__init__(*args, **kwargs)
26
27    def clean(self):
28        """
29        Cleans the form and returns its cleaned data as an dictionary. No additional data must be associated
30        with the given `ProjectAssignment` (ie. `WorkHours`) for this to be successfull.
31        """
32        workhours_exist = WorkHours.objects.filter(
33            project_assignment__id=self.id
34        ).exists()
35        if workhours_exist:
36            raise ValidationError(
37                _('This project assignment cannot be deleted unless all associated workhours are deleted!'),
38                code='workhours_exist'
39            )
40        corrections_exist = WorkHoursCorrection.objects.filter(
41            project_assignment__id=self.id
42        ).exists()
43        if corrections_exist:
44            raise ValidationError(
45                _('This project assignment cannot be deleted unless all associated workhours corrections are deleted!'),
46                code='corrections_exist'
47            )
48        return self.cleaned_data
class ContributorDeleteForm(django.forms.models.ModelForm):
12class ContributorDeleteForm(forms.ModelForm):
13    """
14    A `ModelForm` subclass for deleting a `ProjectAssignment`.
15    """
16    id = None
17    class Meta:
18        model = ProjectAssignment
19        fields = []
20
21    def __init__(self, id, *args, **kwargs):
22        """
23        Initializes and returns an object of this class. An `id` of a `ProjectAssignment` must be provided.
24        """
25        self.id = id
26        super().__init__(*args, **kwargs)
27
28    def clean(self):
29        """
30        Cleans the form and returns its cleaned data as an dictionary. No additional data must be associated
31        with the given `ProjectAssignment` (ie. `WorkHours`) for this to be successfull.
32        """
33        workhours_exist = WorkHours.objects.filter(
34            project_assignment__id=self.id
35        ).exists()
36        if workhours_exist:
37            raise ValidationError(
38                _('This project assignment cannot be deleted unless all associated workhours are deleted!'),
39                code='workhours_exist'
40            )
41        corrections_exist = WorkHoursCorrection.objects.filter(
42            project_assignment__id=self.id
43        ).exists()
44        if corrections_exist:
45            raise ValidationError(
46                _('This project assignment cannot be deleted unless all associated workhours corrections are deleted!'),
47                code='corrections_exist'
48            )
49        return self.cleaned_data

A ModelForm subclass for deleting a ProjectAssignment.

ContributorDeleteForm(id, *args, **kwargs)
21    def __init__(self, id, *args, **kwargs):
22        """
23        Initializes and returns an object of this class. An `id` of a `ProjectAssignment` must be provided.
24        """
25        self.id = id
26        super().__init__(*args, **kwargs)

Initializes and returns an object of this class. An id of a ProjectAssignment must be provided.

id = None
def clean(self):
28    def clean(self):
29        """
30        Cleans the form and returns its cleaned data as an dictionary. No additional data must be associated
31        with the given `ProjectAssignment` (ie. `WorkHours`) for this to be successfull.
32        """
33        workhours_exist = WorkHours.objects.filter(
34            project_assignment__id=self.id
35        ).exists()
36        if workhours_exist:
37            raise ValidationError(
38                _('This project assignment cannot be deleted unless all associated workhours are deleted!'),
39                code='workhours_exist'
40            )
41        corrections_exist = WorkHoursCorrection.objects.filter(
42            project_assignment__id=self.id
43        ).exists()
44        if corrections_exist:
45            raise ValidationError(
46                _('This project assignment cannot be deleted unless all associated workhours corrections are deleted!'),
47                code='corrections_exist'
48            )
49        return self.cleaned_data

Cleans the form and returns its cleaned data as an dictionary. No additional data must be associated with the given ProjectAssignment (ie. WorkHours) for this to be successfull.

media

Return all media required to render the widgets on this form.

declared_fields = {}
base_fields = {}
Inherited Members
django.forms.models.BaseModelForm
validate_unique
save
django.forms.forms.BaseForm
default_renderer
field_order
prefix
use_required_attribute
template_name_div
template_name_p
template_name_table
template_name_ul
template_name_label
is_bound
data
files
auto_id
initial
error_class
label_suffix
empty_permitted
fields
renderer
order_fields
errors
is_valid
add_prefix
add_initial_prefix
template_name
get_context
non_field_errors
add_error
has_error
full_clean
has_changed
changed_data
is_multipart
hidden_fields
visible_fields
get_initial_for_field
django.forms.utils.RenderableFormMixin
as_p
as_table
as_ul
as_div
django.forms.utils.RenderableMixin
render
class ContributorDeleteForm.Meta:
17    class Meta:
18        model = ProjectAssignment
19        fields = []
fields = []