vkk.workhours.accounting.projects.project.forms

 1from django import forms
 2from django.core.exceptions import ValidationError
 3from django.utils.translation import gettext_lazy as _
 4from vkk.workhours.models import ProjectAssignment, WorkHours, WorkHoursCorrection
 5
 6
 7class ContributorDeleteForm(forms.ModelForm):
 8    class Meta:
 9        model = ProjectAssignment
10        fields = []
11
12    def clean(self):
13        workhours_exist = WorkHours.objects.filter().exists()
14        if workhours_exist:
15            raise ValidationError(
16                _('This project assignment cannot be deleted unless all associated workhours are deleted!'),
17                code='workhours_exist'
18            )
19        corrections_exist = WorkHoursCorrection.objects.filter().exists()
20        if corrections_exist:
21            raise ValidationError(
22                _('This project assignment cannot be deleted unless all associated workhours corrections are deleted!'),
23                code='corrections_exist'
24            )
25        return self.cleaned_data
class ContributorDeleteForm(django.forms.models.ModelForm):
 8class ContributorDeleteForm(forms.ModelForm):
 9    class Meta:
10        model = ProjectAssignment
11        fields = []
12
13    def clean(self):
14        workhours_exist = WorkHours.objects.filter().exists()
15        if workhours_exist:
16            raise ValidationError(
17                _('This project assignment cannot be deleted unless all associated workhours are deleted!'),
18                code='workhours_exist'
19            )
20        corrections_exist = WorkHoursCorrection.objects.filter().exists()
21        if corrections_exist:
22            raise ValidationError(
23                _('This project assignment cannot be deleted unless all associated workhours corrections are deleted!'),
24                code='corrections_exist'
25            )
26        return self.cleaned_data

The main implementation of all the Form logic. Note that this class is different than Form. See the comments by the Form class for more info. Any improvements to the form API should be made to this class, not to the Form class.

def clean(self):
13    def clean(self):
14        workhours_exist = WorkHours.objects.filter().exists()
15        if workhours_exist:
16            raise ValidationError(
17                _('This project assignment cannot be deleted unless all associated workhours are deleted!'),
18                code='workhours_exist'
19            )
20        corrections_exist = WorkHoursCorrection.objects.filter().exists()
21        if corrections_exist:
22            raise ValidationError(
23                _('This project assignment cannot be deleted unless all associated workhours corrections are deleted!'),
24                code='corrections_exist'
25            )
26        return self.cleaned_data

Hook for doing any extra form-wide cleaning after Field.clean() has been called on every field. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field named '__all__'.

media

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

Inherited Members
django.forms.models.BaseModelForm
BaseModelForm
validate_unique
save
django.forms.forms.BaseForm
order_fields
errors
is_valid
add_prefix
add_initial_prefix
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:
 9    class Meta:
10        model = ProjectAssignment
11        fields = []