mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 06:03:20 +00:00
Improve group views
This commit is contained in:
parent
ac37d3328c
commit
e75da927c3
20
core/migrations/0002_group_description.py
Normal file
20
core/migrations/0002_group_description.py
Normal 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,
|
||||||
|
),
|
||||||
|
]
|
@ -24,11 +24,12 @@ class Group(AuthGroup):
|
|||||||
default=False,
|
default=False,
|
||||||
help_text=_('Whether a group is a meta group or not'),
|
help_text=_('Whether a group is a meta group or not'),
|
||||||
)
|
)
|
||||||
|
description = models.CharField(_('description'), max_length=60)
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
"""
|
"""
|
||||||
This is needed for black magic powered UpdateView's children
|
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):
|
class MetaGroup(Group):
|
||||||
objects = MetaGroupManager()
|
objects = MetaGroupManager()
|
||||||
@ -148,6 +149,8 @@ class User(AbstractBaseUser, PermissionsMixin):
|
|||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
if group_name == settings.SITH_GROUPS['root']['name'] and self.is_superuser:
|
||||||
|
return True
|
||||||
return self.groups.filter(name=group_name).exists()
|
return self.groups.filter(name=group_name).exists()
|
||||||
|
|
||||||
def get_profile(self):
|
def get_profile(self):
|
||||||
|
@ -6,9 +6,11 @@ Group list
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h3>Group list</h3>
|
<h3>Group list</h3>
|
||||||
|
<p><a href="{{ url('core:group_new') }}">New group</a></p>
|
||||||
<ul>
|
<ul>
|
||||||
{% for g in realgroup_list %}
|
{% 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 %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -18,7 +18,9 @@ urlpatterns = [
|
|||||||
|
|
||||||
# Group handling
|
# Group handling
|
||||||
url(r'^group/$', GroupListView.as_view(), name='group_list'),
|
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]+)/$', GroupEditView.as_view(), name='group_edit'),
|
||||||
|
url(r'^group/(?P<group_id>[0-9]+)/delete$', GroupDeleteView.as_view(), name='group_delete'),
|
||||||
|
|
||||||
# User views
|
# User views
|
||||||
url(r'^user/$', UserListView.as_view(), name='user_list'),
|
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['edit_groups'].required = False
|
||||||
self.fields['view_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,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -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.views.generic import ListView
|
||||||
|
from django.core.urlresolvers import reverse_lazy
|
||||||
|
|
||||||
from core.models import RealGroup
|
from core.models import RealGroup
|
||||||
from core.views.forms import GroupEditForm
|
from core.views.forms import GroupEditForm
|
||||||
@ -16,5 +17,15 @@ class GroupEditView(CanEditMixin, UpdateView):
|
|||||||
model = RealGroup
|
model = RealGroup
|
||||||
pk_url_kwarg = "group_id"
|
pk_url_kwarg = "group_id"
|
||||||
template_name = "core/group_edit.jinja"
|
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')
|
||||||
|
Loading…
Reference in New Issue
Block a user