Merge pull request #1 from ostcar/category

Category
This commit is contained in:
Emanuel Schütze 2013-03-11 12:46:42 -07:00
commit ff848a865a
6 changed files with 110 additions and 10 deletions

View File

@ -15,7 +15,7 @@ from django.utils.translation import ugettext as _
from openslides.utils.forms import CssClassMixin
from openslides.utils.person import PersonFormField, MultiplePersonFormField
from .models import Motion, Workflow
from .models import Motion, Workflow, Category
class BaseMotionForm(forms.ModelForm, CssClassMixin):
@ -90,6 +90,12 @@ class MotionDisableVersioningMixin(forms.ModelForm):
last_version will be used."""
class MotionCategoryMixin(forms.ModelForm):
"""Mixin to let the user choose the category for the motion."""
category = forms.ModelChoiceField(queryset=Category.objects.all(), required=False)
class ConfigForm(CssClassMixin, forms.Form):
"""Form for the configuration tab of OpenSlides."""
motion_min_supporters = forms.IntegerField(

View File

@ -65,7 +65,9 @@ class Motion(SlideMixin, models.Model):
unique=True)
"""A string as human readable identifier for the motion."""
# category = models.ForeignKey('Category', null=True, blank=True)
category = models.ForeignKey('Category', null=True, blank=True)
"""ForeignKey to one category of motions."""
# TODO: proposal
#master = models.ForeignKey('self', null=True, blank=True)
@ -523,12 +525,16 @@ class MotionSupporter(models.Model):
return unicode(self.person)
## class Category(models.Model):
## name = models.CharField(max_length=255, verbose_name=ugettext_lazy("Category name"))
## prefix = models.CharField(max_length=32, verbose_name=ugettext_lazy("Category prefix"))
class Category(models.Model):
name = models.CharField(max_length=255, verbose_name=ugettext_lazy("Category name"))
prefix = models.CharField(max_length=32, verbose_name=ugettext_lazy("Category prefix"))
## def __unicode__(self):
## return self.name
def __unicode__(self):
return self.name
def get_absolute_url(self, link='update'):
if link == 'update' or link == 'edit':
return reverse('motion_category_update', args=[str(self.id)])
## class Comment(models.Model):

View File

@ -0,0 +1,33 @@
{% extends "base.html" %}
{% load tags %}
{% load i18n %}
{% block title %}
{{ block.super }}
{% if motion %}
{% trans "Edit category" %}
{% else %}
{% trans "New category" %}
{% endif %}
{% endblock %}
{% block content %}
<h1>
{% if motion %}
{% trans "Edit category" %}
{% else %}
{% trans "New category" %}
{% endif %}
</h1>
<form action="" method="post">{% csrf_token %}
{% include "form.html" %}
<p>
{% include "formbuttons_saveapply.html" %}
<a href='{% url 'motion_list' %}' class="btn">
{% trans 'Cancel' %}
</a>
</p>
<small>* {% trans "required" %}</small>
</form>
{% endblock %}

View File

@ -0,0 +1,16 @@
{% extends "base.html" %}
{% load tags %}
{% load i18n %}
{% block title %}{{ block.super }} {% trans "Motions" %}{% endblock %}
{% block content %}
<h1>{% trans "Categories" %}</h1>
{% for category in category_list %}
<p><a href="{% model_url category 'update' %}">{{ category }}</a></p>
{% empty %}
<p>No Categories</p>
{% endfor %}
</table>
{% endblock %}

View File

@ -19,8 +19,9 @@ urlpatterns = patterns('openslides.motion.views',
name='motion_list',
),
url(r'^create/$',
url(r'^new/$',
'motion_create',
# TODO: rename to motion_create
name='motion_new',
),
@ -103,4 +104,19 @@ urlpatterns = patterns('openslides.motion.views',
'motion_detail_pdf',
name='motion_detail_pdf',
),
url(r'^category/$',
'category_list',
name='motion_category_list',
),
url(r'^category/new/$',
'category_create',
name='motion_category_create',
),
url(r'^category/(?P<pk>\d+)/edit/$',
'category_update',
name='motion_category_update',
),
)

View File

@ -32,9 +32,10 @@ from openslides.projector.projector import Widget, SLIDE
from openslides.config.models import config
from openslides.agenda.models import Item
from .models import Motion, MotionSubmitter, MotionSupporter, MotionPoll, MotionVersion, State, WorkflowError
from .models import (Motion, MotionSubmitter, MotionSupporter, MotionPoll,
MotionVersion, State, WorkflowError, Category)
from .forms import (BaseMotionForm, MotionSubmitterMixin, MotionSupporterMixin,
MotionDisableVersioningMixin, ConfigForm)
MotionDisableVersioningMixin, ConfigForm, MotionCategoryMixin)
from .pdf import motions_to_pdf, motion_to_pdf
@ -123,6 +124,7 @@ class MotionMixin(object):
form_classes = [BaseMotionForm]
if self.request.user.has_perm('motion.can_manage_motion'):
form_classes.append(MotionSubmitterMixin)
form_classes.append(MotionCategoryMixin)
if config['motion_min_supporters'] > 0:
form_classes.append(MotionSupporterMixin)
if self.object:
@ -467,6 +469,27 @@ motion_list_pdf = MotionPDFView.as_view(print_all_motions=True)
motion_detail_pdf = MotionPDFView.as_view(print_all_motions=False)
class CategoryListView(ListView):
permission_required = 'motion.can_manage_motion'
model = Category
category_list = CategoryListView.as_view()
class CategoryCreateView(CreateView):
permission_required = 'motion.can_manage_motion'
model = Category
category_create = CategoryCreateView.as_view()
class CategoryUpdateView(UpdateView):
permission_required = 'motion.can_manage_motion'
model = Category
category_update = CategoryUpdateView.as_view()
class Config(FormView):
"""The View for the config tab."""
permission_required = 'config.can_manage_config'