mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 14:13:21 +00:00
add some validationErrors on OperationForm
This commit is contained in:
parent
1bcde80a28
commit
0e171fbc8f
@ -282,7 +282,9 @@ class Operation(models.Model):
|
|||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
super(Operation, self).clean()
|
super(Operation, self).clean()
|
||||||
if self.date < self.journal.start_date:
|
if self.date is None:
|
||||||
|
raise ValidationError(_("The date must be set."))
|
||||||
|
elif self.date < self.journal.start_date:
|
||||||
raise ValidationError(_("""The date can not be before the start date of the journal, which is
|
raise ValidationError(_("""The date can not be before the start date of the journal, which is
|
||||||
%(start_date)s.""") % {'start_date': defaultfilters.date(self.journal.start_date, settings.DATE_FORMAT)})
|
%(start_date)s.""") % {'start_date': defaultfilters.date(self.journal.start_date, settings.DATE_FORMAT)})
|
||||||
if self.target_type != "OTHER" and self.get_target() is None:
|
if self.target_type != "OTHER" and self.get_target() is None:
|
||||||
|
@ -28,7 +28,7 @@ from django.shortcuts import render
|
|||||||
from django.core.urlresolvers import reverse_lazy, reverse
|
from django.core.urlresolvers import reverse_lazy, reverse
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.forms.models import modelform_factory
|
from django.forms.models import modelform_factory
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied, ValidationError
|
||||||
from django.forms import HiddenInput, TextInput
|
from django.forms import HiddenInput, TextInput
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.db.models import Sum
|
from django.db.models import Sum
|
||||||
@ -305,6 +305,9 @@ class OperationForm(forms.ModelForm):
|
|||||||
def clean(self):
|
def clean(self):
|
||||||
self.cleaned_data = super(OperationForm, self).clean()
|
self.cleaned_data = super(OperationForm, self).clean()
|
||||||
if 'target_type' in self.cleaned_data.keys():
|
if 'target_type' in self.cleaned_data.keys():
|
||||||
|
if self.cleaned_data.get("user") is None or self.cleaned_data.get("club") or self.cleaned_data.get("club_account") is None or self.cleaned_data.get("company") is None or self.cleaned_data.get("other"):
|
||||||
|
self.add_error('target_id', ValidationError(_("The target must be set.")))
|
||||||
|
else:
|
||||||
if self.cleaned_data['target_type'] == "USER":
|
if self.cleaned_data['target_type'] == "USER":
|
||||||
self.cleaned_data['target_id'] = self.cleaned_data['user'].id
|
self.cleaned_data['target_id'] = self.cleaned_data['user'].id
|
||||||
elif self.cleaned_data['target_type'] == "ACCOUNT":
|
elif self.cleaned_data['target_type'] == "ACCOUNT":
|
||||||
@ -313,6 +316,10 @@ class OperationForm(forms.ModelForm):
|
|||||||
self.cleaned_data['target_id'] = self.cleaned_data['club'].id
|
self.cleaned_data['target_id'] = self.cleaned_data['club'].id
|
||||||
elif self.cleaned_data['target_type'] == "COMPANY":
|
elif self.cleaned_data['target_type'] == "COMPANY":
|
||||||
self.cleaned_data['target_id'] = self.cleaned_data['company'].id
|
self.cleaned_data['target_id'] = self.cleaned_data['company'].id
|
||||||
|
|
||||||
|
if self.cleaned_data.get("amount") is None:
|
||||||
|
self.add_error('amount', ValidationError(_("The amount must be set.")))
|
||||||
|
|
||||||
return self.cleaned_data
|
return self.cleaned_data
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user