2011-07-31 10:46:29 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
openslides.agenda.views
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Views for the agenda app.
|
|
|
|
|
|
|
|
:copyright: 2011 by the OpenSlides team, see AUTHORS.
|
|
|
|
:license: GNU GPL, see LICENSE for more details.
|
|
|
|
"""
|
2012-02-21 13:17:42 +01:00
|
|
|
from reportlab.platypus import Paragraph
|
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
from django.core.urlresolvers import reverse
|
|
|
|
from django.contrib import messages
|
|
|
|
from django.utils.translation import ugettext as _
|
2012-02-20 17:46:45 +01:00
|
|
|
from django.core.context_processors import csrf
|
2012-02-20 19:39:26 +01:00
|
|
|
from django.views.generic.detail import SingleObjectMixin
|
2012-02-20 17:46:45 +01:00
|
|
|
|
2012-02-21 13:17:42 +01:00
|
|
|
from utils.pdf import stylesheet
|
2012-03-16 14:31:59 +01:00
|
|
|
from utils.views import TemplateView, RedirectView, UpdateView, CreateView, DeleteView, PDFView, FormView
|
2012-03-18 17:11:58 +01:00
|
|
|
from utils.template import Tab
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2012-02-15 12:04:11 +01:00
|
|
|
from system import config
|
|
|
|
|
2012-02-09 02:29:38 +01:00
|
|
|
from projector.api import get_active_slide, set_active_slide
|
|
|
|
|
2012-02-03 23:12:28 +01:00
|
|
|
from agenda.models import Item
|
2012-02-20 17:46:45 +01:00
|
|
|
from agenda.api import is_summary
|
2012-03-16 14:31:59 +01:00
|
|
|
from agenda.forms import ItemOrderForm, ItemForm, ConfigForm
|
2012-02-20 17:46:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
class View(TemplateView):
|
|
|
|
permission_required = 'agenda.can_see_projector'
|
|
|
|
template_name = 'projector/AgendaText.html'
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(View, self).get_context_data(**kwargs)
|
|
|
|
context.update({
|
2012-03-03 09:11:56 +01:00
|
|
|
'item': Item.objects.get(pk=kwargs['pk']),
|
2012-02-20 17:46:45 +01:00
|
|
|
'ajax': 'off',
|
|
|
|
})
|
|
|
|
return context
|
|
|
|
|
|
|
|
|
|
|
|
class Overview(TemplateView):
|
|
|
|
permission_required = 'agenda.can_see_agenda'
|
|
|
|
template_name = 'agenda/overview.html'
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
2012-03-18 17:11:58 +01:00
|
|
|
context = super(Overview, self).get_context_data(**kwargs)
|
2012-02-20 17:46:45 +01:00
|
|
|
context.update({
|
|
|
|
'items': Item.objects.all(),
|
|
|
|
'overview': get_active_slide(only_sid=True) == 'agenda_show',
|
|
|
|
'summary': is_summary(),
|
|
|
|
})
|
|
|
|
return context
|
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
2012-03-18 17:11:58 +01:00
|
|
|
#todo: check for permission
|
2012-02-20 17:46:45 +01:00
|
|
|
context = self.get_context_data(**kwargs)
|
|
|
|
#todo: check for any erros in the forms befor saving the data
|
2011-07-31 10:46:29 +02:00
|
|
|
for item in Item.objects.all():
|
2012-02-06 22:22:16 +01:00
|
|
|
form = ItemOrderForm(request.POST, prefix="i%d" % item.id)
|
2011-07-31 10:46:29 +02:00
|
|
|
if form.is_valid():
|
|
|
|
try:
|
2012-02-09 02:29:38 +01:00
|
|
|
item.parent = Item.objects.get(
|
2011-07-31 10:46:29 +02:00
|
|
|
id=form.cleaned_data['parent'])
|
|
|
|
except Item.DoesNotExist:
|
|
|
|
item.parent = None
|
|
|
|
item.weight = form.cleaned_data['weight']
|
|
|
|
item.save()
|
2012-02-20 17:46:45 +01:00
|
|
|
return self.render_to_response(context)
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
|
|
|
2012-02-20 19:39:26 +01:00
|
|
|
class SetActive(RedirectView, SingleObjectMixin):
|
2011-07-31 10:46:29 +02:00
|
|
|
"""
|
|
|
|
Set an Item as the active one.
|
|
|
|
"""
|
2012-02-20 17:46:45 +01:00
|
|
|
url = 'item_overview'
|
|
|
|
allow_ajax = True
|
|
|
|
permission_required = 'agenda.can_manage_agenda'
|
2012-02-20 19:39:26 +01:00
|
|
|
model = Item
|
2012-02-20 17:46:45 +01:00
|
|
|
|
|
|
|
def get_ajax_context(self, **kwargs):
|
|
|
|
context = super(SetActive, self).get_ajax_context(**kwargs)
|
|
|
|
context.update({
|
2012-02-20 19:39:26 +01:00
|
|
|
'active': kwargs['pk'],
|
2012-02-20 17:46:45 +01:00
|
|
|
'summary': is_summary(),
|
|
|
|
})
|
|
|
|
return context
|
|
|
|
|
|
|
|
def pre_redirect(self, request, *args, **kwargs):
|
|
|
|
summary = kwargs['summary']
|
2012-02-20 19:39:26 +01:00
|
|
|
if kwargs['pk'] == "0":
|
2012-02-20 17:46:45 +01:00
|
|
|
set_active_slide("agenda_show")
|
|
|
|
else:
|
2012-02-20 19:39:26 +01:00
|
|
|
self.object = self.get_object()
|
|
|
|
self.object.set_active(summary)
|
2012-02-20 17:46:45 +01:00
|
|
|
config["bigger"] = 100
|
|
|
|
config["up"] = 0
|
|
|
|
return super(SetActive, self).pre_redirect(request, *args, **kwargs)
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
|
|
|
2012-02-20 19:39:26 +01:00
|
|
|
class SetClosed(RedirectView, SingleObjectMixin):
|
2011-07-31 10:46:29 +02:00
|
|
|
"""
|
|
|
|
Close or open an Item.
|
|
|
|
"""
|
2012-02-20 17:46:45 +01:00
|
|
|
permission_required = 'agenda.can_manage_agenda'
|
|
|
|
allow_ajax = True
|
|
|
|
url = 'item_overview'
|
2012-02-20 19:39:26 +01:00
|
|
|
model = Item
|
2011-09-02 20:46:24 +02:00
|
|
|
|
2012-02-20 17:46:45 +01:00
|
|
|
def get_ajax_context(self, **kwargs):
|
|
|
|
context = super(SetClosed, self).get_ajax_context(**kwargs)
|
|
|
|
closed = kwargs['closed']
|
2011-08-31 23:47:31 +02:00
|
|
|
if closed:
|
2012-02-20 19:39:26 +01:00
|
|
|
link = reverse('item_open', args=[self.object.id])
|
2011-08-31 23:47:31 +02:00
|
|
|
else:
|
2012-02-20 19:39:26 +01:00
|
|
|
link = reverse('item_close', args=[self.object.id])
|
2012-02-20 17:46:45 +01:00
|
|
|
context.update({
|
|
|
|
'closed': kwargs['closed'],
|
|
|
|
'link': link,
|
|
|
|
})
|
|
|
|
return context
|
|
|
|
|
|
|
|
def pre_redirect(self, request, *args, **kwargs):
|
2012-02-20 19:39:26 +01:00
|
|
|
self.object = self.get_object()
|
2012-02-20 17:46:45 +01:00
|
|
|
closed = kwargs['closed']
|
2012-02-20 19:39:26 +01:00
|
|
|
self.object.set_closed(closed)
|
2012-02-20 17:46:45 +01:00
|
|
|
return super(SetClosed, self).pre_redirect(request, *args, **kwargs)
|
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2012-02-20 17:46:45 +01:00
|
|
|
class ItemUpdate(UpdateView):
|
|
|
|
permission_required = 'agenda.can_manage_agenda'
|
|
|
|
template_name = 'agenda/edit.html'
|
|
|
|
model = Item
|
|
|
|
context_object_name = 'item'
|
|
|
|
form_class = ItemForm
|
|
|
|
success_url = 'item_overview'
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2012-02-20 17:46:45 +01:00
|
|
|
|
|
|
|
class ItemCreate(CreateView):
|
|
|
|
permission_required = 'agenda.can_manage_agenda'
|
|
|
|
template_name = 'agenda/edit.html'
|
|
|
|
model = Item
|
|
|
|
context_object_name = 'item'
|
|
|
|
form_class = ItemForm
|
|
|
|
success_url = 'item_overview'
|
|
|
|
|
|
|
|
|
|
|
|
class ItemDelete(DeleteView):
|
2011-07-31 10:46:29 +02:00
|
|
|
"""
|
|
|
|
Delete an Item.
|
|
|
|
"""
|
2012-02-20 17:46:45 +01:00
|
|
|
permission_required = 'agenda.can_manage_agenda'
|
|
|
|
model = Item
|
|
|
|
url = 'item_overview'
|
|
|
|
|
|
|
|
def pre_post_redirect(self, request, *args, **kwargs):
|
|
|
|
self.object = self.get_object()
|
2012-02-09 02:29:38 +01:00
|
|
|
|
2011-09-03 12:45:19 +02:00
|
|
|
if 'all' in request.POST:
|
2012-02-20 17:46:45 +01:00
|
|
|
self.object.delete()
|
|
|
|
messages.success(request, _("Item <b>%s</b> and his children were successfully deleted.") % self.object)
|
2011-09-03 12:45:19 +02:00
|
|
|
else:
|
2012-02-21 13:36:00 +01:00
|
|
|
for child in self.object.get_children():
|
2012-02-20 17:46:45 +01:00
|
|
|
child.parent = self.object.parent
|
2011-09-03 12:45:19 +02:00
|
|
|
child.save()
|
2012-02-20 17:46:45 +01:00
|
|
|
self.object.delete()
|
|
|
|
messages.success(request, _("Item <b>%s</b> was successfully deleted.") % self.object)
|
|
|
|
|
|
|
|
def gen_confirm_form(self, request, message, url, singleitem=None):
|
|
|
|
if singleitem:
|
|
|
|
messages.warning(request, '%s<form action="%s" method="post"><input type="hidden" value="%s" name="csrfmiddlewaretoken"><input type="submit" value="%s" /> <input type="button" value="%s"></form>' % (message, url, csrf(request)['csrf_token'], _("Yes"), _("No")))
|
|
|
|
else:
|
|
|
|
messages.warning(request, '%s<form action="%s" method="post"><input type="hidden" value="%s" name="csrfmiddlewaretoken"><input type="submit" value="%s" /> <input type="submit" name="all" value="%s" /> <input type="button" value="%s"></form>' % (message, url, csrf(request)['csrf_token'], _("Yes"), _("Yes, with all child items."), _("No")))
|
|
|
|
|
|
|
|
def confirm_form(self, request, object, name=None):
|
|
|
|
if name is None:
|
|
|
|
name = object
|
|
|
|
if object.children:
|
|
|
|
self.gen_confirm_form(request, _('Do you really want to delete <b>%s</b>?') % name, object.get_absolute_url('delete'), False)
|
|
|
|
else:
|
|
|
|
self.gen_confirm_form(request, _('Do you really want to delete <b>%s</b>?') % name, object.get_absolute_url('delete'), True)
|
2012-02-21 13:17:42 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ItemPDF(PDFView):
|
|
|
|
permission_required = 'agenda.can_see_agenda'
|
|
|
|
filename = _('Agenda')
|
|
|
|
|
|
|
|
def append_to_pdf(self, story):
|
|
|
|
for item in Item.objects.all():
|
|
|
|
ancestors = item.get_ancestors()
|
|
|
|
if ancestors:
|
|
|
|
space = " " * ancestors.count()
|
|
|
|
story.append(Paragraph("%s%s" % (space, item.title), stylesheet['Subitem']))
|
|
|
|
else:
|
|
|
|
story.append(Paragraph(item.title, stylesheet['Item']))
|
2012-03-16 14:31:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Config(FormView):
|
|
|
|
permission_required = 'system.can_manage_system'
|
|
|
|
form_class = ConfigForm
|
|
|
|
template_name = 'agenda/config.html'
|
|
|
|
|
|
|
|
def get_initial(self):
|
|
|
|
return {'agenda_countdown_time': config['agenda_countdown_time']}
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
config['agenda_countdown_time'] = form.cleaned_data['agenda_countdown_time']
|
|
|
|
messages.success(self.request, _('Agenda settings successfully saved.'))
|
|
|
|
return super(Config, self).form_valid(form)
|
2012-03-18 17:11:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
def register_tab(request):
|
|
|
|
selected = True if request.path.startswith('/agenda/') else False
|
|
|
|
return Tab(
|
|
|
|
title=_('Agenda'),
|
|
|
|
url=reverse('item_overview'),
|
|
|
|
permission=request.user.has_perm('agenda.can_see_agenda') or request.user.has_perm('agenda.can_manage_agenda'),
|
|
|
|
selected=selected,
|
|
|
|
)
|