2011-07-31 10:46:29 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
openslides.agenda.models
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Models for the agenda app.
|
|
|
|
|
2012-04-25 22:29:19 +02:00
|
|
|
:copyright: 2011, 2012 by OpenSlides team, see AUTHORS.
|
2011-07-31 10:46:29 +02:00
|
|
|
:license: GNU GPL, see LICENSE for more details.
|
|
|
|
"""
|
|
|
|
|
2011-08-31 18:25:03 +02:00
|
|
|
try:
|
|
|
|
import json
|
|
|
|
except ImportError:
|
2012-07-04 12:50:33 +02:00
|
|
|
# for python 2.5 support
|
2011-08-31 18:25:03 +02:00
|
|
|
import simplejson as json
|
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
from django.db import models
|
2012-06-03 09:35:26 +02:00
|
|
|
from django.core.urlresolvers import reverse
|
2012-07-20 11:22:09 +02:00
|
|
|
from django.utils.translation import ugettext_lazy as _, ugettext_noop, ugettext
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2012-02-20 00:14:54 +01:00
|
|
|
from mptt.models import MPTTModel, TreeForeignKey
|
|
|
|
|
2012-07-04 12:50:33 +02:00
|
|
|
from openslides.config.models import config
|
2012-02-15 12:04:11 +01:00
|
|
|
|
2012-07-04 12:50:33 +02:00
|
|
|
from openslides.projector.projector import SlideMixin
|
|
|
|
from openslides.projector.api import (register_slidemodel, get_slide_from_sid,
|
|
|
|
register_slidefunc, split_sid)
|
2012-02-15 12:04:11 +01:00
|
|
|
|
2012-07-04 12:50:33 +02:00
|
|
|
from openslides.agenda.slides import agenda_show
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2012-04-14 11:18:47 +02:00
|
|
|
|
2012-03-03 09:11:56 +01:00
|
|
|
class Item(MPTTModel, SlideMixin):
|
2011-07-31 10:46:29 +02:00
|
|
|
"""
|
2012-02-03 23:12:28 +01:00
|
|
|
An Agenda Item
|
2012-02-21 13:17:42 +01:00
|
|
|
|
|
|
|
MPTT-model. See http://django-mptt.github.com/django-mptt/
|
2011-07-31 10:46:29 +02:00
|
|
|
"""
|
2012-02-09 02:29:38 +01:00
|
|
|
prefix = 'item'
|
|
|
|
|
2012-07-04 12:50:33 +02:00
|
|
|
title = models.CharField(null=True, max_length=255, verbose_name=_("Title"))
|
2012-02-03 23:12:28 +01:00
|
|
|
text = models.TextField(null=True, blank=True, verbose_name=_("Text"))
|
2012-04-15 09:41:17 +02:00
|
|
|
comment = models.TextField(null=True, blank=True, verbose_name=_("Comment"))
|
2011-07-31 10:46:29 +02:00
|
|
|
closed = models.BooleanField(default=False, verbose_name=_("Closed"))
|
|
|
|
weight = models.IntegerField(default=0, verbose_name=_("Weight"))
|
2012-07-04 12:50:33 +02:00
|
|
|
parent = TreeForeignKey('self', null=True, blank=True,
|
|
|
|
related_name='children')
|
|
|
|
related_sid = models.CharField(null=True, blank=True, max_length=63)
|
2012-04-19 12:46:04 +02:00
|
|
|
|
2012-07-04 11:00:58 +02:00
|
|
|
def get_related_slide(self):
|
2012-07-04 12:50:33 +02:00
|
|
|
"""
|
|
|
|
return the object, of which the item points.
|
|
|
|
"""
|
2012-08-05 11:28:56 +02:00
|
|
|
object = get_slide_from_sid(self.related_sid, element=True)
|
|
|
|
if object is None:
|
|
|
|
self.title = 'Item for deleted slide: %s' % self.related_sid
|
|
|
|
self.related_sid = None
|
|
|
|
self.save()
|
|
|
|
return self
|
|
|
|
else:
|
|
|
|
return object
|
2012-04-19 12:46:04 +02:00
|
|
|
|
2012-07-04 11:00:58 +02:00
|
|
|
def get_related_type(self):
|
2012-07-04 12:50:33 +02:00
|
|
|
"""
|
|
|
|
return the type of the releated slide.
|
|
|
|
"""
|
2012-07-04 11:00:58 +02:00
|
|
|
return self.get_related_slide().prefix
|
2012-06-03 09:35:26 +02:00
|
|
|
|
2012-07-04 11:00:58 +02:00
|
|
|
def print_related_type(self):
|
2012-06-30 11:06:32 +02:00
|
|
|
"""
|
2012-07-04 11:00:58 +02:00
|
|
|
Print the type of the related item.
|
2012-06-30 11:06:32 +02:00
|
|
|
|
|
|
|
For use in Template
|
2012-07-04 11:00:58 +02:00
|
|
|
??Why does {% trans item.print_related_type|capfirst %} not work??
|
2012-06-30 11:06:32 +02:00
|
|
|
"""
|
2012-07-20 11:22:09 +02:00
|
|
|
return ugettext(self.get_related_type().capitalize())
|
2012-06-30 11:06:32 +02:00
|
|
|
|
2012-04-19 12:46:04 +02:00
|
|
|
def get_title(self):
|
2012-07-04 12:50:33 +02:00
|
|
|
"""
|
|
|
|
return the title of this item.
|
|
|
|
"""
|
2012-07-04 11:00:58 +02:00
|
|
|
if self.related_sid is None:
|
2012-04-19 12:46:04 +02:00
|
|
|
return self.title
|
2012-07-04 11:00:58 +02:00
|
|
|
return self.get_related_slide().get_agenda_title()
|
2012-04-19 12:46:04 +02:00
|
|
|
|
2012-07-20 11:22:09 +02:00
|
|
|
|
|
|
|
def get_title_supplement(self):
|
|
|
|
"""
|
|
|
|
return a supplement for the title.
|
|
|
|
"""
|
|
|
|
if self.related_sid is None:
|
|
|
|
return ''
|
|
|
|
try:
|
|
|
|
return self.get_related_slide().get_agenda_title_supplement()
|
|
|
|
except AttributeError:
|
|
|
|
return '(%s)' % self.print_related_type()
|
|
|
|
|
2012-02-06 22:08:08 +01:00
|
|
|
def slide(self):
|
2011-07-31 10:46:29 +02:00
|
|
|
"""
|
2012-02-06 22:08:08 +01:00
|
|
|
Return a map with all Data for the Slide
|
2011-07-31 10:46:29 +02:00
|
|
|
"""
|
2012-07-01 16:10:26 +02:00
|
|
|
if config['presentation_argument'] == 'summary':
|
|
|
|
data = {
|
|
|
|
'title': self.get_title(),
|
|
|
|
'items': self.get_children(),
|
|
|
|
'template': 'projector/AgendaSummary.html',
|
|
|
|
}
|
2012-07-04 11:00:58 +02:00
|
|
|
elif self.related_sid:
|
|
|
|
data = self.get_related_slide().slide()
|
2012-07-01 16:10:26 +02:00
|
|
|
else:
|
|
|
|
data = {
|
|
|
|
'item': self,
|
|
|
|
'title': self.get_title(),
|
|
|
|
'template': 'projector/AgendaText.html',
|
|
|
|
}
|
2012-02-09 01:46:58 +01:00
|
|
|
return data
|
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
def set_closed(self, closed=True):
|
|
|
|
"""
|
|
|
|
Changes the closed-status of the item.
|
|
|
|
"""
|
|
|
|
self.closed = closed
|
|
|
|
self.save()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def weight_form(self):
|
|
|
|
"""
|
|
|
|
Return the WeightForm for this item.
|
|
|
|
"""
|
2012-07-10 14:00:51 +02:00
|
|
|
from openslides.agenda.forms import ItemOrderForm
|
2011-07-31 10:46:29 +02:00
|
|
|
try:
|
|
|
|
parent = self.parent.id
|
|
|
|
except AttributeError:
|
|
|
|
parent = 0
|
|
|
|
initial = {
|
|
|
|
'weight': self.weight,
|
|
|
|
'self': self.id,
|
|
|
|
'parent': parent,
|
|
|
|
}
|
2012-02-06 22:22:16 +01:00
|
|
|
return ItemOrderForm(initial=initial, prefix="i%d" % self.id)
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2012-06-23 11:41:32 +02:00
|
|
|
def delete(self, with_children=False):
|
|
|
|
"""
|
|
|
|
Delete the Item.
|
|
|
|
"""
|
|
|
|
if not with_children:
|
|
|
|
for child in self.get_children():
|
|
|
|
child.move_to(self.parent)
|
|
|
|
child.save()
|
|
|
|
super(Item, self).delete()
|
|
|
|
Item.objects.rebuild()
|
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
def get_absolute_url(self, link='view'):
|
|
|
|
"""
|
|
|
|
Return the URL to this item. By default it is the Link to its
|
2012-02-06 22:08:08 +01:00
|
|
|
slide
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
|
|
link can be:
|
|
|
|
* view
|
2012-06-23 10:27:58 +02:00
|
|
|
* edit
|
2011-07-31 10:46:29 +02:00
|
|
|
* delete
|
|
|
|
"""
|
|
|
|
if link == 'view':
|
2012-07-04 11:00:58 +02:00
|
|
|
if self.related_sid:
|
|
|
|
return self.get_related_slide().get_absolute_url(link)
|
2012-06-03 09:35:26 +02:00
|
|
|
return reverse('item_view', args=[str(self.id)])
|
|
|
|
if link == 'edit':
|
2012-07-04 11:00:58 +02:00
|
|
|
if self.related_sid:
|
|
|
|
return self.get_related_slide().get_absolute_url(link)
|
2012-06-03 09:35:26 +02:00
|
|
|
return reverse('item_edit', args=[str(self.id)])
|
2011-07-31 10:46:29 +02:00
|
|
|
if link == 'delete':
|
2012-06-03 09:35:26 +02:00
|
|
|
return reverse('item_delete', args=[str(self.id)])
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
|
|
def __unicode__(self):
|
2012-04-19 12:46:04 +02:00
|
|
|
return self.get_title()
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
permissions = (
|
2012-07-04 12:50:33 +02:00
|
|
|
('can_see_agenda', ugettext_noop("Can see agenda")),
|
|
|
|
('can_manage_agenda', ugettext_noop("Can manage agenda")),
|
2011-07-31 10:46:29 +02:00
|
|
|
)
|
|
|
|
|
2012-02-20 00:14:54 +01:00
|
|
|
class MPTTMeta:
|
2012-04-19 12:46:04 +02:00
|
|
|
order_insertion_by = ['weight']
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
|
|
|
2012-04-18 14:53:19 +02:00
|
|
|
register_slidemodel(Item, control_template='agenda/control_item.html')
|
2012-04-15 15:46:32 +02:00
|
|
|
register_slidefunc('agenda', agenda_show, weight=-1, name=_('Agenda'))
|