8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-26 00:43:46 +00:00

GEstion complète des droits - ajout/suppression

This commit is contained in:
Gabriel Detraz 2016-07-02 04:40:24 +02:00
parent a0641aa35d
commit 723ca43fe7
4 changed files with 25 additions and 2 deletions

View file

@ -1,5 +1,6 @@
from django.db import models from django.db import models
from django.forms import ModelForm from django.forms import ModelForm
from django import forms
class User(models.Model): class User(models.Model):
STATE_ACTIVE = 0 STATE_ACTIVE = 0
@ -23,7 +24,7 @@ class User(models.Model):
state = models.IntegerField(choices=STATES, default=STATE_ACTIVE) state = models.IntegerField(choices=STATES, default=STATE_ACTIVE)
def __str__(self): def __str__(self):
return self.name return self.pseudo
class Right(models.Model): class Right(models.Model):
user = models.ForeignKey('User', on_delete=models.PROTECT) user = models.ForeignKey('User', on_delete=models.PROTECT)
@ -32,6 +33,9 @@ class Right(models.Model):
class Meta: class Meta:
unique_together = ("user", "right") unique_together = ("user", "right")
def __str__(self):
return str(self.user) + " - " + str(self.right)
class School(models.Model): class School(models.Model):
name = models.CharField(max_length=255) name = models.CharField(max_length=255)
@ -90,3 +94,10 @@ class RightForm(ModelForm):
class Meta: class Meta:
model = Right model = Right
fields = ['user', 'right'] fields = ['user', 'right']
class DelRightForm(ModelForm):
rights = forms.ModelMultipleChoiceField(queryset=Right.objects.all(), label="Droits actuels", widget=forms.CheckboxSelectMultiple)
class Meta:
model = Right
exclude = ['user', 'right']

View file

@ -3,4 +3,6 @@
{% block sidebar %} {% block sidebar %}
<p><a href="{% url "users:new-user" %}">Créer un adhérent</a></p> <p><a href="{% url "users:new-user" %}">Créer un adhérent</a></p>
<p><a href="{% url "users:index" %}">Liste des adhérents</a></p> <p><a href="{% url "users:index" %}">Liste des adhérents</a></p>
<p><a href="{% url "users:add-right" %}">Ajouter un droit rezo</a></p>
<p><a href="{% url "users:del-right" %}">Retirer un droit rezo</a></p>
{% endblock %} {% endblock %}

View file

@ -8,6 +8,7 @@ urlpatterns = [
url(r'^state/(?P<userid>[0-9]+)$', views.state, name='state'), url(r'^state/(?P<userid>[0-9]+)$', views.state, name='state'),
url(r'^password/(?P<userid>[0-9]+)$', views.password, name='password'), url(r'^password/(?P<userid>[0-9]+)$', views.password, name='password'),
url(r'^add_right/$', views.add_right, name='add-right'), url(r'^add_right/$', views.add_right, name='add-right'),
url(r'^del_right/$', views.del_right, name='del-right'),
url(r'^$', views.index, name='index'), url(r'^$', views.index, name='index'),
] ]

View file

@ -7,7 +7,7 @@ from django.core.context_processors import csrf
from django.template import Context, RequestContext, loader from django.template import Context, RequestContext, loader
from django.contrib import messages from django.contrib import messages
from users.models import User, UserForm, InfoForm, PasswordForm, StateForm, RightForm from users.models import User, Right, DelRightForm, UserForm, InfoForm, PasswordForm, StateForm, RightForm
from users.forms import PassForm from users.forms import PassForm
from re2o.login import makeSecret, hashNT from re2o.login import makeSecret, hashNT
@ -77,6 +77,15 @@ def add_right(request):
return redirect("/users/") return redirect("/users/")
return form({'userform': right}, 'users/user.html', request) return form({'userform': right}, 'users/user.html', request)
def del_right(request):
right = DelRightForm(request.POST or None)
if right.is_valid():
right_del = right.cleaned_data['rights']
right_del.delete()
messages.success(request, "Droit retiré avec succès")
return redirect("/users/")
return form({'userform': right}, 'users/user.html', request)
def index(request): def index(request):
users_list = User.objects.order_by('pk') users_list = User.objects.order_by('pk')
return render(request, 'users/index.html', {'users_list': users_list}) return render(request, 'users/index.html', {'users_list': users_list})