From 96c5b1d2dcb3c599cff896bf946531c5caba852f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Thu, 20 Jun 2013 17:57:15 +0200 Subject: [PATCH] Fix numbering with category prefix in simple workflow, fix #769 --- openslides/motion/views.py | 20 ++++++++++++++------ tests/motion/test_views.py | 12 +++++++++++- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/openslides/motion/views.py b/openslides/motion/views.py index 6c19b78f4..d52207fc2 100644 --- a/openslides/motion/views.py +++ b/openslides/motion/views.py @@ -98,10 +98,6 @@ class MotionEditMixin(object): Saves the CreateForm or UpdateForm into a motion object. """ self.object = form.save(commit=False) - self.manipulate_object(form) - - for attr in ['title', 'text', 'reason']: - setattr(self.version, attr, form.cleaned_data[attr]) try: self.object.category = form.cleaned_data['category'] @@ -113,6 +109,11 @@ class MotionEditMixin(object): except KeyError: pass + self.manipulate_object(form) + + for attr in ['title', 'text', 'reason']: + setattr(self.version, attr, form.cleaned_data[attr]) + self.object.save(use_version=self.version) # Save the submitter an the supporter so the motion. @@ -195,10 +196,13 @@ class MotionCreateView(MotionEditMixin, CreateView): return initial def manipulate_object(self, form): - self.version = self.object.get_new_version() - + """ + Sets first state according to given or default workflow and initiates + a new version. + """ workflow = form.cleaned_data.get('workflow', config['motion_workflow']) self.object.reset_state(workflow) + self.version = self.object.get_new_version() motion_create = MotionCreateView.as_view() @@ -234,6 +238,10 @@ class MotionUpdateView(MotionEditMixin, UpdateView): return initial def manipulate_object(self, form): + """ + Resets state if the workflow should change and decides whether to use a + new version or the last version. + """ workflow = form.cleaned_data.get('workflow', None) if (workflow is not None and workflow != self.object.state.workflow): diff --git a/tests/motion/test_views.py b/tests/motion/test_views.py index 35dfb353e..ee7cb8503 100644 --- a/tests/motion/test_views.py +++ b/tests/motion/test_views.py @@ -13,7 +13,7 @@ from django.test.client import Client from openslides.config.api import config from openslides.utils.test import TestCase from openslides.participant.models import User, Group -from openslides.motion.models import Motion, State +from openslides.motion.models import Motion, State, Category class MotionViewTestCase(TestCase): @@ -140,6 +140,16 @@ class TestMotionCreateView(MotionViewTestCase): 'submitter': self.admin.person_id}) self.assertFormError(response, 'form', 'text', 'This field is required.') + def test_identifier_with_category_prefix(self): + category = Category.objects.create(name='category_oosozieh9eBa9aegujee', prefix='prefix_raiLie6keik6Eikeiphi') + response = self.admin_client.post(self.url, {'title': 'motion io2iez3Iwoh3aengi5hu', + 'text': 'motion text thoiveshoongoNg7ceek', + 'category': 1, + 'workflow': 1}) + self.assertEqual(response.status_code, 302) + motion = Motion.objects.filter(category=category).get() + self.assertEqual(motion.identifier, 'prefix_raiLie6keik6Eikeiphi 1') + class TestMotionUpdateView(MotionViewTestCase): url = '/motion/1/edit/'