From 2614a1cb2f89e3c9eaabcbefd40cdc409091ab52 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Mon, 11 Mar 2013 20:17:19 +0100 Subject: [PATCH] Categories for Motions --- openslides/motion/models.py | 18 ++++++++++++------ openslides/motion/urls.py | 18 +++++++++++++++++- openslides/motion/views.py | 24 +++++++++++++++++++++++- 3 files changed, 52 insertions(+), 8 deletions(-) diff --git a/openslides/motion/models.py b/openslides/motion/models.py index f8de1544d..2446747c6 100644 --- a/openslides/motion/models.py +++ b/openslides/motion/models.py @@ -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): diff --git a/openslides/motion/urls.py b/openslides/motion/urls.py index a2b6b49e2..06bccb7b2 100644 --- a/openslides/motion/urls.py +++ b/openslides/motion/urls.py @@ -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\d+)/edit/$', + 'category_update', + name='motion_category_update', + ), ) diff --git a/openslides/motion/views.py b/openslides/motion/views.py index da7d27dd4..1e1541d7c 100644 --- a/openslides/motion/views.py +++ b/openslides/motion/views.py @@ -32,7 +32,8 @@ 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) from .pdf import motions_to_pdf, motion_to_pdf @@ -473,6 +474,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'