Save the supporter

This commit is contained in:
Oskar Hahn 2013-01-26 16:42:23 +01:00
parent d3b340769b
commit 0702d49e2e
3 changed files with 16 additions and 6 deletions

View File

@ -47,7 +47,6 @@ class MotionSubmitterMixin(forms.ModelForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
if self.motion is not None: if self.motion is not None:
submitter = [submitter.person.person_id for submitter in self.motion.submitter.all()] submitter = [submitter.person.person_id for submitter in self.motion.submitter.all()]
print submitter
self.initial['submitter'] = submitter self.initial['submitter'] = submitter
super(MotionSubmitterMixin, self).__init__(*args, **kwargs) super(MotionSubmitterMixin, self).__init__(*args, **kwargs)
@ -55,8 +54,14 @@ class MotionSubmitterMixin(forms.ModelForm):
class MotionSupporterMixin(forms.ModelForm): class MotionSupporterMixin(forms.ModelForm):
supporter = MultiplePersonFormField(required=False, label=_("Supporters")) 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( trivial_change = forms.BooleanField(
required=False, label=_("Trivial change"), required=False, label=_("Trivial change"),
help_text=_("Trivial changes don't create a new version.")) help_text=_("Trivial changes don't create a new version."))

View File

@ -11,6 +11,7 @@
<p>Text: {{ motion.text }}</p> <p>Text: {{ motion.text }}</p>
<p>Reason: {{ motion.reason }}</p> <p>Reason: {{ motion.reason }}</p>
<p>Submitter: {% for submitter in motion.submitter.all %}{{ submitter.person }} {% endfor %}</p> <p>Submitter: {% for submitter in motion.submitter.all %}{{ submitter.person }} {% endfor %}</p>
<p>Supporter: {% for supporter in motion.supporter.all %}{{ supporter.person }} {% endfor %}</p>
<ol> <ol>
{% for motion_version in motion.versions.all %} {% for motion_version in motion.versions.all %}

View File

@ -28,7 +28,7 @@ from openslides.utils.utils import html_strong
from openslides.projector.api import get_active_slide from openslides.projector.api import get_active_slide
from openslides.projector.projector import Widget, SLIDE from openslides.projector.projector import Widget, SLIDE
from openslides.config.models import config from openslides.config.models import config
from .models import Motion, MotionSubmitter from .models import Motion, MotionSubmitter, MotionSupporter
from .forms import (BaseMotionForm, MotionSubmitterMixin, MotionSupporterMixin, from .forms import (BaseMotionForm, MotionSubmitterMixin, MotionSupporterMixin,
MotionTrivialChangesMixin, ConfigForm) MotionTrivialChangesMixin, ConfigForm)
@ -74,20 +74,24 @@ class MotionMixin(object):
def post_save(self, form): def post_save(self, form):
super(MotionMixin, self).post_save(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.submitter.all().delete()
self.object.supporter.all().delete()
MotionSubmitter.objects.bulk_create( MotionSubmitter.objects.bulk_create(
[MotionSubmitter(motion=self.object, person=person) [MotionSubmitter(motion=self.object, person=person)
for person in form.cleaned_data['submitter']]) 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): def get_form_class(self):
form_classes = [BaseMotionForm] form_classes = [BaseMotionForm]
if config['motion_allow_trivial_change']:
form_classes.append(MotionTrivialChangesMixin)
if self.request.user.has_perm('motion.can_manage_motion'): if self.request.user.has_perm('motion.can_manage_motion'):
form_classes.append(MotionSubmitterMixin) form_classes.append(MotionSubmitterMixin)
if config['motion_min_supporters'] > 0: if config['motion_min_supporters'] > 0:
form_classes.append(MotionSupporterMixin) form_classes.append(MotionSupporterMixin)
if config['motion_allow_trivial_change']:
form_classes.append(MotionTrivialChangesMixin)
return type('MotionForm', tuple(form_classes), {}) return type('MotionForm', tuple(form_classes), {})