From 0702d49e2e82a3bd701f833739df5acc05d626aa Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Sat, 26 Jan 2013 16:42:23 +0100 Subject: [PATCH] Save the supporter --- openslides/motion/forms.py | 9 +++++++-- .../motion/templates/motion/motion_detail.html | 1 + openslides/motion/views.py | 12 ++++++++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/openslides/motion/forms.py b/openslides/motion/forms.py index 98dd674ae..559317556 100644 --- a/openslides/motion/forms.py +++ b/openslides/motion/forms.py @@ -47,7 +47,6 @@ class MotionSubmitterMixin(forms.ModelForm): def __init__(self, *args, **kwargs): if self.motion is not None: submitter = [submitter.person.person_id for submitter in self.motion.submitter.all()] - print submitter self.initial['submitter'] = submitter super(MotionSubmitterMixin, self).__init__(*args, **kwargs) @@ -55,8 +54,14 @@ class MotionSubmitterMixin(forms.ModelForm): class MotionSupporterMixin(forms.ModelForm): supporter = MultiplePersonFormField(required=False, label=_("Supporters")) + def __init__(self, *args, **kwargs): + if self.motion is not None: + supporter = [supporter.person.person_id for supporter in self.motion.supporter.all()] + self.initial['supporter'] = supporter + super(MotionSupporterMixin, self).__init__(*args, **kwargs) -class MotionTrivialChangesMixin(object): + +class MotionTrivialChangesMixin(forms.ModelForm): trivial_change = forms.BooleanField( required=False, label=_("Trivial change"), help_text=_("Trivial changes don't create a new version.")) diff --git a/openslides/motion/templates/motion/motion_detail.html b/openslides/motion/templates/motion/motion_detail.html index 07f048750..fd5880ada 100644 --- a/openslides/motion/templates/motion/motion_detail.html +++ b/openslides/motion/templates/motion/motion_detail.html @@ -11,6 +11,7 @@

Text: {{ motion.text }}

Reason: {{ motion.reason }}

Submitter: {% for submitter in motion.submitter.all %}{{ submitter.person }} {% endfor %}

+

Supporter: {% for supporter in motion.supporter.all %}{{ supporter.person }} {% endfor %}

    {% for motion_version in motion.versions.all %} diff --git a/openslides/motion/views.py b/openslides/motion/views.py index b26752892..dcc8eaf8d 100644 --- a/openslides/motion/views.py +++ b/openslides/motion/views.py @@ -28,7 +28,7 @@ from openslides.utils.utils import html_strong from openslides.projector.api import get_active_slide from openslides.projector.projector import Widget, SLIDE from openslides.config.models import config -from .models import Motion, MotionSubmitter +from .models import Motion, MotionSubmitter, MotionSupporter from .forms import (BaseMotionForm, MotionSubmitterMixin, MotionSupporterMixin, MotionTrivialChangesMixin, ConfigForm) @@ -74,20 +74,24 @@ class MotionMixin(object): def post_save(self, form): super(MotionMixin, self).post_save(form) - # TODO: only delete and save neccessary submitters + # TODO: only delete and save neccessary submitters and supporter self.object.submitter.all().delete() + self.object.supporter.all().delete() MotionSubmitter.objects.bulk_create( [MotionSubmitter(motion=self.object, person=person) for person in form.cleaned_data['submitter']]) + MotionSupporter.objects.bulk_create( + [MotionSupporter(motion=self.object, person=person) + for person in form.cleaned_data['supporter']]) def get_form_class(self): form_classes = [BaseMotionForm] - if config['motion_allow_trivial_change']: - form_classes.append(MotionTrivialChangesMixin) if self.request.user.has_perm('motion.can_manage_motion'): form_classes.append(MotionSubmitterMixin) if config['motion_min_supporters'] > 0: form_classes.append(MotionSupporterMixin) + if config['motion_allow_trivial_change']: + form_classes.append(MotionTrivialChangesMixin) return type('MotionForm', tuple(form_classes), {})