This commit is contained in:
Oskar Hahn 2013-04-28 10:02:19 +02:00
parent 50077f1c03
commit 04edef9d8a
2 changed files with 23 additions and 2 deletions

View File

@ -106,6 +106,18 @@ class MotionCategoryMixin(forms.ModelForm):
class MotionIdentifierMixin(forms.ModelForm): class MotionIdentifierMixin(forms.ModelForm):
"""Mixin to let the user choose the identifier for the motion.""" """
Mixin to let the user choose the identifier for the motion.
"""
identifier = forms.CharField(required=False, label=ugettext_lazy("Identifier")) identifier = forms.CharField(required=False, label=ugettext_lazy('Identifier'))
def clean_identifier(self):
"""
Test, that the identifier is unique
"""
identifier = self.cleaned_data['identifier']
if Motion.objects.filter(identifier=identifier).exists():
raise forms.ValidationError(_('The Identifier is not unique.'))
else:
return identifier

View File

@ -119,6 +119,15 @@ class TestMotionCreateView(MotionViewTestCase):
response = self.staff_client.get('/motion/') response = self.staff_client.get('/motion/')
self.assertContains(response, 'href="/motion/new/"', status_code=200) self.assertContains(response, 'href="/motion/new/"', status_code=200)
def test_identifier_not_unique(self):
Motion.objects.create(identifier='foo')
response = self.admin_client.post(self.url, {'title': 'foo',
'text': 'bar',
'submitter': self.admin,
'identifier': 'foo'})
self.assertFormError(response, 'form', 'identifier', 'The Identifier is not unique.')
class TestMotionUpdateView(MotionViewTestCase): class TestMotionUpdateView(MotionViewTestCase):
url = '/motion/1/edit/' url = '/motion/1/edit/'