config pages in apps

This commit is contained in:
Oskar Hahn 2012-03-16 14:31:59 +01:00
parent ccdce52caa
commit fb17b16fae
16 changed files with 309 additions and 190 deletions

View File

@ -11,7 +11,7 @@
"""
from django.forms import Form, ModelForm, IntegerField, ChoiceField, \
ModelChoiceField, HiddenInput, Select
ModelChoiceField, HiddenInput, Select, TextInput
from django.utils.translation import ugettext as _
from mptt.forms import TreeNodeChoiceField
@ -41,3 +41,7 @@ class ItemOrderForm(Form, CssClassMixin):
label="")
self = IntegerField(widget=HiddenInput(attrs={'class': 'menu-mlid'}))
parent = IntegerField(widget=HiddenInput(attrs={'class': 'menu-plid'}))
class ConfigForm(Form, CssClassMixin):
agenda_countdown_time = IntegerField(widget=TextInput(attrs={'class':'small-input'}),label=_("Countdown (in seconds)"),initial=60, min_value=0)

View File

@ -7,7 +7,7 @@
{% block content %}
<h1>{%trans "Agenda settings" %}</h1>
<form action="" method="post">{% csrf_token %}
{{ form_agenda.as_p }}
{{ form.as_p }}
<p>
<button class="button" type="submit">
<span class="icon ok">{%trans 'Save' %}</span>

View File

@ -18,7 +18,7 @@ from django.core.context_processors import csrf
from django.views.generic.detail import SingleObjectMixin
from utils.pdf import stylesheet
from utils.views import TemplateView, RedirectView, UpdateView, CreateView, DeleteView, PDFView
from utils.views import TemplateView, RedirectView, UpdateView, CreateView, DeleteView, PDFView, FormView
from system import config
@ -26,7 +26,7 @@ from projector.api import get_active_slide, set_active_slide
from agenda.models import Item
from agenda.api import is_summary
from agenda.forms import ItemOrderForm, ItemForm
from agenda.forms import ItemOrderForm, ItemForm, ConfigForm
class View(TemplateView):
@ -195,3 +195,17 @@ class ItemPDF(PDFView):
story.append(Paragraph("%s%s" % (space, item.title), stylesheet['Subitem']))
else:
story.append(Paragraph(item.title, stylesheet['Item']))
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)

View File

@ -10,7 +10,7 @@
:license: GNU GPL, see LICENSE for more details.
"""
from django.forms import ModelForm, Form, CharField, Textarea, TextInput, ModelMultipleChoiceField, ModelChoiceField, BooleanField, FileField, FileInput
from django.forms import ModelForm, Form, CharField, Textarea, TextInput, ModelMultipleChoiceField, ModelChoiceField, BooleanField, FileField, FileInput, IntegerField, ChoiceField, Select
from django.contrib.auth.models import User
from django.utils.translation import ugettext as _
@ -27,6 +27,7 @@ class UserModelChoiceField(ModelChoiceField):
def label_from_instance(self, obj):
return obj.get_full_name()
class UserModelMultipleChoiceField(ModelMultipleChoiceField):
"""
Extend ModelMultipleChoiceField for users so that the choices are
@ -42,6 +43,7 @@ class ApplicationForm(Form, CssClassMixin):
reason = CharField(widget=Textarea(), required=False, label=_("Reason"))
trivial_change = BooleanField(required=False, label=_("Trivial change"), help_text=_("Trivial changes don't create a new version."))
class ApplicationManagerForm(ModelForm, CssClassMixin):
users = User.objects.all().exclude(profile=None).order_by("first_name")
submitter = UserModelChoiceField(queryset=users, label=_("Submitter"))
@ -51,5 +53,47 @@ class ApplicationManagerForm(ModelForm, CssClassMixin):
model = Application
exclude = ('number', 'status', 'permitted', 'log')
class ApplicationImportForm(Form, CssClassMixin):
csvfile = FileField(widget=FileInput(attrs={'size':'50'}), label=_("CSV File"))
class ConfigForm(Form, CssClassMixin):
application_min_supporters = IntegerField(
widget=TextInput(attrs={'class':'small-input'}),
label=_("Number of (minimum) required supporters for a application"),
initial=4,
min_value=0,
max_value=8,
)
application_preamble = CharField(
widget=TextInput(),
required=False,
label=_("Application preamble")
)
application_pdf_ballot_papers_selection = ChoiceField(
widget=Select(),
required=False,
label=_("Number of ballot papers (selection)"),
choices=[
("1", _("Number of all delegates")),
("2", _("Number of all participants")),
("0", _("Use the following custum number")),
]
)
application_pdf_ballot_papers_number = IntegerField(
widget=TextInput(attrs={'class':'small-input'}),
required=False,
min_value=1,
label=_("Custom number of ballot papers")
)
application_pdf_title = CharField(
widget=TextInput(),
required=False,
label=_("Title for PDF document (all applications)")
)
application_pdf_preamble = CharField(
widget=Textarea(),
required=False,
label=_("Preamble text for PDF document (all applications)")
)

View File

@ -7,7 +7,7 @@
{% block content %}
<h1>{%trans "Application settings" %}</h1>
<form action="" method="post">{% csrf_token %}
{{ form_application.as_p }}
{{ form.as_p }}
<p>
<button class="button" type="submit">
<span class="icon ok">{%trans 'Save' %}</span>

View File

@ -29,9 +29,12 @@ from system import config
from agenda.models import Item
from application.models import Application, AVersion, ApplicationPoll
from application.forms import ApplicationForm, \
ApplicationManagerForm, \
ApplicationImportForm
from application.forms import (
ApplicationForm,
ApplicationManagerForm,
ApplicationImportForm,
ConfigForm,
)
from participant.models import Profile
@ -39,6 +42,7 @@ from poll.views import PollFormView
from utils.utils import template, permission_required, \
render_to_forbitten, del_confirm_form, gen_confirm_form
from utils.views import FormView
from utils.pdf import print_application, print_application_poll
@ -583,3 +587,27 @@ def application_import(request):
}
class Config(FormView):
permission_required = 'system.can_manage_system'
form_class = ConfigForm
template_name = 'application/config.html'
def get_initial(self):
return {
'application_min_supporters': config['application_min_supporters'],
'application_preamble': config['application_preamble'],
'application_pdf_ballot_papers_selection': config['application_pdf_ballot_papers_selection'],
'application_pdf_ballot_papers_number': config['application_pdf_ballot_papers_number'],
'application_pdf_title': config['application_pdf_title'],
'application_pdf_preamble': config['application_pdf_preamble'],
}
def form_valid(self, form):
config['application_min_supporters'] = form.cleaned_data['application_min_supporters']
config['application_preamble'] = form.cleaned_data['application_preamble']
config['application_pdf_ballot_papers_selection'] = form.cleaned_data['application_pdf_ballot_papers_selection']
config['application_pdf_ballot_papers_number'] = form.cleaned_data['application_pdf_ballot_papers_number']
config['application_pdf_title'] = form.cleaned_data['application_pdf_title']
config['application_pdf_preamble'] = form.cleaned_data['application_pdf_preamble']
messages.success(self.request, _('Application settings successfully saved.'))
return super(Config, self).form_valid(form)

View File

@ -10,6 +10,7 @@
:license: GNU GPL, see LICENSE for more details.
"""
from django import forms
from django.forms import ModelForm, Form, ModelChoiceField, Select
from django.utils.translation import ugettext as _
@ -30,3 +31,35 @@ class AssignmentRunForm(Form, CssClassMixin):
queryset=Profile.objects.all().order_by('user__first_name'),
label=_("Nominate a participant"),
)
class ConfigForm(Form, CssClassMixin):
assignment_publish_winner_results_only = forms.BooleanField(
required=False,
label=_("Only publish voting results for selected winners (Projector view only)")
)
assignment_pdf_ballot_papers_selection = forms.ChoiceField(widget=forms.Select(),
required=False,
label=_("Number of ballot papers (selection)"),
choices=[
("1", _("Number of all delegates")),
("2", _("Number of all participants")),
("0", _("Use the following custum number"))
]
)
assignment_pdf_ballot_papers_number = forms.IntegerField(
widget=forms.TextInput(attrs={'class':'small-input'}),
required=False,
min_value=1,
label=_("Custom number of ballot papers")
)
assignment_pdf_title = forms.CharField(
widget=forms.TextInput(),
required=False,
label=_("Title for PDF document (all elections)")
)
assignment_pdf_preamble = forms.CharField(
widget=forms.Textarea(),
required=False,
label=_("Preamble text for PDF document (all elections)")
)

View File

@ -7,7 +7,7 @@
{% block content %}
<h1>{%trans "Election settings" %}</h1>
<form action="" method="post">{% csrf_token %}
{{ form_assignment.as_p }}
{{ form.as_p }}
<p>
<button class="button" type="submit">
<span class="icon ok">{%trans 'Save' %}</span>

View File

@ -18,11 +18,14 @@ from django.utils.translation import ugettext as _
from utils.utils import template, permission_required, gen_confirm_form, del_confirm_form, ajax_request
from utils.pdf import print_assignment, print_assignment_poll
from utils.views import FormView
from system import config
from poll.views import PollFormView
from assignment.models import Assignment, AssignmentPoll, AssignmentOption
from assignment.forms import AssignmentForm, AssignmentRunForm
from assignment.forms import AssignmentForm, AssignmentRunForm, ConfigForm
from participant.models import Profile
@ -261,3 +264,30 @@ def set_elected(request, assignment_id, profile_id, elected=True):
'text': text})
return redirect(reverse('assignment_view', args=[assignment_id]))
class Config(FormView):
permission_required = 'system.can_manage_system'
form_class = ConfigForm
template_name = 'assignment/config.html'
def get_initial(self):
return {
'assignment_publish_winner_results_only': config['assignment_publish_winner_results_only'],
'assignment_pdf_ballot_papers_selection': config['assignment_pdf_ballot_papers_selection'],
'assignment_pdf_ballot_papers_number': config['assignment_pdf_ballot_papers_number'],
'assignment_pdf_title': config['assignment_pdf_title'],
'assignment_pdf_preamble': config['assignment_pdf_preamble'],
}
def form_valid(self, form):
if form.cleaned_data['assignment_publish_winner_results_only']:
config['assignment_publish_winner_results_only'] = True
else:
config['assignment_publish_winner_results_only'] = False
config['assignment_pdf_ballot_papers_selection'] = form.cleaned_data['assignment_pdf_ballot_papers_selection']
config['assignment_pdf_ballot_papers_number'] = form.cleaned_data['assignment_pdf_ballot_papers_number']
config['assignment_pdf_title'] = form.cleaned_data['assignment_pdf_title']
config['assignment_pdf_preamble'] = form.cleaned_data['assignment_pdf_preamble']
messages.success(self.request, _('Election settings successfully saved.'))
return super(Config, self).form_valid(form)

View File

@ -29,24 +29,3 @@ class EventConfigForm(Form, CssClassMixin):
event_date = CharField(widget=TextInput(), required=False, label=_("Event date"))
event_location = CharField(widget=TextInput(), required=False, label=_("Event location"))
event_organizer = CharField(widget=TextInput(), required=False, label=_("Event organizer"))
class AgendaConfigForm(Form, CssClassMixin):
agenda_countdown_time = IntegerField(widget=TextInput(attrs={'class':'small-input'}),label=_("Countdown (in seconds)"),initial=60, min_value=0)
class ApplicationConfigForm(Form, CssClassMixin):
application_min_supporters = IntegerField(widget=TextInput(attrs={'class':'small-input'}),label=_("Number of (minimum) required supporters for a application"),initial=4, min_value=0, max_value=8)
application_preamble = CharField(widget=TextInput(), required=False, label=_("Application preamble"))
application_pdf_ballot_papers_selection = ChoiceField(widget=Select(), required=False, label=_("Number of ballot papers (selection)"), choices=[("1", _("Number of all delegates")),("2", _("Number of all participants")),("0", _("Use the following custum number"))])
application_pdf_ballot_papers_number = IntegerField(widget=TextInput(attrs={'class':'small-input'}), required=False, min_value=1, label=_("Custom number of ballot papers"))
application_pdf_title = CharField(widget=TextInput(), required=False, label=_("Title for PDF document (all applications)"))
application_pdf_preamble = CharField(widget=Textarea(), required=False, label=_("Preamble text for PDF document (all applications)"))
class AssignmentConfigForm(Form, CssClassMixin):
assignment_publish_winner_results_only = BooleanField(required=False, label=_("Only publish voting results for selected winners (Projector view only)"))
assignment_pdf_ballot_papers_selection = ChoiceField(widget=Select(), required=False, label=_("Number of ballot papers (selection)"), choices=[("1", _("Number of all delegates")),("2", _("Number of all participants")),("0", _("Use the following custum number"))])
assignment_pdf_ballot_papers_number = IntegerField(widget=TextInput(attrs={'class':'small-input'}), required=False, min_value=1, label=_("Custom number of ballot papers"))
assignment_pdf_title = CharField(widget=TextInput(), required=False, label=_("Title for PDF document (all elections)"))
assignment_pdf_preamble = CharField(widget=Textarea(), required=False, label=_("Preamble text for PDF document (all elections)"))

View File

@ -11,10 +11,8 @@
{% url config_system as url_config_system %}
<h4 class="sectiontitle">{%trans "Configuration" %}</h4>
<ul>
<li class="{% if request.path == url_config_general %}selected{% endif %}"><a href="{% url config_general %}">{%trans "General" %}</a></li>
<li class="{% if request.path == url_config_agenda %}selected{% endif %}"><a href="{% url config_agenda %}">{%trans "Agenda" %}</a></li>
<li class="{% if request.path == url_config_application %}selected{% endif %}"><a href="{% url config_application %}">{%trans "Application" %}</a></li>
<li class="{% if request.path == url_config_assignment %}selected{% endif %}"><a href="{% url config_assignment %}">{%trans "Election" %}</a></li>
<li class="{% if request.path == url_config_system %}selected{% endif %}"><a href="{% url config_system %}">{%trans "System" %}</a></li>
{% for menu_link in menu_links %}
<li{% if menu_link.2 %} class="selected"{% endif %}><a href="{{ menu_link.0 }}">{{ menu_link.1 }}</a></li>
{% endfor %}
</ul>
{% endblock %}

View File

@ -7,7 +7,7 @@
{% block content %}
<h1>{%trans "General settings" %}</h1>
<form action="" method="post">{% csrf_token %}
{{ form_event.as_p }}
{{ form.as_p }}
<p>
<button class="button" type="submit">
<span class="icon ok">{%trans 'Save' %}</span>

View File

@ -11,20 +11,31 @@
"""
from django.conf.urls.defaults import *
from django.utils.importlib import import_module
import settings
from views import GeneralConfig
urlpatterns = patterns('system.views',
url(r'^config/general$', 'get_general_config',
name='config_general'),
url(r'^config/agenda$', 'get_agenda_config',
name='config_agenda'),
url(r'^config/application$', 'get_application_config',
name='config_application'),
url(r'^config/assignment$', 'get_assignment_config',
name='config_assignment'),
url(r'^config/system$', 'get_system_config',
name='config_system'),
url(r'^general/$',
GeneralConfig.as_view(),
name='config_general',
),
)
for app in settings.INSTALLED_APPS:
try:
mod = import_module(app + '.views')
except ImportError:
continue
appname = mod.__name__.split('.')[0]
try:
urlpatterns += patterns('', url(
r'^%s/$' % appname,
mod.Config.as_view(),
name='config_%s' % appname,
))
except AttributeError:
continue

View File

@ -15,150 +15,102 @@ from django.core.urlresolvers import reverse
from django.contrib import messages
from django.contrib.auth.models import Group, Permission
from django.utils.translation import ugettext as _
from django.dispatch import receiver
from django.template.loader import render_to_string
from django.utils.importlib import import_module
from utils.utils import template
from utils.utils import template, permission_required
from utils.views import FormView
from system.forms import SystemConfigForm, EventConfigForm, AgendaConfigForm, ApplicationConfigForm, AssignmentConfigForm
from system.forms import SystemConfigForm, EventConfigForm
from openslides.utils.signals import template_manipulation
from system import config
import settings
@permission_required('system.can_manage_system')
@template('system/general.html')
def get_general_config(request):
if request.method == 'POST':
form_event = EventConfigForm(request.POST, prefix='event')
if form_event.is_valid():
# event form
config['event_name'] = form_event.cleaned_data['event_name']
config['event_description'] = form_event.cleaned_data['event_description']
config['event_date'] = form_event.cleaned_data['event_date']
config['event_location'] = form_event.cleaned_data['event_location']
config['event_organizer'] = form_event.cleaned_data['event_organizer']
messages.success(request, _('General settings successfully saved.'))
else:
messages.error(request, _('Please check the form for errors.'))
else:
form_event = EventConfigForm(initial={
class GeneralConfig(FormView):
permission_required = 'system.can_manage_system'
form_class = EventConfigForm
template_name = 'system/general.html'
def get_initial(self):
return {
'event_name': config['event_name'],
'event_description': config['event_description'],
'event_date': config['event_date'],
'event_location': config['event_location'],
'event_organizer': config['event_organizer'],
}, prefix='event')
return {
'form_event': form_event,
}
}
@permission_required('system.can_manage_system')
@template('system/agenda.html')
def get_agenda_config(request):
if request.method == 'POST':
form_agenda = AgendaConfigForm(request.POST, prefix='agenda')
if form_agenda.is_valid():
config['agenda_countdown_time'] = form_agenda.cleaned_data['agenda_countdown_time']
messages.success(request, _('Agenda settings successfully saved.'))
else:
messages.error(request, _('Please check the form for errors.'))
else:
form_agenda = AgendaConfigForm(initial={
'agenda_countdown_time': config['agenda_countdown_time'],
}, prefix='agenda')
return {
'form_agenda': form_agenda,
}
def form_valid(self, form):
config['event_name'] = form.cleaned_data['event_name']
config['event_description'] = form.cleaned_data['event_description']
config['event_date'] = form.cleaned_data['event_date']
config['event_location'] = form.cleaned_data['event_location']
config['event_organizer'] = form.cleaned_data['event_organizer']
messages.success(self.request, _('General settings successfully saved.'))
return super(GeneralConfig, self).form_valid(form)
@permission_required('system.can_manage_system')
@template('system/application.html')
def get_application_config(request):
if request.method == 'POST':
form_application = ApplicationConfigForm(request.POST, prefix='application')
form_assignment = AssignmentConfigForm(request.POST, prefix='assignment')
if form_application.is_valid():
config['application_min_supporters'] = form_application.cleaned_data['application_min_supporters']
config['application_preamble'] = form_application.cleaned_data['application_preamble']
config['application_pdf_ballot_papers_selection'] = form_application.cleaned_data['application_pdf_ballot_papers_selection']
config['application_pdf_ballot_papers_number'] = form_application.cleaned_data['application_pdf_ballot_papers_number']
config['application_pdf_title'] = form_application.cleaned_data['application_pdf_title']
config['application_pdf_preamble'] = form_application.cleaned_data['application_pdf_preamble']
messages.success(request, _('Application settings successfully saved.'))
else:
messages.error(request, _('Please check the form for errors.'))
else:
form_application = ApplicationConfigForm(initial={
'application_min_supporters': config['application_min_supporters'],
'application_preamble': config['application_preamble'],
'application_pdf_ballot_papers_selection': config['application_pdf_ballot_papers_selection'],
'application_pdf_ballot_papers_number': config['application_pdf_ballot_papers_number'],
'application_pdf_title': config['application_pdf_title'],
'application_pdf_preamble': config['application_pdf_preamble'],
}, prefix='application')
return {
'form_application': form_application,
}
def form_invalid(self, form):
messages.error(self.request, _('Please check the form for errors.'))
return super(Config, self).form_invalid(form)
@permission_required('system.can_manage_system')
@template('system/assignment.html')
def get_assignment_config(request):
if request.method == 'POST':
form_assignment = AssignmentConfigForm(request.POST, prefix='assignment')
if form_assignment.is_valid():
if form_assignment.cleaned_data['assignment_publish_winner_results_only']:
config['assignment_publish_winner_results_only'] = True
else:
config['assignment_publish_winner_results_only'] = ''
config['assignment_pdf_ballot_papers_selection'] = form_assignment.cleaned_data['assignment_pdf_ballot_papers_selection']
config['assignment_pdf_ballot_papers_number'] = form_assignment.cleaned_data['assignment_pdf_ballot_papers_number']
config['assignment_pdf_title'] = form_assignment.cleaned_data['assignment_pdf_title']
config['assignment_pdf_preamble'] = form_assignment.cleaned_data['assignment_pdf_preamble']
messages.success(request, _('Election settings successfully saved.'))
else:
messages.error(request, _('Please check the form for errors.'))
else:
form_assignment = AssignmentConfigForm(initial={
'assignment_publish_winner_results_only': config['assignment_publish_winner_results_only'],
'assignment_pdf_ballot_papers_selection': config['assignment_pdf_ballot_papers_selection'],
'assignment_pdf_ballot_papers_number': config['assignment_pdf_ballot_papers_number'],
'assignment_pdf_title': config['assignment_pdf_title'],
'assignment_pdf_preamble': config['assignment_pdf_preamble'],
}, prefix='assignment')
return {
'form_assignment': form_assignment,
}
@permission_required('system.can_manage_system')
@template('system/system.html')
def get_system_config(request):
if request.method == 'POST':
form = SystemConfigForm(request.POST)
if form.is_valid():
config['system_url'] = form.cleaned_data['system_url']
config['system_welcometext'] = form.cleaned_data['system_welcometext']
if form.cleaned_data['system_enable_anonymous']:
config['system_enable_anonymous'] = True
# check for Anonymous group and (re)create it as needed
try:
anonymous = Group.objects.get(name='Anonymous')
except Group.DoesNotExist:
default_perms = [u'can_see_agenda', u'can_see_projector', u'can_see_application']
anonymous = Group()
anonymous.name = 'Anonymous'
anonymous.save()
anonymous.permissions = Permission.objects.filter(codename__in=default_perms)
anonymous.save()
messages.success(request, _('Anonymous access enabled. Please modify the "Anonymous" group to fit your required permissions.'))
else:
# use '' - False will evaluate to uniced(False) => True..
config['system_enable_anonymous'] = ''
messages.success(request, _('System settings successfully saved.'))
class Config(FormView):
permission_required = 'system.can_manage_system'
form_class = SystemConfigForm
template_name = 'system/system.html'
def get_initial(self):
return {
'system_url': config['system_url'],
'system_welcometext': config['system_welcometext'],
'system_enable_anonymous': config['system_enable_anonymous'],
}
def form_valid(self, form):
config['system_url'] = form.cleaned_data['system_url']
config['system_welcometext'] = form.cleaned_data['system_welcometext']
if form.cleaned_data['system_enable_anonymous']:
config['system_enable_anonymous'] = True
# check for Anonymous group and (re)create it as needed
try:
anonymous = Group.objects.get(name='Anonymous')
except Group.DoesNotExist:
default_perms = [u'can_see_agenda', u'can_see_projector', u'can_see_application']
anonymous = Group()
anonymous.name = 'Anonymous'
anonymous.save()
anonymous.permissions = Permission.objects.filter(codename__in=default_perms)
anonymous.save()
messages.success(self.request, _('Anonymous access enabled. Please modify the "Anonymous" group to fit your required permissions.'))
else:
messages.error(request, _('Please check the form for errors.'))
else:
form = SystemConfigForm(initial={
'system_url': config['system_url'],
'system_welcometext': config['system_welcometext'],
'system_enable_anonymous': config['system_enable_anonymous'],
})
return {
'form': form,
}
config['system_enable_anonymous'] = False
messages.success(self.request, _('System settings successfully saved.'))
return super(Config, self).form_valid(form)
@receiver(template_manipulation, dispatch_uid="system_base_system")
def set_submenu(sender, request, **kwargs):
selected = True if request.path == reverse('config_general') else False
menu_links = [
(reverse('config_general'), _('General'), selected),
]
for app in settings.INSTALLED_APPS:
try:
mod = import_module(app + '.views')
mod.Config
except (ImportError, AttributeError):
continue
appname = mod.__name__.split('.')[0]
selected = True if reverse('config_%s' % appname) == request.path else False
menu_links.append(
(reverse('config_%s' % appname), _(appname.title()), selected)
)
kwargs['context'].update({
'menu_links': menu_links,
})

View File

@ -30,7 +30,7 @@ urlpatterns = patterns('',
(r'', include('application.urls')),
(r'', include('participant.urls')),
(r'', include('assignment.urls')),
(r'', include('system.urls')),
(r'config/', include('system.urls')),
(r'projector/', include('projector.urls')),
(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_DOC_ROOT}),
(r'^i18n/', include('django.conf.urls.i18n')),

View File

@ -12,17 +12,23 @@ from reportlab.platypus import SimpleDocTemplate, Paragraph, Frame, PageBreak, S
from reportlab.lib.units import cm
from django.conf import settings
from django.contrib import messages
from django.utils.translation import ugettext as _
from django.http import HttpResponseServerError, HttpResponse
from django.core.urlresolvers import reverse
from django.template import loader, RequestContext
from django.template.loader import render_to_string
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.views.generic import (TemplateView as _TemplateView,
RedirectView as _RedirectView,
UpdateView as _UpdateView,
CreateView as _CreateView,
View,)
from django.views.generic import (
TemplateView as _TemplateView,
RedirectView as _RedirectView,
UpdateView as _UpdateView,
CreateView as _CreateView,
View,
FormView as _FormView,
)
from django.views.generic.detail import SingleObjectMixin
from utils import render_to_forbitten
@ -56,7 +62,6 @@ class PermissionMixin(object):
return super(LoginMixin, self).dispatch(request, *args, **kwargs)
class TemplateView(_TemplateView, PermissionMixin):
def get_context_data(self, **kwargs):
context = super(TemplateView, self).get_context_data(**kwargs)
@ -91,12 +96,33 @@ class RedirectView(_RedirectView, PermissionMixin):
return {}
class FormView(_FormView, PermissionMixin):
def get_success_url(self):
if not self.success_url:
return ''
return reverse(super(FormView, self).get_success_url())
def get_context_data(self, **kwargs):
context = super(FormView, self).get_context_data(**kwargs)
template_manipulation.send(sender=self, request=self.request, context=context)
return context
def form_invalid(self, form):
messages.error(self.request, _('Please check the form for errors.'))
return super(FormView, self).form_invalid(form)
class UpdateView(_UpdateView, PermissionMixin):
def get_success_url(self):
if 'apply' in self.request.POST:
return ''
return reverse(super(UpdateView, self).get_success_url())
def get_context_data(self, **kwargs):
context = super(UpdateView, self).get_context_data(**kwargs)
template_manipulation.send(sender=self, context=context)
return context
class CreateView(_CreateView, PermissionMixin):
def get_success_url(self):