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-09 02:29:38 +01:00
|
|
|
from django.shortcuts import redirect
|
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-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 00:14:54 +01:00
|
|
|
from agenda.api import is_summary, del_confirm_form_for_items
|
2012-02-06 22:22:16 +01:00
|
|
|
from agenda.forms import ItemOrderForm, ItemFormText
|
2012-02-09 02:29:38 +01:00
|
|
|
|
2012-02-03 23:12:28 +01:00
|
|
|
from utils.utils import template, permission_required, \
|
2011-09-02 20:46:24 +02:00
|
|
|
del_confirm_form, ajax_request
|
2012-02-03 23:12:28 +01:00
|
|
|
from utils.pdf import print_agenda
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2012-02-09 02:29:38 +01:00
|
|
|
|
|
|
|
@permission_required('agenda.can_see_projector')
|
|
|
|
@template('projector/AgendaText.html')
|
2011-07-31 10:46:29 +02:00
|
|
|
def view(request, item_id):
|
|
|
|
"""
|
|
|
|
Shows the Slide.
|
|
|
|
"""
|
2012-02-09 02:29:38 +01:00
|
|
|
item = Item.objects.get(pk=item_id)
|
|
|
|
return {
|
|
|
|
'item': item,
|
|
|
|
'ajax': 'off',
|
|
|
|
}
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2011-09-07 23:25:59 +02:00
|
|
|
|
2011-09-04 12:21:58 +02:00
|
|
|
@permission_required('agenda.can_see_agenda')
|
2011-07-31 10:46:29 +02:00
|
|
|
@template('agenda/overview.html')
|
|
|
|
def overview(request):
|
|
|
|
"""
|
|
|
|
Shows an overview of all items.
|
|
|
|
"""
|
|
|
|
if request.method == 'POST':
|
|
|
|
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 00:14:54 +01:00
|
|
|
items = Item.objects.all()
|
2012-02-09 02:29:38 +01:00
|
|
|
|
2012-02-09 01:46:58 +01:00
|
|
|
if get_active_slide(only_sid=True) == 'agenda_show':
|
2011-07-31 10:46:29 +02:00
|
|
|
overview = True
|
2012-02-09 01:46:58 +01:00
|
|
|
else:
|
|
|
|
overview = False
|
2011-07-31 10:46:29 +02:00
|
|
|
return {
|
|
|
|
'items': items,
|
|
|
|
'overview': overview,
|
2011-11-09 21:16:02 +01:00
|
|
|
'summary': is_summary(),
|
2012-02-15 12:04:11 +01:00
|
|
|
'countdown_visible': config['countdown_visible'],
|
|
|
|
'countdown_time': config['agenda_countdown_time'],
|
2012-02-09 02:29:38 +01:00
|
|
|
}
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
@permission_required('agenda.can_manage_agenda')
|
|
|
|
def set_active(request, item_id, summary=False):
|
|
|
|
"""
|
|
|
|
Set an Item as the active one.
|
|
|
|
"""
|
|
|
|
if item_id == "0":
|
2012-02-09 02:29:38 +01:00
|
|
|
set_active_slide("agenda_show")
|
2011-07-31 10:46:29 +02:00
|
|
|
else:
|
|
|
|
try:
|
2012-02-09 02:29:38 +01:00
|
|
|
item = Item.objects.get(pk=item_id)
|
2011-07-31 10:46:29 +02:00
|
|
|
item.set_active(summary)
|
|
|
|
except Item.DoesNotExist:
|
|
|
|
messages.error(request, _('Item ID %d does not exist.') % int(item_id))
|
2012-02-15 12:04:11 +01:00
|
|
|
config["bigger"] = 100
|
|
|
|
config["up"] = 0
|
2011-08-31 18:25:03 +02:00
|
|
|
if request.is_ajax():
|
2012-02-09 02:29:38 +01:00
|
|
|
return ajax_request({'active': item_id, 'summary': summary})
|
2011-08-31 18:25:03 +02:00
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
return redirect(reverse('item_overview'))
|
|
|
|
|
|
|
|
|
|
|
|
@permission_required('agenda.can_manage_agenda')
|
|
|
|
def set_closed(request, item_id, closed=True):
|
|
|
|
"""
|
|
|
|
Close or open an Item.
|
|
|
|
"""
|
|
|
|
try:
|
2012-02-09 02:29:38 +01:00
|
|
|
item = Item.objects.get(pk=item_id)
|
2011-07-31 10:46:29 +02:00
|
|
|
item.set_closed(closed)
|
|
|
|
except Item.DoesNotExist:
|
|
|
|
messages.error(request, _('Item ID %d does not exist.') % int(item_id))
|
2011-09-02 20:46:24 +02:00
|
|
|
|
2011-08-31 23:47:31 +02:00
|
|
|
if request.is_ajax():
|
|
|
|
if closed:
|
|
|
|
link = reverse('item_open', args=[item.id])
|
|
|
|
else:
|
|
|
|
link = reverse('item_close', args=[item.id])
|
2011-09-02 20:46:24 +02:00
|
|
|
|
|
|
|
return ajax_request({'closed': closed,
|
|
|
|
'link': link})
|
2011-07-31 10:46:29 +02:00
|
|
|
return redirect(reverse('item_overview'))
|
|
|
|
|
|
|
|
|
|
|
|
@permission_required('agenda.can_manage_agenda')
|
|
|
|
@template('agenda/edit.html')
|
2012-02-06 10:10:20 +01:00
|
|
|
def edit(request, item_id=None):
|
2011-07-31 10:46:29 +02:00
|
|
|
"""
|
|
|
|
Show a form to edit an existing Item, or create a new one.
|
|
|
|
"""
|
|
|
|
if item_id is not None:
|
|
|
|
try:
|
2012-02-06 10:10:20 +01:00
|
|
|
item = Item.objects.get(pk=item_id)
|
2011-07-31 10:46:29 +02:00
|
|
|
except Item.DoesNotExist:
|
|
|
|
messages.error(request, _('Item ID %d does not exist.') % int(item_id))
|
|
|
|
return redirect(reverse('item_overview'))
|
|
|
|
else:
|
|
|
|
item = None
|
|
|
|
|
|
|
|
if request.method == 'POST':
|
2012-02-06 10:10:20 +01:00
|
|
|
form = ItemFormText(request.POST, instance=item)
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
|
|
if form.is_valid():
|
|
|
|
item = form.save()
|
|
|
|
if item_id is None:
|
|
|
|
messages.success(request, _('New item was successfully created.'))
|
|
|
|
else:
|
|
|
|
messages.success(request, _('Item was successfully modified.'))
|
2011-09-03 12:14:17 +02:00
|
|
|
if not 'apply' in request.POST:
|
|
|
|
return redirect(reverse('item_overview'))
|
2011-09-03 18:35:19 +02:00
|
|
|
if item_id is None:
|
|
|
|
return redirect(reverse('item_edit', args=[item.id]))
|
2011-09-03 12:14:17 +02:00
|
|
|
else:
|
|
|
|
messages.error(request, _('Please check the form for errors.'))
|
2011-07-31 10:46:29 +02:00
|
|
|
else:
|
2012-02-06 10:10:20 +01:00
|
|
|
form = ItemFormText(instance=item)
|
2012-02-09 02:29:38 +01:00
|
|
|
return {
|
|
|
|
'form': form,
|
|
|
|
'item': item,
|
|
|
|
}
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
@permission_required('agenda.can_manage_agenda')
|
|
|
|
def delete(request, item_id):
|
|
|
|
"""
|
|
|
|
Delete an Item.
|
|
|
|
"""
|
2012-02-09 02:29:38 +01:00
|
|
|
try:
|
|
|
|
item = Item.objects.get(pk=item_id)
|
|
|
|
except Item.DoesNotExist:
|
|
|
|
messages.error(request, _('Item ID %d does not exist.') % int(item_id))
|
|
|
|
return redirect(reverse('item_overview'))
|
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
if request.method == 'POST':
|
2011-09-03 12:45:19 +02:00
|
|
|
if 'all' in request.POST:
|
|
|
|
item.delete()
|
|
|
|
messages.success(request, _("Item <b>%s</b> and his children were successfully deleted.") % item)
|
|
|
|
else:
|
|
|
|
for child in item.children:
|
|
|
|
child.parent = item.parent
|
|
|
|
child.save()
|
|
|
|
item.delete()
|
|
|
|
messages.success(request, _("Item <b>%s</b> was successfully deleted.") % item)
|
2011-07-31 10:46:29 +02:00
|
|
|
else:
|
2011-09-03 12:45:19 +02:00
|
|
|
del_confirm_form_for_items(request, item)
|
2011-07-31 10:46:29 +02:00
|
|
|
return redirect(reverse('item_overview'))
|