OpenSlides/openslides/agenda/models.py

146 lines
3.7 KiB
Python
Raw Normal View History

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.
"""
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 _
from mptt.models import MPTTModel, TreeForeignKey
2012-02-15 12:04:11 +01:00
from system import config
2012-03-03 09:11:56 +01:00
from projector.models import SlideMixin
2012-02-06 22:22:16 +01:00
from projector.api import register_slidemodel
2012-02-15 12:04:11 +01:00
2012-02-09 01:46:58 +01:00
from agenda.api import is_summary
2011-07-31 10:46:29 +02:00
2012-03-03 09:11:56 +01:00
class Item(MPTTModel, SlideMixin):
2011-07-31 10:46:29 +02:00
"""
An Agenda Item
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'
2011-07-31 10:46:29 +02:00
title = models.CharField(max_length=100, verbose_name=_("Title"))
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 = TreeForeignKey('self', null=True, blank=True, related_name='children')
2011-07-31 10:46:29 +02:00
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-02-09 01:46:58 +01:00
data = {
'item': self,
'title': self.title,
2012-02-06 22:08:08 +01:00
'template': 'projector/AgendaText.html',
}
2011-07-31 10:46:29 +02:00
2012-02-09 01:46:58 +01:00
if is_summary():
2012-03-03 09:11:56 +01:00
data['items'] = self.children.all()
2012-02-09 01:46:58 +01:00
data['template'] = 'projector/AgendaSummary.html'
return data
2011-07-31 10:46:29 +02:00
def set_active(self, summary=False):
"""
Appoint this item as the active one.
"""
2012-03-03 09:11:56 +01:00
super(Item, self).set_active()
2011-07-31 10:46:29 +02:00
if summary:
2012-02-15 12:04:11 +01:00
config["agenda_summary"] = True
2011-07-31 10:46:29 +02:00
else:
2012-02-15 12:04:11 +01:00
config["agenda_summary"] = False
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:
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
@models.permalink
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
* delete
"""
if link == 'view':
return ('item_view', [str(self.id)])
if link == 'delete':
return ('item_delete', [str(self.id)])
def __unicode__(self):
return self.title
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
)
class MPTTMeta:
order_insertion_by = ['weight', 'title']
2011-07-31 10:46:29 +02:00
2012-03-03 11:16:10 +01:00
register_slidemodel(Item, category=_('Agenda'), model_name=_('Agenda Item'))
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
register_slidefunc('agenda_show', agenda_show, category=_('Agenda'))
2012-02-15 12:36:50 +01:00
2011-07-31 10:46:29 +02:00