Merge pull request #630 from ostcar/Issue604

Fixed #604
This commit is contained in:
Oskar Hahn 2013-04-28 01:05:22 -07:00
commit a03422dcb7
2 changed files with 23 additions and 2 deletions

View File

@ -106,6 +106,18 @@ class MotionCategoryMixin(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/')
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):
url = '/motion/1/edit/'