commit
a03422dcb7
@ -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
|
||||||
|
@ -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/'
|
||||||
|
Loading…
Reference in New Issue
Block a user