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, \ from django.forms import Form, ModelForm, IntegerField, ChoiceField, \
ModelChoiceField, HiddenInput, Select ModelChoiceField, HiddenInput, Select, TextInput
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from mptt.forms import TreeNodeChoiceField from mptt.forms import TreeNodeChoiceField
@ -41,3 +41,7 @@ class ItemOrderForm(Form, CssClassMixin):
label="") label="")
self = IntegerField(widget=HiddenInput(attrs={'class': 'menu-mlid'})) self = IntegerField(widget=HiddenInput(attrs={'class': 'menu-mlid'}))
parent = IntegerField(widget=HiddenInput(attrs={'class': 'menu-plid'})) 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 %} {% block content %}
<h1>{%trans "Agenda settings" %}</h1> <h1>{%trans "Agenda settings" %}</h1>
<form action="" method="post">{% csrf_token %} <form action="" method="post">{% csrf_token %}
{{ form_agenda.as_p }} {{ form.as_p }}
<p> <p>
<button class="button" type="submit"> <button class="button" type="submit">
<span class="icon ok">{%trans 'Save' %}</span> <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 django.views.generic.detail import SingleObjectMixin
from utils.pdf import stylesheet 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 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.models import Item
from agenda.api import is_summary from agenda.api import is_summary
from agenda.forms import ItemOrderForm, ItemForm from agenda.forms import ItemOrderForm, ItemForm, ConfigForm
class View(TemplateView): class View(TemplateView):
@ -195,3 +195,17 @@ class ItemPDF(PDFView):
story.append(Paragraph("%s%s" % (space, item.title), stylesheet['Subitem'])) story.append(Paragraph("%s%s" % (space, item.title), stylesheet['Subitem']))
else: else:
story.append(Paragraph(item.title, stylesheet['Item'])) 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. :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.contrib.auth.models import User
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
@ -27,6 +27,7 @@ class UserModelChoiceField(ModelChoiceField):
def label_from_instance(self, obj): def label_from_instance(self, obj):
return obj.get_full_name() return obj.get_full_name()
class UserModelMultipleChoiceField(ModelMultipleChoiceField): class UserModelMultipleChoiceField(ModelMultipleChoiceField):
""" """
Extend ModelMultipleChoiceField for users so that the choices are 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")) 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.")) trivial_change = BooleanField(required=False, label=_("Trivial change"), help_text=_("Trivial changes don't create a new version."))
class ApplicationManagerForm(ModelForm, CssClassMixin): class ApplicationManagerForm(ModelForm, CssClassMixin):
users = User.objects.all().exclude(profile=None).order_by("first_name") users = User.objects.all().exclude(profile=None).order_by("first_name")
submitter = UserModelChoiceField(queryset=users, label=_("Submitter")) submitter = UserModelChoiceField(queryset=users, label=_("Submitter"))
@ -51,5 +53,47 @@ class ApplicationManagerForm(ModelForm, CssClassMixin):
model = Application model = Application
exclude = ('number', 'status', 'permitted', 'log') exclude = ('number', 'status', 'permitted', 'log')
class ApplicationImportForm(Form, CssClassMixin): class ApplicationImportForm(Form, CssClassMixin):
csvfile = FileField(widget=FileInput(attrs={'size':'50'}), label=_("CSV File")) 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 %} {% block content %}
<h1>{%trans "Application settings" %}</h1> <h1>{%trans "Application settings" %}</h1>
<form action="" method="post">{% csrf_token %} <form action="" method="post">{% csrf_token %}
{{ form_application.as_p }} {{ form.as_p }}
<p> <p>
<button class="button" type="submit"> <button class="button" type="submit">
<span class="icon ok">{%trans 'Save' %}</span> <span class="icon ok">{%trans 'Save' %}</span>

View File

@ -29,9 +29,12 @@ from system import config
from agenda.models import Item from agenda.models import Item
from application.models import Application, AVersion, ApplicationPoll from application.models import Application, AVersion, ApplicationPoll
from application.forms import ApplicationForm, \ from application.forms import (
ApplicationManagerForm, \ ApplicationForm,
ApplicationImportForm ApplicationManagerForm,
ApplicationImportForm,
ConfigForm,
)
from participant.models import Profile from participant.models import Profile
@ -39,6 +42,7 @@ from poll.views import PollFormView
from utils.utils import template, permission_required, \ from utils.utils import template, permission_required, \
render_to_forbitten, del_confirm_form, gen_confirm_form render_to_forbitten, del_confirm_form, gen_confirm_form
from utils.views import FormView
from utils.pdf import print_application, print_application_poll 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. :license: GNU GPL, see LICENSE for more details.
""" """
from django import forms
from django.forms import ModelForm, Form, ModelChoiceField, Select from django.forms import ModelForm, Form, ModelChoiceField, Select
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
@ -30,3 +31,35 @@ class AssignmentRunForm(Form, CssClassMixin):
queryset=Profile.objects.all().order_by('user__first_name'), queryset=Profile.objects.all().order_by('user__first_name'),
label=_("Nominate a participant"), 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 %} {% block content %}
<h1>{%trans "Election settings" %}</h1> <h1>{%trans "Election settings" %}</h1>
<form action="" method="post">{% csrf_token %} <form action="" method="post">{% csrf_token %}
{{ form_assignment.as_p }} {{ form.as_p }}
<p> <p>
<button class="button" type="submit"> <button class="button" type="submit">
<span class="icon ok">{%trans 'Save' %}</span> <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.utils import template, permission_required, gen_confirm_form, del_confirm_form, ajax_request
from utils.pdf import print_assignment, print_assignment_poll from utils.pdf import print_assignment, print_assignment_poll
from utils.views import FormView
from system import config
from poll.views import PollFormView from poll.views import PollFormView
from assignment.models import Assignment, AssignmentPoll, AssignmentOption 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 from participant.models import Profile
@ -261,3 +264,30 @@ def set_elected(request, assignment_id, profile_id, elected=True):
'text': text}) 'text': text})
return redirect(reverse('assignment_view', args=[assignment_id])) 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_date = CharField(widget=TextInput(), required=False, label=_("Event date"))
event_location = CharField(widget=TextInput(), required=False, label=_("Event location")) event_location = CharField(widget=TextInput(), required=False, label=_("Event location"))
event_organizer = CharField(widget=TextInput(), required=False, label=_("Event organizer")) 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 %} {% url config_system as url_config_system %}
<h4 class="sectiontitle">{%trans "Configuration" %}</h4> <h4 class="sectiontitle">{%trans "Configuration" %}</h4>
<ul> <ul>
<li class="{% if request.path == url_config_general %}selected{% endif %}"><a href="{% url config_general %}">{%trans "General" %}</a></li> {% for menu_link in menu_links %}
<li class="{% if request.path == url_config_agenda %}selected{% endif %}"><a href="{% url config_agenda %}">{%trans "Agenda" %}</a></li> <li{% if menu_link.2 %} class="selected"{% endif %}><a href="{{ menu_link.0 }}">{{ menu_link.1 }}</a></li>
<li class="{% if request.path == url_config_application %}selected{% endif %}"><a href="{% url config_application %}">{%trans "Application" %}</a></li> {% endfor %}
<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>
</ul> </ul>
{% endblock %} {% endblock %}

View File

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

View File

@ -11,20 +11,31 @@
""" """
from django.conf.urls.defaults import * from django.conf.urls.defaults import *
from django.utils.importlib import import_module
import settings
from views import GeneralConfig
urlpatterns = patterns('system.views', urlpatterns = patterns('system.views',
url(r'^config/general$', 'get_general_config', url(r'^general/$',
name='config_general'), GeneralConfig.as_view(),
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'),
) )
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,123 +15,62 @@ from django.core.urlresolvers import reverse
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.models import Group, Permission from django.contrib.auth.models import Group, Permission
from django.utils.translation import ugettext as _ 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.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 from system import config
import settings
@permission_required('system.can_manage_system')
@template('system/general.html') class GeneralConfig(FormView):
def get_general_config(request): permission_required = 'system.can_manage_system'
if request.method == 'POST': form_class = EventConfigForm
form_event = EventConfigForm(request.POST, prefix='event') template_name = 'system/general.html'
if form_event.is_valid():
# event form def get_initial(self):
config['event_name'] = form_event.cleaned_data['event_name'] return {
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={
'event_name': config['event_name'], 'event_name': config['event_name'],
'event_description': config['event_description'], 'event_description': config['event_description'],
'event_date': config['event_date'], 'event_date': config['event_date'],
'event_location': config['event_location'], 'event_location': config['event_location'],
'event_organizer': config['event_organizer'], 'event_organizer': config['event_organizer'],
}, prefix='event')
return {
'form_event': form_event,
} }
@permission_required('system.can_manage_system') def form_valid(self, form):
@template('system/agenda.html') config['event_name'] = form.cleaned_data['event_name']
def get_agenda_config(request): config['event_description'] = form.cleaned_data['event_description']
if request.method == 'POST': config['event_date'] = form.cleaned_data['event_date']
form_agenda = AgendaConfigForm(request.POST, prefix='agenda') config['event_location'] = form.cleaned_data['event_location']
if form_agenda.is_valid(): config['event_organizer'] = form.cleaned_data['event_organizer']
config['agenda_countdown_time'] = form_agenda.cleaned_data['agenda_countdown_time'] messages.success(self.request, _('General settings successfully saved.'))
messages.success(request, _('Agenda settings successfully saved.')) return super(GeneralConfig, self).form_valid(form)
else:
messages.error(request, _('Please check the form for errors.')) def form_invalid(self, form):
else: messages.error(self.request, _('Please check the form for errors.'))
form_agenda = AgendaConfigForm(initial={ return super(Config, self).form_invalid(form)
'agenda_countdown_time': config['agenda_countdown_time'],
}, prefix='agenda')
class Config(FormView):
permission_required = 'system.can_manage_system'
form_class = SystemConfigForm
template_name = 'system/system.html'
def get_initial(self):
return { return {
'form_agenda': form_agenda, 'system_url': config['system_url'],
'system_welcometext': config['system_welcometext'],
'system_enable_anonymous': config['system_enable_anonymous'],
} }
@permission_required('system.can_manage_system') def form_valid(self, form):
@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,
}
@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_url'] = form.cleaned_data['system_url']
config['system_welcometext'] = form.cleaned_data['system_welcometext'] config['system_welcometext'] = form.cleaned_data['system_welcometext']
if form.cleaned_data['system_enable_anonymous']: if form.cleaned_data['system_enable_anonymous']:
@ -146,19 +85,32 @@ def get_system_config(request):
anonymous.save() anonymous.save()
anonymous.permissions = Permission.objects.filter(codename__in=default_perms) anonymous.permissions = Permission.objects.filter(codename__in=default_perms)
anonymous.save() anonymous.save()
messages.success(request, _('Anonymous access enabled. Please modify the "Anonymous" group to fit your required permissions.')) messages.success(self.request, _('Anonymous access enabled. Please modify the "Anonymous" group to fit your required permissions.'))
else: else:
# use '' - False will evaluate to uniced(False) => True.. config['system_enable_anonymous'] = False
config['system_enable_anonymous'] = '' messages.success(self.request, _('System settings successfully saved.'))
messages.success(request, _('System settings successfully saved.')) return super(Config, self).form_valid(form)
else:
messages.error(request, _('Please check the form for errors.'))
else: @receiver(template_manipulation, dispatch_uid="system_base_system")
form = SystemConfigForm(initial={ def set_submenu(sender, request, **kwargs):
'system_url': config['system_url'], selected = True if request.path == reverse('config_general') else False
'system_welcometext': config['system_welcometext'], menu_links = [
'system_enable_anonymous': config['system_enable_anonymous'], (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,
}) })
return {
'form': form,
}

View File

@ -30,7 +30,7 @@ urlpatterns = patterns('',
(r'', include('application.urls')), (r'', include('application.urls')),
(r'', include('participant.urls')), (r'', include('participant.urls')),
(r'', include('assignment.urls')), (r'', include('assignment.urls')),
(r'', include('system.urls')), (r'config/', include('system.urls')),
(r'projector/', include('projector.urls')), (r'projector/', include('projector.urls')),
(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_DOC_ROOT}), (r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_DOC_ROOT}),
(r'^i18n/', include('django.conf.urls.i18n')), (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 reportlab.lib.units import cm
from django.conf import settings 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.http import HttpResponseServerError, HttpResponse
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.template import loader, RequestContext from django.template import loader, RequestContext
from django.template.loader import render_to_string from django.template.loader import render_to_string
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.views.generic import (TemplateView as _TemplateView, from django.views.generic import (
TemplateView as _TemplateView,
RedirectView as _RedirectView, RedirectView as _RedirectView,
UpdateView as _UpdateView, UpdateView as _UpdateView,
CreateView as _CreateView, CreateView as _CreateView,
View,) View,
FormView as _FormView,
)
from django.views.generic.detail import SingleObjectMixin from django.views.generic.detail import SingleObjectMixin
from utils import render_to_forbitten from utils import render_to_forbitten
@ -56,7 +62,6 @@ class PermissionMixin(object):
return super(LoginMixin, self).dispatch(request, *args, **kwargs) return super(LoginMixin, self).dispatch(request, *args, **kwargs)
class TemplateView(_TemplateView, PermissionMixin): class TemplateView(_TemplateView, PermissionMixin):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(TemplateView, self).get_context_data(**kwargs) context = super(TemplateView, self).get_context_data(**kwargs)
@ -91,12 +96,33 @@ class RedirectView(_RedirectView, PermissionMixin):
return {} 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): class UpdateView(_UpdateView, PermissionMixin):
def get_success_url(self): def get_success_url(self):
if 'apply' in self.request.POST: if 'apply' in self.request.POST:
return '' return ''
return reverse(super(UpdateView, self).get_success_url()) 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): class CreateView(_CreateView, PermissionMixin):
def get_success_url(self): def get_success_url(self):