Merge pull request #772 from normanjaeckel/MotionIdentifierSetting

Fix numbering with category prefix in simple workflow, fix #769
This commit is contained in:
Oskar Hahn 2013-06-20 13:07:57 -07:00
commit 7c7bdd92dd
2 changed files with 25 additions and 7 deletions

View File

@ -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):

View File

@ -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/'