2011-07-31 10:46:29 +02:00
|
|
|
|
#!/usr/bin/env python
|
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
"""
|
2012-10-24 11:04:23 +02:00
|
|
|
|
openslides.motion.models
|
2013-02-01 17:20:11 +01:00
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
2012-10-24 11:04:23 +02:00
|
|
|
|
Models for the motion app.
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
2013-02-05 18:46:46 +01:00
|
|
|
|
To use a motion object, you only have to import the Motion class. Any
|
|
|
|
|
functionality can be reached from a motion object.
|
|
|
|
|
|
2013-03-01 17:13:12 +01:00
|
|
|
|
:copyright: (c) 2011–2013 by the OpenSlides team, see AUTHORS.
|
2011-07-31 10:46:29 +02:00
|
|
|
|
:license: GNU GPL, see LICENSE for more details.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
2012-04-12 16:21:30 +02:00
|
|
|
|
from django.core.urlresolvers import reverse
|
2013-03-12 22:03:56 +01:00
|
|
|
|
from django.db import models, IntegrityError
|
2012-07-13 11:16:06 +02:00
|
|
|
|
from django.db.models import Max
|
|
|
|
|
from django.dispatch import receiver
|
2013-03-09 14:29:40 +01:00
|
|
|
|
from django.utils import formats
|
2012-06-30 15:21:27 +02:00
|
|
|
|
from django.utils.translation import pgettext
|
2013-04-22 19:59:05 +02:00
|
|
|
|
from django.utils.translation import ugettext as _, ugettext_lazy, ugettext_noop
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
2013-05-16 01:14:14 +02:00
|
|
|
|
from openslides.utils.jsonfield import JSONField
|
2012-08-07 22:43:57 +02:00
|
|
|
|
from openslides.utils.person import PersonField
|
2013-03-01 17:13:12 +01:00
|
|
|
|
from openslides.config.api import config
|
2012-11-24 14:01:21 +01:00
|
|
|
|
from openslides.poll.models import (
|
|
|
|
|
BaseOption, BasePoll, CountVotesCast, CountInvalid, BaseVote)
|
|
|
|
|
from openslides.participant.models import User
|
2012-07-08 09:21:39 +02:00
|
|
|
|
from openslides.projector.api import register_slidemodel
|
|
|
|
|
from openslides.projector.models import SlideMixin
|
|
|
|
|
from openslides.agenda.models import Item
|
2012-06-23 11:41:32 +02:00
|
|
|
|
|
2013-02-14 19:27:36 +01:00
|
|
|
|
from .exceptions import MotionError, WorkflowError
|
2012-02-03 23:12:28 +01:00
|
|
|
|
|
2013-02-17 17:07:44 +01:00
|
|
|
|
|
2013-02-05 18:46:46 +01:00
|
|
|
|
class Motion(SlideMixin, models.Model):
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
The Motion Class.
|
2013-01-26 12:28:51 +01:00
|
|
|
|
|
2013-02-05 18:46:46 +01:00
|
|
|
|
This class is the main entry point to all other classes related to a motion.
|
|
|
|
|
"""
|
2013-01-26 12:28:51 +01:00
|
|
|
|
|
2013-05-24 00:31:52 +02:00
|
|
|
|
prefix = ugettext_noop('motion')
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
Prefix for the slide system.
|
|
|
|
|
"""
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
2013-02-05 18:46:46 +01:00
|
|
|
|
active_version = models.ForeignKey('MotionVersion', null=True,
|
|
|
|
|
related_name="active_version")
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
Points to a specific version.
|
2013-01-26 15:25:54 +01:00
|
|
|
|
|
2013-03-14 22:54:00 +01:00
|
|
|
|
Used be the permitted-version-system to deside which version is the active
|
|
|
|
|
version. Could also be used to only choose a specific version as a default
|
|
|
|
|
version. Like the sighted versions on Wikipedia.
|
2013-02-05 18:46:46 +01:00
|
|
|
|
"""
|
2013-01-06 12:07:37 +01:00
|
|
|
|
|
2013-02-06 23:56:21 +01:00
|
|
|
|
state = models.ForeignKey('State', null=True) # TODO: Check whether null=True is necessary.
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
The related state object.
|
2013-01-06 12:07:37 +01:00
|
|
|
|
|
2013-02-06 23:56:21 +01:00
|
|
|
|
This attribute is to get the current state of the motion.
|
2013-01-26 12:28:51 +01:00
|
|
|
|
"""
|
2013-01-06 12:07:37 +01:00
|
|
|
|
|
|
|
|
|
identifier = models.CharField(max_length=255, null=True, blank=True,
|
|
|
|
|
unique=True)
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
A string as human readable identifier for the motion.
|
|
|
|
|
"""
|
2013-02-05 18:46:46 +01:00
|
|
|
|
|
2013-03-12 22:03:56 +01:00
|
|
|
|
identifier_number = models.IntegerField(null=True)
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
Counts the number of the motion in one category.
|
2013-03-12 22:03:56 +01:00
|
|
|
|
|
|
|
|
|
Needed to find the next free motion-identifier.
|
|
|
|
|
"""
|
|
|
|
|
|
2013-03-11 20:17:19 +01:00
|
|
|
|
category = models.ForeignKey('Category', null=True, blank=True)
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
ForeignKey to one category of motions.
|
|
|
|
|
"""
|
2013-03-11 20:17:19 +01:00
|
|
|
|
|
2013-02-05 18:46:46 +01:00
|
|
|
|
# TODO: proposal
|
|
|
|
|
#master = models.ForeignKey('self', null=True, blank=True)
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
2013-01-06 12:07:37 +01:00
|
|
|
|
class Meta:
|
|
|
|
|
permissions = (
|
|
|
|
|
('can_see_motion', ugettext_noop('Can see motions')),
|
|
|
|
|
('can_create_motion', ugettext_noop('Can create motions')),
|
|
|
|
|
('can_support_motion', ugettext_noop('Can support motions')),
|
|
|
|
|
('can_manage_motion', ugettext_noop('Can manage motions')),
|
|
|
|
|
)
|
|
|
|
|
# TODO: order per default by category and identifier
|
|
|
|
|
# ordering = ('number',)
|
2012-08-04 12:19:31 +02:00
|
|
|
|
|
2013-01-06 12:07:37 +01:00
|
|
|
|
def __unicode__(self):
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
Return a human readable name of this motion.
|
|
|
|
|
"""
|
2013-05-24 00:31:52 +02:00
|
|
|
|
return self.active_version.title
|
2013-01-06 12:07:37 +01:00
|
|
|
|
|
|
|
|
|
# TODO: Use transaction
|
2013-05-09 23:51:58 +02:00
|
|
|
|
def save(self, ignore_version_data=False, *args, **kwargs):
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
Save the motion.
|
2013-02-05 18:46:46 +01:00
|
|
|
|
|
2013-02-06 23:56:21 +01:00
|
|
|
|
1. Set the state of a new motion to the default state.
|
2013-05-09 23:51:58 +02:00
|
|
|
|
2. Ensure that the identifier is not an empty string.
|
|
|
|
|
3. Save the motion object.
|
|
|
|
|
4. Save the version data, if ignore_version_data == False.
|
|
|
|
|
5. Set the active version for the motion, if ignore_version_data == False.
|
2013-01-26 12:28:51 +01:00
|
|
|
|
"""
|
2013-02-06 23:56:21 +01:00
|
|
|
|
if not self.state:
|
2013-02-01 17:20:11 +01:00
|
|
|
|
self.reset_state()
|
2013-05-09 23:51:58 +02:00
|
|
|
|
# TODO: Bad hack here to make Motion.objects.create() work
|
|
|
|
|
# again. We have to remove the flag to force an INSERT given
|
|
|
|
|
# by Django's create() method without knowing its advantages
|
|
|
|
|
# because of our misuse of the save() method in the
|
|
|
|
|
# set_identifier() method.
|
|
|
|
|
kwargs.pop('force_insert', None)
|
|
|
|
|
|
|
|
|
|
if not self.identifier and self.identifier is not None: # TODO: Why not >if self.identifier is '':<
|
2013-04-19 14:12:49 +02:00
|
|
|
|
self.identifier = None
|
|
|
|
|
|
2013-01-06 12:07:37 +01:00
|
|
|
|
super(Motion, self).save(*args, **kwargs)
|
2013-02-05 18:46:46 +01:00
|
|
|
|
|
2013-05-09 23:51:58 +02:00
|
|
|
|
if not ignore_version_data:
|
|
|
|
|
# Select version object
|
2013-01-06 12:07:37 +01:00
|
|
|
|
version = self.last_version
|
2013-05-09 23:51:58 +02:00
|
|
|
|
if hasattr(self, '_new_version'):
|
|
|
|
|
version = self.new_version
|
|
|
|
|
del self._new_version
|
|
|
|
|
version.motion = self # TODO: Test if this line is really neccessary.
|
|
|
|
|
|
|
|
|
|
# Save title, text and reason in the version object
|
|
|
|
|
for attr in ['title', 'text', 'reason']:
|
|
|
|
|
_attr = '_%s' % attr
|
|
|
|
|
try:
|
|
|
|
|
setattr(version, attr, getattr(self, _attr))
|
|
|
|
|
delattr(self, _attr)
|
|
|
|
|
except AttributeError:
|
|
|
|
|
if self.versions.exists():
|
|
|
|
|
# If the _attr was not set, use the value from last_version
|
|
|
|
|
setattr(version, attr, getattr(self.last_version, attr))
|
|
|
|
|
|
|
|
|
|
# Set version_number of the new Version (if neccessary) and save it into the DB
|
|
|
|
|
if version.id is None:
|
|
|
|
|
# TODO: auto increment the version_number in the Database
|
|
|
|
|
version_number = self.versions.aggregate(Max('version_number'))['version_number__max'] or 0
|
|
|
|
|
version.version_number = version_number + 1
|
|
|
|
|
version.save()
|
|
|
|
|
|
|
|
|
|
# Set the active version of this motion. This has to be done after the
|
|
|
|
|
# version is saved to the database
|
|
|
|
|
if self.active_version is None or not self.state.leave_old_version_active:
|
|
|
|
|
self.active_version = version
|
|
|
|
|
self.save(ignore_version_data=True)
|
2013-02-03 13:24:29 +01:00
|
|
|
|
|
2013-01-06 12:07:37 +01:00
|
|
|
|
def get_absolute_url(self, link='detail'):
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
Return an URL for this version.
|
2013-02-05 18:46:46 +01:00
|
|
|
|
|
2013-05-24 00:31:52 +02:00
|
|
|
|
The keyword argument 'link' can be 'detail', 'view', 'edit', 'update' or 'delete'.
|
2013-02-05 18:46:46 +01:00
|
|
|
|
"""
|
2013-01-06 12:07:37 +01:00
|
|
|
|
if link == 'view' or link == 'detail':
|
|
|
|
|
return reverse('motion_detail', args=[str(self.id)])
|
2013-05-24 00:31:52 +02:00
|
|
|
|
if link == 'update' or link == 'edit':
|
2012-10-24 11:04:23 +02:00
|
|
|
|
return reverse('motion_edit', args=[str(self.id)])
|
2011-07-31 10:46:29 +02:00
|
|
|
|
if link == 'delete':
|
2012-10-24 11:04:23 +02:00
|
|
|
|
return reverse('motion_delete', args=[str(self.id)])
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
2013-03-12 22:03:56 +01:00
|
|
|
|
def set_identifier(self):
|
2013-05-09 23:51:58 +02:00
|
|
|
|
"""
|
|
|
|
|
Sets the motion identifier automaticly according to the config
|
|
|
|
|
value, if it is not set yet.
|
|
|
|
|
"""
|
|
|
|
|
if config['motion_identifier'] == 'manually' or self.identifier:
|
2013-03-12 23:35:08 +01:00
|
|
|
|
# Do not set an identifier.
|
|
|
|
|
return
|
|
|
|
|
elif config['motion_identifier'] == 'per_category':
|
|
|
|
|
motions = Motion.objects.filter(category=self.category)
|
2013-05-09 23:51:58 +02:00
|
|
|
|
else: # That means: config['motion_identifier'] == 'serially_numbered'
|
2013-03-12 23:35:08 +01:00
|
|
|
|
motions = Motion.objects.all()
|
|
|
|
|
|
|
|
|
|
number = motions.aggregate(Max('identifier_number'))['identifier_number__max'] or 0
|
2013-03-12 23:54:37 +01:00
|
|
|
|
if self.category is None or not self.category.prefix:
|
2013-03-12 22:03:56 +01:00
|
|
|
|
prefix = ''
|
2013-03-12 23:35:08 +01:00
|
|
|
|
else:
|
|
|
|
|
prefix = self.category.prefix + ' '
|
2013-03-12 22:03:56 +01:00
|
|
|
|
|
2013-05-09 23:51:58 +02:00
|
|
|
|
# TODO: Do not use the save() method in this method, see note in
|
|
|
|
|
# the save() method above.
|
2013-03-12 22:03:56 +01:00
|
|
|
|
while True:
|
|
|
|
|
number += 1
|
|
|
|
|
self.identifier = '%s%d' % (prefix, number)
|
2013-05-09 23:51:58 +02:00
|
|
|
|
self.identifier_number = number
|
2013-03-12 22:03:56 +01:00
|
|
|
|
try:
|
2013-05-09 23:51:58 +02:00
|
|
|
|
self.save(ignore_version_data=True)
|
2013-03-12 22:03:56 +01:00
|
|
|
|
except IntegrityError:
|
|
|
|
|
continue
|
|
|
|
|
else:
|
|
|
|
|
break
|
|
|
|
|
|
2013-01-06 12:07:37 +01:00
|
|
|
|
def get_title(self):
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
Get the title of the motion.
|
2013-02-05 18:46:46 +01:00
|
|
|
|
|
2013-05-09 23:51:58 +02:00
|
|
|
|
The title is taken from motion.version.
|
2013-01-26 12:28:51 +01:00
|
|
|
|
"""
|
2011-07-31 10:46:29 +02:00
|
|
|
|
try:
|
2013-01-06 12:07:37 +01:00
|
|
|
|
return self._title
|
2011-07-31 10:46:29 +02:00
|
|
|
|
except AttributeError:
|
2013-01-26 12:28:51 +01:00
|
|
|
|
return self.version.title
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
2013-01-06 12:07:37 +01:00
|
|
|
|
def set_title(self, title):
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
Set the titel of the motion.
|
2013-02-05 18:46:46 +01:00
|
|
|
|
|
2013-05-09 23:51:58 +02:00
|
|
|
|
The title will be saved into the version object, wenn motion.save() is
|
2013-02-05 18:46:46 +01:00
|
|
|
|
called.
|
2013-01-26 12:28:51 +01:00
|
|
|
|
"""
|
2013-01-06 12:07:37 +01:00
|
|
|
|
self._title = title
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
2013-01-06 12:07:37 +01:00
|
|
|
|
title = property(get_title, set_title)
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
The title of the motion.
|
2013-02-05 18:46:46 +01:00
|
|
|
|
|
|
|
|
|
Is saved in a MotionVersion object.
|
|
|
|
|
"""
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
2013-01-06 12:07:37 +01:00
|
|
|
|
def get_text(self):
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
Get the text of the motion.
|
2013-02-05 18:46:46 +01:00
|
|
|
|
|
|
|
|
|
Simular to get_title().
|
2013-01-26 12:28:51 +01:00
|
|
|
|
"""
|
2013-01-06 12:07:37 +01:00
|
|
|
|
try:
|
|
|
|
|
return self._text
|
|
|
|
|
except AttributeError:
|
2013-01-26 12:28:51 +01:00
|
|
|
|
return self.version.text
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
2013-01-06 12:07:37 +01:00
|
|
|
|
def set_text(self, text):
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
Set the text of the motion.
|
2013-02-05 18:46:46 +01:00
|
|
|
|
|
|
|
|
|
Simular to set_title().
|
2013-01-26 12:28:51 +01:00
|
|
|
|
"""
|
2013-01-06 12:07:37 +01:00
|
|
|
|
self._text = text
|
|
|
|
|
|
|
|
|
|
text = property(get_text, set_text)
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
The text of a motin.
|
2013-02-05 18:46:46 +01:00
|
|
|
|
|
|
|
|
|
Is saved in a MotionVersion object.
|
|
|
|
|
"""
|
2013-01-06 12:07:37 +01:00
|
|
|
|
|
|
|
|
|
def get_reason(self):
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
Get the reason of the motion.
|
2013-02-05 18:46:46 +01:00
|
|
|
|
|
|
|
|
|
Simular to get_title().
|
2013-01-26 12:28:51 +01:00
|
|
|
|
"""
|
2013-01-06 12:07:37 +01:00
|
|
|
|
try:
|
|
|
|
|
return self._reason
|
|
|
|
|
except AttributeError:
|
2013-01-26 12:28:51 +01:00
|
|
|
|
return self.version.reason
|
2013-01-06 12:07:37 +01:00
|
|
|
|
|
|
|
|
|
def set_reason(self, reason):
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
Set the reason of the motion.
|
2013-02-05 18:46:46 +01:00
|
|
|
|
|
|
|
|
|
Simular to set_title().
|
2013-01-26 12:28:51 +01:00
|
|
|
|
"""
|
2013-01-06 12:07:37 +01:00
|
|
|
|
self._reason = reason
|
|
|
|
|
|
|
|
|
|
reason = property(get_reason, set_reason)
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
The reason for the motion.
|
2013-02-05 18:46:46 +01:00
|
|
|
|
|
|
|
|
|
Is saved in a MotionVersion object.
|
|
|
|
|
"""
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
2013-01-26 12:28:51 +01:00
|
|
|
|
@property
|
|
|
|
|
def new_version(self):
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
Return a version object, not saved in the database.
|
2013-02-05 18:46:46 +01:00
|
|
|
|
|
2013-01-26 12:28:51 +01:00
|
|
|
|
On the first call, it creates a new version. On any later call, it
|
|
|
|
|
use the existing new version.
|
|
|
|
|
|
2013-02-05 18:46:46 +01:00
|
|
|
|
The new_version object will be deleted when it is saved into the db.
|
2013-01-26 12:28:51 +01:00
|
|
|
|
"""
|
|
|
|
|
try:
|
|
|
|
|
return self._new_version
|
|
|
|
|
except AttributeError:
|
|
|
|
|
self._new_version = MotionVersion(motion=self)
|
|
|
|
|
return self._new_version
|
|
|
|
|
|
|
|
|
|
def get_version(self):
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
Get the 'active' version object.
|
2013-02-05 18:46:46 +01:00
|
|
|
|
|
|
|
|
|
This version will be used to get the data for this motion.
|
2013-01-26 12:28:51 +01:00
|
|
|
|
"""
|
2013-01-06 12:07:37 +01:00
|
|
|
|
try:
|
2013-01-26 12:28:51 +01:00
|
|
|
|
return self._version
|
2013-01-06 12:07:37 +01:00
|
|
|
|
except AttributeError:
|
|
|
|
|
return self.last_version
|
2012-02-14 16:31:21 +01:00
|
|
|
|
|
2013-01-26 12:28:51 +01:00
|
|
|
|
def set_version(self, version):
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
Set the 'active' version object.
|
2013-02-05 18:46:46 +01:00
|
|
|
|
|
2013-02-06 23:56:21 +01:00
|
|
|
|
The keyword argument 'version' can be a MotionVersion object or the
|
|
|
|
|
version_number of a version object or None.
|
2013-01-26 12:28:51 +01:00
|
|
|
|
|
2013-02-05 18:46:46 +01:00
|
|
|
|
If the argument is None, the newest version will be used.
|
2013-01-26 12:28:51 +01:00
|
|
|
|
"""
|
2013-01-06 12:07:37 +01:00
|
|
|
|
if version is None:
|
|
|
|
|
try:
|
2013-01-26 12:28:51 +01:00
|
|
|
|
del self._version
|
2013-01-06 12:07:37 +01:00
|
|
|
|
except AttributeError:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
if type(version) is int:
|
2013-02-03 13:24:29 +01:00
|
|
|
|
version = self.versions.get(version_number=version)
|
2013-01-06 12:07:37 +01:00
|
|
|
|
elif type(version) is not MotionVersion:
|
|
|
|
|
raise ValueError('The argument \'version\' has to be int or '
|
|
|
|
|
'MotionVersion, not %s' % type(version))
|
2013-01-26 12:28:51 +01:00
|
|
|
|
# TODO: Test, that the version is one of this motion
|
|
|
|
|
self._version = version
|
2012-02-14 16:31:21 +01:00
|
|
|
|
|
2013-01-26 12:28:51 +01:00
|
|
|
|
version = property(get_version, set_version)
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
The active version of this motion.
|
|
|
|
|
"""
|
2012-02-15 12:36:50 +01:00
|
|
|
|
|
2013-01-06 12:07:37 +01:00
|
|
|
|
@property
|
|
|
|
|
def last_version(self):
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
Return the newest version of the motion.
|
|
|
|
|
"""
|
2013-05-31 14:54:53 +02:00
|
|
|
|
# TODO: Fix the case, that the motion has no version.
|
|
|
|
|
# Check whether the case, that a motion has not any version, can still appear.
|
2013-01-06 12:07:37 +01:00
|
|
|
|
try:
|
2013-02-03 13:24:29 +01:00
|
|
|
|
return self.versions.order_by('-version_number')[0]
|
2013-01-06 12:07:37 +01:00
|
|
|
|
except IndexError:
|
|
|
|
|
return self.new_version
|
2012-02-15 13:44:55 +01:00
|
|
|
|
|
2013-03-09 14:29:40 +01:00
|
|
|
|
@property
|
|
|
|
|
def submitters(self):
|
|
|
|
|
return sorted([object.person for object in self.submitter.all()],
|
|
|
|
|
key=lambda person: person.sort_name)
|
|
|
|
|
|
2013-02-02 10:24:28 +01:00
|
|
|
|
def is_submitter(self, person):
|
2013-02-05 18:46:46 +01:00
|
|
|
|
"""Return True, if person is a submitter of this motion. Else: False."""
|
2013-03-15 11:35:03 +01:00
|
|
|
|
return self.submitter.filter(person=person).exists()
|
2013-02-02 10:24:28 +01:00
|
|
|
|
|
2013-03-09 14:29:40 +01:00
|
|
|
|
@property
|
|
|
|
|
def supporters(self):
|
|
|
|
|
return sorted([object.person for object in self.supporter.all()],
|
|
|
|
|
key=lambda person: person.sort_name)
|
|
|
|
|
|
2013-03-15 11:35:03 +01:00
|
|
|
|
def add_submitter(self, person):
|
|
|
|
|
MotionSubmitter.objects.create(motion=self, person=person)
|
|
|
|
|
|
2013-05-12 00:47:49 +02:00
|
|
|
|
def clear_submitters(self):
|
|
|
|
|
MotionSubmitter.objects.filter(motion=self).delete()
|
|
|
|
|
|
2013-01-26 18:18:02 +01:00
|
|
|
|
def is_supporter(self, person):
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
Return True, if person is a supporter of this motion. Else: False.
|
|
|
|
|
"""
|
2013-02-01 19:19:18 +01:00
|
|
|
|
return self.supporter.filter(person=person).exists()
|
2013-01-26 18:18:02 +01:00
|
|
|
|
|
|
|
|
|
def support(self, person):
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
Add 'person' as a supporter of this motion.
|
|
|
|
|
"""
|
2013-02-06 23:56:21 +01:00
|
|
|
|
if self.state.allow_support:
|
2013-02-01 16:44:06 +01:00
|
|
|
|
if not self.is_supporter(person):
|
|
|
|
|
MotionSupporter(motion=self, person=person).save()
|
|
|
|
|
else:
|
2013-02-06 23:56:21 +01:00
|
|
|
|
raise WorkflowError('You can not support a motion in state %s.' % self.state.name)
|
2013-01-26 18:18:02 +01:00
|
|
|
|
|
|
|
|
|
def unsupport(self, person):
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
Remove 'person' as supporter from this motion.
|
|
|
|
|
"""
|
2013-02-06 23:56:21 +01:00
|
|
|
|
if self.state.allow_support:
|
2013-02-01 19:19:18 +01:00
|
|
|
|
self.supporter.filter(person=person).delete()
|
2013-02-01 16:44:06 +01:00
|
|
|
|
else:
|
2013-02-06 23:56:21 +01:00
|
|
|
|
raise WorkflowError('You can not unsupport a motion in state %s.' % self.state.name)
|
2013-01-26 18:18:02 +01:00
|
|
|
|
|
2013-05-31 18:30:03 +02:00
|
|
|
|
def clear_supporters(self):
|
|
|
|
|
"""
|
|
|
|
|
Deletes all supporters of this motion.
|
|
|
|
|
"""
|
|
|
|
|
MotionSupporter.objects.filter(motion=self).delete()
|
|
|
|
|
|
2013-02-01 12:51:54 +01:00
|
|
|
|
def create_poll(self):
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
Create a new poll for this motion.
|
2013-02-05 18:46:46 +01:00
|
|
|
|
|
|
|
|
|
Return the new poll object.
|
2013-02-01 16:33:45 +01:00
|
|
|
|
"""
|
2013-02-06 23:56:21 +01:00
|
|
|
|
if self.state.allow_create_poll:
|
|
|
|
|
# TODO: auto increment the poll_number in the database
|
2013-02-01 16:44:06 +01:00
|
|
|
|
poll_number = self.polls.aggregate(Max('poll_number'))['poll_number__max'] or 0
|
|
|
|
|
poll = MotionPoll.objects.create(motion=self, poll_number=poll_number + 1)
|
|
|
|
|
poll.set_options()
|
|
|
|
|
return poll
|
|
|
|
|
else:
|
2013-02-06 23:56:21 +01:00
|
|
|
|
raise WorkflowError('You can not create a poll in state %s.' % self.state.name)
|
2013-02-01 16:33:45 +01:00
|
|
|
|
|
2013-03-12 22:03:56 +01:00
|
|
|
|
def set_state(self, state):
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
Set the state of the motion.
|
2013-03-12 22:03:56 +01:00
|
|
|
|
|
|
|
|
|
State can be the id of a state object or a state object.
|
|
|
|
|
"""
|
|
|
|
|
if type(state) is int:
|
|
|
|
|
state = State.objects.get(pk=state)
|
|
|
|
|
|
2013-03-12 22:13:17 +01:00
|
|
|
|
if not state.dont_set_identifier:
|
2013-03-12 22:03:56 +01:00
|
|
|
|
self.set_identifier()
|
|
|
|
|
self.state = state
|
|
|
|
|
|
2013-05-13 23:08:55 +02:00
|
|
|
|
def reset_state(self, workflow=None):
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
Set the state to the default state.
|
|
|
|
|
|
2013-05-13 23:08:55 +02:00
|
|
|
|
If the motion is new and workflow is None, it chooses the default
|
|
|
|
|
workflow from config.
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
2013-05-13 23:08:55 +02:00
|
|
|
|
if workflow:
|
|
|
|
|
new_state = workflow.first_state
|
|
|
|
|
elif self.state:
|
2013-05-09 23:51:58 +02:00
|
|
|
|
new_state = self.state.workflow.first_state
|
2013-02-06 23:56:21 +01:00
|
|
|
|
else:
|
2013-05-09 23:51:58 +02:00
|
|
|
|
new_state = (Workflow.objects.get(pk=config['motion_workflow']).first_state or
|
|
|
|
|
Workflow.objects.get(pk=config['motion_workflow']).state_set.all()[0])
|
|
|
|
|
self.set_state(new_state)
|
2013-02-01 17:20:11 +01:00
|
|
|
|
|
2013-02-02 00:37:43 +01:00
|
|
|
|
def slide(self):
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
Return the slide dict.
|
|
|
|
|
"""
|
2013-02-02 00:37:43 +01:00
|
|
|
|
data = super(Motion, self).slide()
|
|
|
|
|
data['motion'] = self
|
|
|
|
|
data['title'] = self.title
|
|
|
|
|
data['template'] = 'projector/Motion.html'
|
|
|
|
|
return data
|
|
|
|
|
|
2013-02-02 00:51:08 +01:00
|
|
|
|
def get_agenda_title(self):
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
Return a title for the Agenda.
|
|
|
|
|
"""
|
2013-05-24 00:31:52 +02:00
|
|
|
|
return self.active_version.title
|
2013-02-02 00:51:08 +01:00
|
|
|
|
|
2013-05-24 00:31:52 +02:00
|
|
|
|
def get_agenda_title_supplement(self):
|
|
|
|
|
"""
|
|
|
|
|
Returns the supplement to the title for the agenda item.
|
|
|
|
|
"""
|
|
|
|
|
if self.identifier:
|
|
|
|
|
return '(%s %s)' % (_('Motion'), self.identifier)
|
|
|
|
|
return '(%s)' % _('Motion')
|
2013-02-02 00:51:08 +01:00
|
|
|
|
|
2013-02-02 10:24:28 +01:00
|
|
|
|
def get_allowed_actions(self, person):
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
|
|
|
|
Return a dictonary with all allowed actions for a specific person.
|
2013-02-02 10:24:28 +01:00
|
|
|
|
|
|
|
|
|
The dictonary contains the following actions.
|
|
|
|
|
|
2013-05-31 18:30:03 +02:00
|
|
|
|
* update / edit
|
2013-02-02 10:24:28 +01:00
|
|
|
|
* delete
|
|
|
|
|
* create_poll
|
|
|
|
|
* support
|
|
|
|
|
* unsupport
|
|
|
|
|
* change_state
|
|
|
|
|
* reset_state
|
|
|
|
|
"""
|
|
|
|
|
actions = {
|
2013-05-31 18:30:03 +02:00
|
|
|
|
'update': ((self.is_submitter(person) and
|
|
|
|
|
self.state.allow_submitter_edit) or
|
|
|
|
|
person.has_perm('motion.can_manage_motion')),
|
|
|
|
|
|
|
|
|
|
'delete': person.has_perm('motion.can_manage_motion'),
|
2013-02-02 10:24:28 +01:00
|
|
|
|
|
2013-02-02 10:52:13 +01:00
|
|
|
|
'create_poll': (person.has_perm('motion.can_manage_motion') and
|
2013-02-06 23:56:21 +01:00
|
|
|
|
self.state.allow_create_poll),
|
2013-02-02 10:24:28 +01:00
|
|
|
|
|
2013-02-06 23:56:21 +01:00
|
|
|
|
'support': (self.state.allow_support and
|
2013-02-02 10:52:13 +01:00
|
|
|
|
config['motion_min_supporters'] > 0 and
|
2013-03-09 14:29:40 +01:00
|
|
|
|
not self.is_submitter(person) and
|
|
|
|
|
not self.is_supporter(person)),
|
|
|
|
|
|
|
|
|
|
'unsupport': (self.state.allow_support and
|
|
|
|
|
self.is_supporter(person)),
|
2013-02-02 10:24:28 +01:00
|
|
|
|
|
|
|
|
|
'change_state': person.has_perm('motion.can_manage_motion'),
|
|
|
|
|
|
2013-05-31 18:30:03 +02:00
|
|
|
|
'reset_state': person.has_perm('motion.can_manage_motion')}
|
|
|
|
|
|
|
|
|
|
actions['edit'] = actions['update']
|
|
|
|
|
|
2013-02-02 10:24:28 +01:00
|
|
|
|
return actions
|
|
|
|
|
|
2013-05-16 01:14:14 +02:00
|
|
|
|
def write_log(self, message_list, person=None):
|
2013-05-16 00:58:37 +02:00
|
|
|
|
"""
|
|
|
|
|
Write a log message.
|
2013-02-05 18:46:46 +01:00
|
|
|
|
|
2013-05-16 00:58:37 +02:00
|
|
|
|
The message should be in English and translatable,
|
2013-05-16 01:14:14 +02:00
|
|
|
|
e. g. motion.write_log(message_list=[ugettext_noop('Message Text')])
|
2013-02-05 18:46:46 +01:00
|
|
|
|
"""
|
2013-05-16 01:14:14 +02:00
|
|
|
|
MotionLog.objects.create(motion=self, message_list=message_list, person=person)
|
2013-02-02 21:40:23 +01:00
|
|
|
|
|
2013-04-19 16:02:16 +02:00
|
|
|
|
def set_active_version(self, version):
|
2013-04-19 14:12:49 +02:00
|
|
|
|
"""
|
2013-05-31 14:54:53 +02:00
|
|
|
|
Set the active version of a motion to 'version'.
|
2013-02-03 13:24:29 +01:00
|
|
|
|
|
|
|
|
|
'version' can be a version object, or the version_number of a version.
|
|
|
|
|
"""
|
|
|
|
|
if type(version) is int:
|
|
|
|
|
version = self.versions.get(version_number=version)
|
|
|
|
|
self.active_version = version
|
|
|
|
|
|
2012-02-15 13:44:55 +01:00
|
|
|
|
|
2013-01-06 12:07:37 +01:00
|
|
|
|
class MotionVersion(models.Model):
|
2013-02-05 18:46:46 +01:00
|
|
|
|
"""
|
2013-04-19 14:12:49 +02:00
|
|
|
|
A MotionVersion object saves some date of the motion.
|
|
|
|
|
"""
|
2013-02-05 18:46:46 +01:00
|
|
|
|
|
|
|
|
|
motion = models.ForeignKey(Motion, related_name='versions')
|
2013-02-06 23:56:21 +01:00
|
|
|
|
"""The motion to which the version belongs."""
|
2013-02-05 18:46:46 +01:00
|
|
|
|
|
2013-02-03 13:24:29 +01:00
|
|
|
|
version_number = models.PositiveIntegerField(default=1)
|
2013-02-05 18:46:46 +01:00
|
|
|
|
"""An id for this version in realation to a motion.
|
|
|
|
|
|
|
|
|
|
Is unique for each motion.
|
|
|
|
|
"""
|
|
|
|
|
|
2013-01-26 16:33:55 +01:00
|
|
|
|
title = models.CharField(max_length=255, verbose_name=ugettext_lazy("Title"))
|
2013-02-06 23:56:21 +01:00
|
|
|
|
"""The title of a motion."""
|
2013-02-05 18:46:46 +01:00
|
|
|
|
|
2013-04-22 19:59:05 +02:00
|
|
|
|
text = models.TextField(verbose_name=ugettext_lazy("Text"))
|
2013-02-05 18:46:46 +01:00
|
|
|
|
"""The text of a motion."""
|
|
|
|
|
|
2013-01-26 16:33:55 +01:00
|
|
|
|
reason = models.TextField(null=True, blank=True, verbose_name=ugettext_lazy("Reason"))
|
2013-02-05 18:46:46 +01:00
|
|
|
|
"""The reason for a motion."""
|
|
|
|
|
|
2013-01-06 12:07:37 +01:00
|
|
|
|
creation_time = models.DateTimeField(auto_now=True)
|
2013-02-06 23:56:21 +01:00
|
|
|
|
"""Time when the version was saved."""
|
2013-02-05 18:46:46 +01:00
|
|
|
|
|
|
|
|
|
#identifier = models.CharField(max_length=255, verbose_name=ugettext_lazy("Version identifier"))
|
|
|
|
|
#note = models.TextField(null=True, blank=True)
|
2012-02-19 17:31:17 +01:00
|
|
|
|
|
2013-02-03 13:24:29 +01:00
|
|
|
|
class Meta:
|
|
|
|
|
unique_together = ("motion", "version_number")
|
|
|
|
|
|
2013-01-06 12:07:37 +01:00
|
|
|
|
def __unicode__(self):
|
2013-02-05 18:46:46 +01:00
|
|
|
|
"""Return a string, representing this object."""
|
2013-04-22 19:59:05 +02:00
|
|
|
|
counter = self.version_number or ugettext_lazy('new')
|
2013-02-06 23:56:21 +01:00
|
|
|
|
return "%s Version %s" % (self.motion, counter) # TODO: Should this really be self.motion or the title of the specific version?
|
2013-01-06 12:07:37 +01:00
|
|
|
|
|
2013-01-26 15:25:54 +01:00
|
|
|
|
def get_absolute_url(self, link='detail'):
|
2013-02-05 18:46:46 +01:00
|
|
|
|
"""Return the URL of this Version.
|
|
|
|
|
|
|
|
|
|
The keyargument link can be 'view' or 'detail'.
|
|
|
|
|
"""
|
2013-01-26 15:25:54 +01:00
|
|
|
|
if link == 'view' or link == 'detail':
|
|
|
|
|
return reverse('motion_version_detail', args=[str(self.motion.id),
|
|
|
|
|
str(self.version_number)])
|
|
|
|
|
|
|
|
|
|
@property
|
2013-02-03 13:24:29 +01:00
|
|
|
|
def active(self):
|
2013-02-05 18:46:46 +01:00
|
|
|
|
"""Return True, if the version is the active version of a motion. Else: False."""
|
2013-02-03 13:24:29 +01:00
|
|
|
|
return self.active_version.exists()
|
2012-04-12 16:21:30 +02:00
|
|
|
|
|
2012-04-14 12:52:56 +02:00
|
|
|
|
|
2013-02-05 18:46:46 +01:00
|
|
|
|
class MotionSubmitter(models.Model):
|
|
|
|
|
"""Save the submitter of a Motion."""
|
|
|
|
|
|
|
|
|
|
motion = models.ForeignKey('Motion', related_name="submitter")
|
|
|
|
|
"""The motion to witch the object belongs."""
|
|
|
|
|
|
|
|
|
|
person = PersonField()
|
|
|
|
|
"""The person, who is the submitter."""
|
2013-01-06 12:07:37 +01:00
|
|
|
|
|
|
|
|
|
def __unicode__(self):
|
2013-02-05 18:46:46 +01:00
|
|
|
|
"""Return the name of the submitter as string."""
|
|
|
|
|
return unicode(self.person)
|
2012-04-14 17:09:15 +02:00
|
|
|
|
|
2012-04-14 12:52:56 +02:00
|
|
|
|
|
2013-02-05 18:46:46 +01:00
|
|
|
|
class MotionSupporter(models.Model):
|
|
|
|
|
"""Save the submitter of a Motion."""
|
|
|
|
|
|
|
|
|
|
motion = models.ForeignKey('Motion', related_name="supporter")
|
|
|
|
|
"""The motion to witch the object belongs."""
|
|
|
|
|
|
|
|
|
|
person = PersonField()
|
|
|
|
|
"""The person, who is the supporter."""
|
|
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
|
"""Return the name of the supporter as string."""
|
|
|
|
|
return unicode(self.person)
|
|
|
|
|
|
|
|
|
|
|
2013-03-11 20:17:19 +01:00
|
|
|
|
class Category(models.Model):
|
|
|
|
|
name = models.CharField(max_length=255, verbose_name=ugettext_lazy("Category name"))
|
2013-03-12 23:54:37 +01:00
|
|
|
|
"""Name of the category."""
|
|
|
|
|
|
2013-03-14 21:36:02 +01:00
|
|
|
|
prefix = models.CharField(blank=True, max_length=32, verbose_name=ugettext_lazy("Prefix"))
|
2013-03-12 23:54:37 +01:00
|
|
|
|
"""Prefix of the category.
|
|
|
|
|
|
|
|
|
|
Used to build the identifier of a motion.
|
|
|
|
|
"""
|
2013-03-11 20:17:19 +01:00
|
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
|
return self.name
|
2013-02-05 18:46:46 +01:00
|
|
|
|
|
2013-03-11 20:17:19 +01:00
|
|
|
|
def get_absolute_url(self, link='update'):
|
|
|
|
|
if link == 'update' or link == 'edit':
|
|
|
|
|
return reverse('motion_category_update', args=[str(self.id)])
|
2013-03-11 21:38:07 +01:00
|
|
|
|
if link == 'delete':
|
|
|
|
|
return reverse('motion_category_delete', args=[str(self.id)])
|
2013-02-05 18:46:46 +01:00
|
|
|
|
|
2013-03-11 21:29:56 +01:00
|
|
|
|
class Meta:
|
|
|
|
|
ordering = ['prefix']
|
2013-02-05 18:46:46 +01:00
|
|
|
|
|
|
|
|
|
## class Comment(models.Model):
|
|
|
|
|
## motion_version = models.ForeignKey(MotionVersion)
|
|
|
|
|
## text = models.TextField()
|
|
|
|
|
## author = PersonField()
|
|
|
|
|
## creation_time = models.DateTimeField(auto_now=True)
|
2013-02-01 12:51:54 +01:00
|
|
|
|
|
|
|
|
|
|
2013-02-02 21:40:23 +01:00
|
|
|
|
class MotionLog(models.Model):
|
2013-02-05 18:46:46 +01:00
|
|
|
|
"""Save a logmessage for a motion."""
|
|
|
|
|
|
2013-02-02 21:40:23 +01:00
|
|
|
|
motion = models.ForeignKey(Motion, related_name='log_messages')
|
2013-02-05 18:46:46 +01:00
|
|
|
|
"""The motion to witch the object belongs."""
|
|
|
|
|
|
2013-05-16 01:14:14 +02:00
|
|
|
|
message_list = JSONField()
|
|
|
|
|
"""
|
|
|
|
|
The log message. It should be a list of strings in english.
|
2013-02-05 18:46:46 +01:00
|
|
|
|
"""
|
|
|
|
|
|
2013-02-02 21:40:23 +01:00
|
|
|
|
person = PersonField(null=True)
|
2013-02-05 18:46:46 +01:00
|
|
|
|
"""A person object, who created the log message. Optional."""
|
|
|
|
|
|
2013-02-02 21:40:23 +01:00
|
|
|
|
time = models.DateTimeField(auto_now=True)
|
2013-02-05 18:46:46 +01:00
|
|
|
|
"""The Time, when the loged action was performed."""
|
2013-02-02 21:40:23 +01:00
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
ordering = ['-time']
|
|
|
|
|
|
|
|
|
|
def __unicode__(self):
|
2013-05-16 01:14:14 +02:00
|
|
|
|
"""
|
|
|
|
|
Return a string, representing the log message.
|
|
|
|
|
"""
|
2013-03-09 14:29:40 +01:00
|
|
|
|
time = formats.date_format(self.time, 'DATETIME_FORMAT')
|
2013-05-23 23:19:53 +02:00
|
|
|
|
return_message = '%s ' % time + ''.join(map(_, self.message_list))
|
2013-05-16 01:14:14 +02:00
|
|
|
|
if self.person is not None:
|
2013-05-23 23:19:53 +02:00
|
|
|
|
return_message += _(' by %s') % self.person
|
2013-05-16 01:14:14 +02:00
|
|
|
|
return return_message
|
2013-02-02 21:40:23 +01:00
|
|
|
|
|
2013-02-03 14:14:07 +01:00
|
|
|
|
|
2013-02-01 12:51:54 +01:00
|
|
|
|
class MotionVote(BaseVote):
|
2013-02-05 18:46:46 +01:00
|
|
|
|
"""Saves the votes for a MotionPoll.
|
|
|
|
|
|
|
|
|
|
There should allways be three MotionVote objects for each poll,
|
|
|
|
|
one for 'yes', 'no', and 'abstain'."""
|
|
|
|
|
|
2013-02-01 12:51:54 +01:00
|
|
|
|
option = models.ForeignKey('MotionOption')
|
2013-02-05 18:46:46 +01:00
|
|
|
|
"""The option object, to witch the vote belongs."""
|
2013-02-01 12:51:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MotionOption(BaseOption):
|
2013-02-05 18:46:46 +01:00
|
|
|
|
"""Links between the MotionPollClass and the MotionVoteClass.
|
|
|
|
|
|
|
|
|
|
There should be one MotionOption object for each poll."""
|
|
|
|
|
|
2013-02-01 12:51:54 +01:00
|
|
|
|
poll = models.ForeignKey('MotionPoll')
|
2013-02-05 18:46:46 +01:00
|
|
|
|
"""The poll object, to witch the object belongs."""
|
|
|
|
|
|
2013-02-01 12:51:54 +01:00
|
|
|
|
vote_class = MotionVote
|
2013-02-05 18:46:46 +01:00
|
|
|
|
"""The VoteClass, to witch this Class links."""
|
2013-02-01 12:51:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MotionPoll(CountInvalid, CountVotesCast, BasePoll):
|
2013-02-05 18:46:46 +01:00
|
|
|
|
"""The Class to saves the poll results for a motion poll."""
|
|
|
|
|
|
|
|
|
|
motion = models.ForeignKey(Motion, related_name='polls')
|
|
|
|
|
"""The motion to witch the object belongs."""
|
|
|
|
|
|
2013-02-01 12:51:54 +01:00
|
|
|
|
option_class = MotionOption
|
2013-02-05 18:46:46 +01:00
|
|
|
|
"""The option class, witch links between this object the the votes."""
|
|
|
|
|
|
2013-02-01 12:51:54 +01:00
|
|
|
|
vote_values = [
|
|
|
|
|
ugettext_noop('Yes'), ugettext_noop('No'), ugettext_noop('Abstain')]
|
2013-02-05 18:46:46 +01:00
|
|
|
|
"""The possible anwers for the poll. 'Yes, 'No' and 'Abstain'."""
|
2013-02-01 12:51:54 +01:00
|
|
|
|
|
|
|
|
|
poll_number = models.PositiveIntegerField(default=1)
|
2013-02-05 18:46:46 +01:00
|
|
|
|
"""An id for this poll in realation to a motion.
|
|
|
|
|
|
|
|
|
|
Is unique for each motion.
|
|
|
|
|
"""
|
2013-02-01 12:51:54 +01:00
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
unique_together = ("motion", "poll_number")
|
|
|
|
|
|
2013-02-01 13:24:44 +01:00
|
|
|
|
def __unicode__(self):
|
2013-02-05 18:46:46 +01:00
|
|
|
|
"""Return a string, representing the poll."""
|
2013-05-28 20:31:01 +02:00
|
|
|
|
return _('Vote %d') % self.poll_number
|
2013-02-01 13:24:44 +01:00
|
|
|
|
|
2013-02-01 12:51:54 +01:00
|
|
|
|
def get_absolute_url(self, link='edit'):
|
2013-02-05 18:46:46 +01:00
|
|
|
|
"""Return an URL for the poll.
|
|
|
|
|
|
|
|
|
|
The keyargument 'link' can be 'edit' or 'delete'.
|
|
|
|
|
"""
|
2013-02-01 13:24:44 +01:00
|
|
|
|
if link == 'edit':
|
|
|
|
|
return reverse('motion_poll_edit', args=[str(self.motion.pk),
|
|
|
|
|
str(self.poll_number)])
|
|
|
|
|
if link == 'delete':
|
|
|
|
|
return reverse('motion_poll_delete', args=[str(self.motion.pk),
|
|
|
|
|
str(self.poll_number)])
|
2013-02-01 12:51:54 +01:00
|
|
|
|
|
|
|
|
|
def set_options(self):
|
2013-02-05 18:46:46 +01:00
|
|
|
|
"""Create the option class for this poll."""
|
2013-02-01 12:51:54 +01:00
|
|
|
|
#TODO: maybe it is possible with .create() to call this without poll=self
|
2013-02-05 18:46:46 +01:00
|
|
|
|
# or call this in save()
|
2013-02-01 12:51:54 +01:00
|
|
|
|
self.get_option_class()(poll=self).save()
|
|
|
|
|
|
|
|
|
|
def append_pollform_fields(self, fields):
|
2013-02-05 18:46:46 +01:00
|
|
|
|
"""Apend the fields for invalid and votecast to the ModelForm."""
|
2013-02-01 12:51:54 +01:00
|
|
|
|
CountInvalid.append_pollform_fields(self, fields)
|
|
|
|
|
CountVotesCast.append_pollform_fields(self, fields)
|
2013-02-06 23:56:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class State(models.Model):
|
|
|
|
|
"""Defines a state for a motion.
|
|
|
|
|
|
|
|
|
|
Every state belongs to a workflow. All states of a workflow are linked together
|
|
|
|
|
via 'next_states'. One of these states is the first state, but this
|
|
|
|
|
is saved in the workflow table (one-to-one relation). In every state
|
|
|
|
|
you can configure some handling of a motion. See the following fields
|
|
|
|
|
for more information.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
|
"""A string representing the state."""
|
|
|
|
|
|
|
|
|
|
action_word = models.CharField(max_length=255)
|
|
|
|
|
"""An alternative string to be used for a button to switch to this state."""
|
|
|
|
|
|
|
|
|
|
workflow = models.ForeignKey('Workflow')
|
|
|
|
|
"""A many-to-one relation to a workflow."""
|
|
|
|
|
|
|
|
|
|
next_states = models.ManyToManyField('self', symmetrical=False)
|
|
|
|
|
"""A many-to-many relation to all states, that can be choosen from this state."""
|
|
|
|
|
|
|
|
|
|
icon = models.CharField(max_length=255)
|
|
|
|
|
"""A string representing the url to the icon-image."""
|
|
|
|
|
|
|
|
|
|
allow_support = models.BooleanField(default=False)
|
|
|
|
|
"""If true, persons can support the motion in this state."""
|
|
|
|
|
|
|
|
|
|
allow_create_poll = models.BooleanField(default=False)
|
|
|
|
|
"""If true, polls can be created in this state."""
|
|
|
|
|
|
|
|
|
|
allow_submitter_edit = models.BooleanField(default=False)
|
|
|
|
|
"""If true, the submitter can edit the motion in this state."""
|
|
|
|
|
|
|
|
|
|
versioning = models.BooleanField(default=False)
|
|
|
|
|
"""
|
|
|
|
|
If true, editing the motion will create a new version by default.
|
|
|
|
|
This behavior can be changed by the form and view, e. g. via the
|
|
|
|
|
MotionDisableVersioningMixin.
|
|
|
|
|
"""
|
|
|
|
|
|
2013-04-22 22:31:58 +02:00
|
|
|
|
leave_old_version_active = models.BooleanField(default=False)
|
2013-02-06 23:56:21 +01:00
|
|
|
|
"""If true, new versions are not automaticly set active."""
|
|
|
|
|
|
2013-03-12 22:13:17 +01:00
|
|
|
|
dont_set_identifier = models.BooleanField(default=False)
|
|
|
|
|
"""Decides if the motion gets an identifier.
|
|
|
|
|
|
|
|
|
|
If true, the motion does not get an identifier if the state change to
|
|
|
|
|
this one, else it does."""
|
2013-03-12 22:03:56 +01:00
|
|
|
|
|
2013-02-06 23:56:21 +01:00
|
|
|
|
def __unicode__(self):
|
|
|
|
|
"""Returns the name of the state."""
|
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
|
def save(self, **kwargs):
|
|
|
|
|
"""Saves a state to the database.
|
|
|
|
|
|
|
|
|
|
Used to check the integrity before saving.
|
|
|
|
|
"""
|
|
|
|
|
self.check_next_states()
|
|
|
|
|
super(State, self).save(**kwargs)
|
|
|
|
|
|
|
|
|
|
def get_action_word(self):
|
|
|
|
|
"""Returns the alternative name of the state if it exists."""
|
|
|
|
|
return self.action_word or self.name
|
|
|
|
|
|
|
|
|
|
def check_next_states(self):
|
|
|
|
|
"""Checks whether all next states of a state belong to the correct workflow."""
|
|
|
|
|
# No check if it is a new state which has not been saved yet.
|
|
|
|
|
if not self.id:
|
|
|
|
|
return
|
|
|
|
|
for state in self.next_states.all():
|
|
|
|
|
if not state.workflow == self.workflow:
|
|
|
|
|
raise WorkflowError('%s can not be next state of %s because it does not belong to the same workflow.' % (state, self))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Workflow(models.Model):
|
|
|
|
|
"""Defines a workflow for a motion."""
|
|
|
|
|
|
|
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
|
"""A string representing the workflow."""
|
|
|
|
|
|
2013-03-11 21:32:09 +01:00
|
|
|
|
first_state = models.OneToOneField(State, related_name='+', null=True)
|
2013-02-06 23:56:21 +01:00
|
|
|
|
"""A one-to-one relation to a state, the starting point for the workflow."""
|
|
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
|
"""Returns the name of the workflow."""
|
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
|
def save(self, **kwargs):
|
|
|
|
|
"""Saves a workflow to the database.
|
|
|
|
|
|
|
|
|
|
Used to check the integrity before saving.
|
|
|
|
|
"""
|
|
|
|
|
self.check_first_state()
|
|
|
|
|
super(Workflow, self).save(**kwargs)
|
|
|
|
|
|
|
|
|
|
def check_first_state(self):
|
|
|
|
|
"""Checks whether the first_state itself belongs to the workflow."""
|
2013-03-11 21:32:09 +01:00
|
|
|
|
if self.first_state and not self.first_state.workflow == self:
|
2013-02-06 23:56:21 +01:00
|
|
|
|
raise WorkflowError('%s can not be first state of %s because it does not belong to it.' % (self.first_state, self))
|