Save the supporter
This commit is contained in:
parent
d3b340769b
commit
0702d49e2e
|
@ -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."))
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
<p>Text: {{ motion.text }}</p>
|
||||
<p>Reason: {{ motion.reason }}</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>
|
||||
{% for motion_version in motion.versions.all %}
|
||||
|
|
|
@ -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), {})
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue