Commit e75da927 authored by Skia's avatar Skia
Browse files

Improve group views

parent ac37d332
# -*- 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,
),
]
......@@ -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):
......
......@@ -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 %}
......
......@@ -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'),
......
......@@ -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,
}
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')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment