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:
|
|
|
|
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
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2012-02-20 00:14:54 +01:00
|
|
|
from mptt.models import MPTTModel, TreeForeignKey
|
|
|
|
|
2012-04-14 12:52:56 +02:00
|
|
|
from config.models import config
|
2012-02-15 12:04:11 +01:00
|
|
|
|
2012-03-12 18:22:18 +01:00
|
|
|
from projector.projector import SlideMixin
|
2012-04-19 12:46:04 +02:00
|
|
|
from projector.api import register_slidemodel, get_slide_from_sid
|
2012-02-15 12:04:11 +01:00
|
|
|
|
2012-04-14 14:31:09 +02:00
|
|
|
from utils.translation_ext import ugettext as _
|
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-05-18 10:24:43 +02:00
|
|
|
title = models.CharField(null=True, max_length=256, 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-02-20 00:14:54 +01:00
|
|
|
parent = TreeForeignKey('self', null=True, blank=True, related_name='children')
|
2012-04-19 12:46:04 +02:00
|
|
|
releated_sid = models.CharField(null=True, blank=True, max_length=64)
|
|
|
|
|
|
|
|
def get_releated_slide(self):
|
|
|
|
return get_slide_from_sid(self.releated_sid, True)
|
|
|
|
|
2012-06-03 09:35:26 +02:00
|
|
|
def get_releated_type(self):
|
|
|
|
return self.get_releated_slide().prefix
|
|
|
|
|
2012-06-30 11:06:32 +02:00
|
|
|
def print_releated_type(self):
|
|
|
|
"""
|
|
|
|
Print the type of the releated item.
|
|
|
|
|
|
|
|
For use in Template
|
|
|
|
??Why does {% trans item.print_releated_type|capfirst %} not work??
|
|
|
|
"""
|
|
|
|
return _(self.get_releated_type().capitalize())
|
|
|
|
|
2012-04-19 12:46:04 +02:00
|
|
|
def get_title(self):
|
|
|
|
if self.releated_sid is None:
|
|
|
|
return self.title
|
|
|
|
return self.get_releated_slide().get_agenda_title()
|
|
|
|
|
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-06-03 09:35:26 +02:00
|
|
|
if self.releated_sid:
|
|
|
|
return self.get_releated_slide().slide()
|
2012-02-09 01:46:58 +01:00
|
|
|
data = {
|
2012-02-03 23:12:28 +01:00
|
|
|
'item': self,
|
2012-04-19 12:46:04 +02:00
|
|
|
'title': self.get_title(),
|
2012-02-06 22:08:08 +01:00
|
|
|
'template': 'projector/AgendaText.html',
|
2012-02-03 23:12:28 +01:00
|
|
|
}
|
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()
|
|
|
|
|
2012-02-09 02:29:38 +01:00
|
|
|
@property
|
|
|
|
def active_parent(self):
|
|
|
|
"""
|
|
|
|
Return True if the item has a active parent
|
|
|
|
"""
|
|
|
|
sid = get_active_slide(only_sid=True).split()
|
|
|
|
if len(sid) == 2 and sid[0] == self.prefix:
|
2012-02-20 00:14:54 +01:00
|
|
|
if self.get_ancestors().filter(pk=sid[0]).exists():
|
2012-02-09 02:29:38 +01:00
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
@property
|
|
|
|
def weight_form(self):
|
|
|
|
"""
|
|
|
|
Return the WeightForm for this item.
|
|
|
|
"""
|
2012-02-06 22:22:16 +01:00
|
|
|
from 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-06-03 10:19:08 +02:00
|
|
|
if self.releated_sid:
|
|
|
|
return self.get_releated_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-06-03 10:19:08 +02:00
|
|
|
if self.releated_sid:
|
|
|
|
return self.get_releated_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-04-14 09:28:28 +02:00
|
|
|
('can_see_agenda', _("Can see agenda", fixstr=True)),
|
|
|
|
('can_manage_agenda', _("Can manage agenda", fixstr=True)),
|
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')
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2012-03-03 09:11:56 +01:00
|
|
|
# TODO: put this in another file
|
2012-02-15 12:36:50 +01:00
|
|
|
|
|
|
|
from projector.api import register_slidefunc
|
|
|
|
from agenda.slides import agenda_show
|
|
|
|
|
2012-04-15 15:46:32 +02:00
|
|
|
register_slidefunc('agenda', agenda_show, weight=-1, name=_('Agenda'))
|
2012-04-14 12:52:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
from django.dispatch import receiver
|
|
|
|
from openslides.config.signals import default_config_value
|
|
|
|
|
|
|
|
|
|
|
|
@receiver(default_config_value, dispatch_uid="agenda_default_config")
|
|
|
|
def default_config(sender, key, **kwargs):
|
|
|
|
return {
|
|
|
|
'agenda_countdown_time': 60,
|
|
|
|
}.get(key)
|