Improve group views

This commit is contained in:
Skia 2016-05-11 17:54:00 +02:00
parent ac37d3328c
commit e75da927c3
6 changed files with 42 additions and 15 deletions

View File

@ -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,
),
]

View File

@ -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):

View File

@ -6,9 +6,11 @@ Group list
{% block content %}
<h3>Group list</h3>
<p><a href="{{ url('core:group_new') }}">New group</a></p>
<ul>
{% for g in realgroup_list %}
<li><a href="{{ url('core:group_edit', group_id=g.id) }}">{{ g.name }}</a></li>
<li><a href="{{ url('core:group_edit', group_id=g.id) }}">{{ g.name }}</a> - {{ g.description }} -
<a href="{{ url('core:group_delete', group_id=g.id) }}">Delete</a></li>
{% endfor %}
</ul>
{% endblock %}

View File

@ -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<group_id>[0-9]+)/$', GroupEditView.as_view(), name='group_edit'),
url(r'^group/(?P<group_id>[0-9]+)/delete$', GroupDeleteView.as_view(), name='group_delete'),
# User views
url(r'^user/$', UserListView.as_view(), name='user_list'),

View File

@ -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,
}

View File

@ -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')