From e75da927c3f9a37ad5249db7170804627e5216a4 Mon Sep 17 00:00:00 2001 From: Skia Date: Wed, 11 May 2016 17:54:00 +0200 Subject: [PATCH] Improve group views --- core/migrations/0002_group_description.py | 20 ++++++++++++++++++++ core/models.py | 5 ++++- core/templates/core/group_list.jinja | 4 +++- core/urls.py | 2 ++ core/views/forms.py | 11 ----------- core/views/group.py | 15 +++++++++++++-- 6 files changed, 42 insertions(+), 15 deletions(-) create mode 100644 core/migrations/0002_group_description.py diff --git a/core/migrations/0002_group_description.py b/core/migrations/0002_group_description.py new file mode 100644 index 00000000..f81b44da --- /dev/null +++ b/core/migrations/0002_group_description.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='group', + name='description', + field=models.CharField(max_length=60, verbose_name='description', default='guy'), + preserve_default=False, + ), + ] diff --git a/core/models.py b/core/models.py index 72f95af8..7c480e28 100644 --- a/core/models.py +++ b/core/models.py @@ -24,11 +24,12 @@ class Group(AuthGroup): default=False, help_text=_('Whether a group is a meta group or not'), ) + description = models.CharField(_('description'), max_length=60) def get_absolute_url(self): """ This is needed for black magic powered UpdateView's children """ - return reverse('core:group_edit', kwargs={'group_id': self.pk}) + return reverse('core:group_list') class MetaGroup(Group): objects = MetaGroupManager() @@ -148,6 +149,8 @@ class User(AbstractBaseUser, PermissionsMixin): return False else: return False + if group_name == settings.SITH_GROUPS['root']['name'] and self.is_superuser: + return True return self.groups.filter(name=group_name).exists() def get_profile(self): diff --git a/core/templates/core/group_list.jinja b/core/templates/core/group_list.jinja index 7a07aa51..12e5b7d9 100644 --- a/core/templates/core/group_list.jinja +++ b/core/templates/core/group_list.jinja @@ -6,9 +6,11 @@ Group list {% block content %}

Group list

+

New group

{% endblock %} diff --git a/core/urls.py b/core/urls.py index 3dcde1f0..e07609ac 100644 --- a/core/urls.py +++ b/core/urls.py @@ -18,7 +18,9 @@ urlpatterns = [ # Group handling url(r'^group/$', GroupListView.as_view(), name='group_list'), + url(r'^group/new$', GroupCreateView.as_view(), name='group_new'), url(r'^group/(?P[0-9]+)/$', GroupEditView.as_view(), name='group_edit'), + url(r'^group/(?P[0-9]+)/delete$', GroupDeleteView.as_view(), name='group_delete'), # User views url(r'^user/$', UserListView.as_view(), name='user_list'), diff --git a/core/views/forms.py b/core/views/forms.py index db1428da..2f0ab6d8 100644 --- a/core/views/forms.py +++ b/core/views/forms.py @@ -60,14 +60,3 @@ class PagePropForm(forms.ModelForm): self.fields['edit_groups'].required = False self.fields['view_groups'].required = False - -class GroupEditForm(forms.ModelForm): - error_css_class = 'error' - required_css_class = 'required' - class Meta: - model = RealGroup - fields = ['name', 'permissions',] - widgets = { - 'permissions': CheckboxSelectMultiple, - } - diff --git a/core/views/group.py b/core/views/group.py index 172b5791..e228f073 100644 --- a/core/views/group.py +++ b/core/views/group.py @@ -1,5 +1,6 @@ -from django.views.generic.edit import UpdateView +from django.views.generic.edit import UpdateView, CreateView, DeleteView from django.views.generic import ListView +from django.core.urlresolvers import reverse_lazy from core.models import RealGroup from core.views.forms import GroupEditForm @@ -16,5 +17,15 @@ class GroupEditView(CanEditMixin, UpdateView): model = RealGroup pk_url_kwarg = "group_id" template_name = "core/group_edit.jinja" - form_class = GroupEditForm + fields = ['name', 'description'] +class GroupCreateView(CanEditMixin, CreateView): + model = RealGroup + template_name = "core/group_edit.jinja" + fields = ['name', 'description'] + +class GroupDeleteView(CanEditMixin, DeleteView): + model = RealGroup + pk_url_kwarg = "group_id" + template_name = "core/delete_confirm.jinja" + success_url = reverse_lazy('core:group_list')