mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 14:13:21 +00:00
Basic group view and permissions management on the pages
This commit is contained in:
parent
48e3f88b87
commit
b19ec084b6
@ -1,7 +1,8 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from .models import User, Page
|
from .models import User, Page, Group
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(User)
|
admin.site.register(User)
|
||||||
|
admin.site.register(Group)
|
||||||
admin.site.register(Page)
|
admin.site.register(Page)
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
[{"pk": 1, "model": "auth.group", "fields": {"name": "root", "permissions": [1, 2, 3, 7, 8, 9, 4, 5, 6, 10, 11, 12, 19, 20, 21, 16, 17, 18, 13, 14, 15]}}]
|
[{"fields": {"permissions": [1, 2, 3, 7, 8, 9, 4, 5, 6, 10, 11, 12, 19, 20, 21, 22, 25, 23, 24, 16, 17, 18, 13, 14, 15]}, "pk": 1, "model": "core.group"}]
|
37
core/migrations/0007_auto_20151126_1613.py
Normal file
37
core/migrations/0007_auto_20151126_1613.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('auth', '0006_require_contenttypes_0002'),
|
||||||
|
('core', '0006_auto_20151125_0855'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Group',
|
||||||
|
fields=[
|
||||||
|
('group_ptr', models.OneToOneField(auto_created=True, to='auth.Group', primary_key=True, serialize=False, parent_link=True)),
|
||||||
|
],
|
||||||
|
bases=('auth.group',),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='page',
|
||||||
|
name='edit_group',
|
||||||
|
field=models.ForeignKey(default=1, to='core.Group', related_name='editable_pages'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='page',
|
||||||
|
name='owner_group',
|
||||||
|
field=models.ForeignKey(default=1, to='core.Group', related_name='owned_pages'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='page',
|
||||||
|
name='view_group',
|
||||||
|
field=models.ForeignKey(default=1, to='core.Group', related_name='viewable_pages'),
|
||||||
|
),
|
||||||
|
]
|
@ -1,5 +1,5 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, UserManager, Group
|
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, UserManager, Group as AuthGroup
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.core import validators
|
from django.core import validators
|
||||||
@ -125,6 +125,12 @@ class User(AbstractBaseUser, PermissionsMixin):
|
|||||||
self.username = user_name
|
self.username = user_name
|
||||||
return user_name
|
return user_name
|
||||||
|
|
||||||
|
class Group(AuthGroup):
|
||||||
|
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})
|
||||||
|
|
||||||
class Page(models.Model):
|
class Page(models.Model):
|
||||||
"""
|
"""
|
||||||
@ -227,3 +233,4 @@ class Page(models.Model):
|
|||||||
def get_display_name(self):
|
def get_display_name(self):
|
||||||
return self.get_full_name()
|
return self.get_full_name()
|
||||||
|
|
||||||
|
|
||||||
|
16
core/templates/core/group_edit.html
Normal file
16
core/templates/core/group_edit.html
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{% extends "core/base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<p><a href="{% url 'core:group_list' %}">Back to list</a></p>
|
||||||
|
<h2>Edit group</h2>
|
||||||
|
<form action="" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form.as_p }}
|
||||||
|
<p><input type="submit" value="Update" /></p>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
15
core/templates/core/group_list.html
Normal file
15
core/templates/core/group_list.html
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{% extends "core/base.html" %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
Group list
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h3>Group list</h3>
|
||||||
|
<ul>
|
||||||
|
{% for g in group_list %}
|
||||||
|
<li><a href="{% url 'core:group_edit' g.id %}">{{ g.name }}</a></li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endblock %}
|
||||||
|
|
@ -17,6 +17,9 @@ urlpatterns = [
|
|||||||
url(r'^reset/done/$', password_reset_complete, name='password_reset_complete'),
|
url(r'^reset/done/$', password_reset_complete, name='password_reset_complete'),
|
||||||
url(r'^register$', register, name='register'),
|
url(r'^register$', register, name='register'),
|
||||||
|
|
||||||
|
url(r'^group/$', GroupListView.as_view(), name='group_list'),
|
||||||
|
url(r'^group/(?P<group_id>[0-9]+)/$', GroupEditView.as_view(), name='group_edit'),
|
||||||
|
|
||||||
url(r'^user/$', UserListView.as_view(), name='user_list'),
|
url(r'^user/$', UserListView.as_view(), name='user_list'),
|
||||||
url(r'^user/(?P<user_id>[0-9]+)/$', UserView.as_view(), name='user_profile'),
|
url(r'^user/(?P<user_id>[0-9]+)/$', UserView.as_view(), name='user_profile'),
|
||||||
url(r'^user/(?P<user_id>[0-9]+)/edit$', UserUpdateProfileView.as_view(), name='user_edit'),
|
url(r'^user/(?P<user_id>[0-9]+)/edit$', UserUpdateProfileView.as_view(), name='user_edit'),
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
from .user import *
|
from .user import *
|
||||||
from .page import *
|
from .page import *
|
||||||
from .site import *
|
from .site import *
|
||||||
|
from .group import *
|
||||||
|
@ -4,7 +4,7 @@ from django.contrib.auth import logout, login, authenticate
|
|||||||
from django.forms import CheckboxSelectMultiple
|
from django.forms import CheckboxSelectMultiple
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from core.models import User, Page
|
from core.models import User, Page, Group
|
||||||
|
|
||||||
class RegisteringForm(UserCreationForm):
|
class RegisteringForm(UserCreationForm):
|
||||||
error_css_class = 'error'
|
error_css_class = 'error'
|
||||||
@ -33,3 +33,13 @@ class UserGroupsForm(forms.ModelForm):
|
|||||||
'user_permissions': CheckboxSelectMultiple,
|
'user_permissions': CheckboxSelectMultiple,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class GroupEditForm(forms.ModelForm):
|
||||||
|
error_css_class = 'error'
|
||||||
|
required_css_class = 'required'
|
||||||
|
class Meta:
|
||||||
|
model = Group
|
||||||
|
fields = ['name', 'permissions',]
|
||||||
|
widgets = {
|
||||||
|
'permissions': CheckboxSelectMultiple,
|
||||||
|
}
|
||||||
|
|
||||||
|
19
core/views/group.py
Normal file
19
core/views/group.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
from django.views.generic.edit import UpdateView
|
||||||
|
from django.views.generic import ListView
|
||||||
|
|
||||||
|
from core.models import Group
|
||||||
|
from core.views.forms import GroupEditForm
|
||||||
|
|
||||||
|
class GroupListView(ListView):
|
||||||
|
"""
|
||||||
|
Displays the group list
|
||||||
|
"""
|
||||||
|
model = Group
|
||||||
|
template_name = "core/group_list.html"
|
||||||
|
|
||||||
|
class GroupEditView(UpdateView):
|
||||||
|
model = Group
|
||||||
|
pk_url_kwarg = "group_id"
|
||||||
|
template_name = "core/group_edit.html"
|
||||||
|
form_class = GroupEditForm
|
||||||
|
|
@ -2,6 +2,8 @@
|
|||||||
from django.shortcuts import render, redirect, get_object_or_404
|
from django.shortcuts import render, redirect, get_object_or_404
|
||||||
from django.views.generic import ListView, DetailView
|
from django.views.generic import ListView, DetailView
|
||||||
from django.views.generic.edit import UpdateView
|
from django.views.generic.edit import UpdateView
|
||||||
|
from django.contrib.auth.decorators import login_required, permission_required
|
||||||
|
from django.utils.decorators import method_decorator
|
||||||
|
|
||||||
from core.models import Page
|
from core.models import Page
|
||||||
|
|
||||||
@ -15,6 +17,10 @@ class PageListView(ListView):
|
|||||||
class PageView(DetailView):
|
class PageView(DetailView):
|
||||||
model = Page
|
model = Page
|
||||||
|
|
||||||
|
@method_decorator(permission_required('core.can_view'))
|
||||||
|
def dispatch(self, *args, **kwargs):
|
||||||
|
return super(PageView, self).dispatch(*args, **kwargs)
|
||||||
|
|
||||||
def get_object(self):
|
def get_object(self):
|
||||||
self.page = Page.get_page_by_full_name(self.kwargs['page_name'])
|
self.page = Page.get_page_by_full_name(self.kwargs['page_name'])
|
||||||
return self.page
|
return self.page
|
||||||
|
Loading…
Reference in New Issue
Block a user