2011-07-31 10:46:29 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
openslides.agenda.models
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Models for the agenda app.
|
|
|
|
|
|
|
|
:copyright: 2011 by the OpenSlides team, see AUTHORS.
|
|
|
|
: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
|
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
|
2012-02-03 23:12:28 +01:00
|
|
|
from beamer.models import Element
|
|
|
|
from beamer.api import element_register
|
|
|
|
from system.api import config_set
|
|
|
|
from application.models import Application
|
|
|
|
from poll.models import Poll
|
|
|
|
from assignment.models import Assignment
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
|
|
|
2012-02-03 23:12:28 +01:00
|
|
|
class Item(models.Model, Element):
|
2011-07-31 10:46:29 +02:00
|
|
|
"""
|
2012-02-03 23:12:28 +01:00
|
|
|
An Agenda Item
|
2011-07-31 10:46:29 +02:00
|
|
|
"""
|
|
|
|
title = models.CharField(max_length=100, verbose_name=_("Title"))
|
2012-02-03 23:12:28 +01:00
|
|
|
text = models.TextField(null=True, blank=True, verbose_name=_("Text"))
|
|
|
|
transcript = models.TextField(null=True, blank=True, verbose_name=_("Transcript"))
|
2011-07-31 10:46:29 +02:00
|
|
|
closed = models.BooleanField(default=False, verbose_name=_("Closed"))
|
|
|
|
weight = models.IntegerField(default=0, verbose_name=_("Weight"))
|
|
|
|
parent = models.ForeignKey('self', blank=True, null=True)
|
|
|
|
hidden = models.BooleanField(default=False,
|
|
|
|
verbose_name=_("Hidden (visible for agenda manager only)"))
|
2012-02-03 23:12:28 +01:00
|
|
|
prefix = 'item'
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2012-02-03 23:12:28 +01:00
|
|
|
|
|
|
|
def beamer(self):
|
2011-07-31 10:46:29 +02:00
|
|
|
"""
|
2012-02-03 23:12:28 +01:00
|
|
|
Return a map with all Data for the Beamer
|
2011-07-31 10:46:29 +02:00
|
|
|
"""
|
2012-02-03 23:12:28 +01:00
|
|
|
return {
|
|
|
|
'item': self,
|
|
|
|
'title': self.title,
|
|
|
|
'template': 'beamer/AgendaText.html',
|
|
|
|
}
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def active_parent(self):
|
|
|
|
"""
|
|
|
|
Return True if the item has a activ parent
|
|
|
|
"""
|
2012-02-03 23:12:28 +01:00
|
|
|
if get_active_element(only_id=True) in \
|
2011-07-31 10:46:29 +02:00
|
|
|
[parent.id for parent in self.parents]:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def set_active(self, summary=False):
|
|
|
|
"""
|
|
|
|
Appoint this item as the active one.
|
|
|
|
"""
|
2012-02-03 23:12:28 +01:00
|
|
|
Element.set_active(self)
|
2011-07-31 10:46:29 +02:00
|
|
|
if summary:
|
|
|
|
config_set("summary", True)
|
|
|
|
else:
|
|
|
|
config_set("summary", '')
|
|
|
|
|
|
|
|
def set_closed(self, closed=True):
|
|
|
|
"""
|
|
|
|
Changes the closed-status of the item.
|
|
|
|
"""
|
|
|
|
self.closed = closed
|
|
|
|
self.save()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def parents(self):
|
|
|
|
"""
|
|
|
|
Return the parent of this item, and the parent's partent and so
|
|
|
|
furth a list.
|
|
|
|
"""
|
|
|
|
parents = []
|
|
|
|
item = self
|
|
|
|
while item.parent is not None:
|
|
|
|
parents.append(item.parent)
|
|
|
|
item = item.parent
|
|
|
|
return parents
|
|
|
|
|
|
|
|
@property
|
|
|
|
def children(self):
|
|
|
|
"""
|
|
|
|
Return a list of all childitems from the next generation. The list
|
|
|
|
is ordert by weight. The childitems are not cast, so there are only
|
|
|
|
Item-objects and not Item-type objects.
|
|
|
|
"""
|
|
|
|
return self.item_set.order_by("weight")
|
|
|
|
|
|
|
|
@property
|
|
|
|
def weight_form(self):
|
|
|
|
"""
|
|
|
|
Return the WeightForm for this item.
|
|
|
|
"""
|
|
|
|
from agenda.forms import ElementOrderForm
|
|
|
|
try:
|
|
|
|
parent = self.parent.id
|
|
|
|
except AttributeError:
|
|
|
|
parent = 0
|
|
|
|
initial = {
|
|
|
|
'weight': self.weight,
|
|
|
|
'self': self.id,
|
|
|
|
'parent': parent,
|
|
|
|
}
|
|
|
|
return ElementOrderForm(initial=initial, prefix="i%d" % self.id)
|
|
|
|
|
|
|
|
def edit_form(self, post=None):
|
|
|
|
"""
|
|
|
|
Return the EditForm for this item.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
return self._edit_form
|
|
|
|
except AttributeError:
|
|
|
|
from agenda.forms import MODELFORM
|
|
|
|
try:
|
|
|
|
form = MODELFORM[self.type]
|
|
|
|
except KeyError:
|
|
|
|
raise NameError(_("No Form for itemtype %s") % self.type)
|
|
|
|
|
|
|
|
self._edit_form = form(post, instance=self)
|
|
|
|
return self._edit_form
|
|
|
|
|
|
|
|
@models.permalink
|
|
|
|
def get_absolute_url(self, link='view'):
|
|
|
|
"""
|
|
|
|
Return the URL to this item. By default it is the Link to its
|
|
|
|
beamer-view.
|
|
|
|
|
|
|
|
link can be:
|
|
|
|
* view
|
|
|
|
* delete
|
|
|
|
"""
|
|
|
|
if link == 'view':
|
|
|
|
return ('item_view', [str(self.id)])
|
|
|
|
if link == 'delete':
|
|
|
|
return ('item_delete', [str(self.id)])
|
|
|
|
|
2011-08-31 18:25:03 +02:00
|
|
|
@property
|
|
|
|
def json(self):
|
|
|
|
"""
|
|
|
|
Return the model as jquery data
|
|
|
|
"""
|
|
|
|
return json.dumps({
|
|
|
|
'id': self.id,
|
|
|
|
'active': self.active,
|
|
|
|
})
|
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
def __unicode__(self):
|
|
|
|
return self.title
|
|
|
|
|
|
|
|
def cast(self):
|
|
|
|
try:
|
|
|
|
return self.realobject
|
|
|
|
except AttributeError:
|
|
|
|
self.realobject = super(Item, self).cast()
|
|
|
|
return self.realobject
|
|
|
|
|
|
|
|
@property
|
|
|
|
def type(self):
|
|
|
|
"""
|
|
|
|
Return the name of the class from this item
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
return self._type
|
|
|
|
except AttributeError:
|
|
|
|
self._type = self.cast().__class__.__name__
|
|
|
|
return self._type
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
permissions = (
|
2011-09-04 12:21:58 +02:00
|
|
|
('can_see_agenda', "Can see agenda"),
|
|
|
|
('can_manage_agenda', "Can manage agenda"),
|
2011-09-04 12:33:06 +02:00
|
|
|
('can_see_projector', "Can see projector"),
|
2011-07-31 10:46:29 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2012-02-03 23:12:28 +01:00
|
|
|
ItemText = Item # ItemText is Depricated
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-02-03 23:12:28 +01:00
|
|
|
element_register(Item.prefix, Item)
|