mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-28 18:03:45 +00:00
Modifie la gestion des droits, depuis le profil maintenant
This commit is contained in:
parent
c9ca21fdd9
commit
073d56a18a
5 changed files with 25 additions and 8 deletions
|
@ -131,12 +131,11 @@ class SchoolForm(ModelForm):
|
|||
class RightForm(ModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(RightForm, self).__init__(*args, **kwargs)
|
||||
self.fields['user'].label = 'Utilisateur'
|
||||
self.fields['right'].label = 'Droit'
|
||||
|
||||
class Meta:
|
||||
model = Right
|
||||
fields = ['user', 'right']
|
||||
fields = ['right']
|
||||
|
||||
class DelRightForm(ModelForm):
|
||||
rights = forms.ModelMultipleChoiceField(queryset=Right.objects.all(), label="Droits actuels", widget=forms.CheckboxSelectMultiple)
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
<a class="btn btn-primary btn-sm" role="button" href="{% url 'users:edit-info' user.id %}"><i class="glyphicon glyphicon-fire"></i> Editer</a>
|
||||
<a class="btn btn-primary btn-sm" role="button" href="{% url 'users:password' user.id %}"><i class="glyphicon glyphicon-lock"></i> Changer le mot de passe</a>
|
||||
<a class="btn btn-primary btn-sm" role="button" href="{% url 'users:state' user.id %}"><i class="glyphicon glyphicon-flash"></i> Changer le statut</a>
|
||||
<a class="btn btn-primary btn-sm" role="button" href="{% url 'users:add-right' user.id %}"><i class="glyphicon glyphicon-ok"></i> Ajouter un droit</a>
|
||||
<br />
|
||||
<br />
|
||||
<table class="table table-striped">
|
||||
|
@ -71,6 +72,12 @@
|
|||
{% else %}
|
||||
<td><font color="red">Désactivée</font></td>
|
||||
{% endif %}
|
||||
<th>Droits</th>
|
||||
{% if list_droits %}
|
||||
<td>{% for droit in list_droits %}{{ droit.right }} - {% endfor %}</td>
|
||||
{% else %}
|
||||
<td>Aucun</td>
|
||||
{% endif %}
|
||||
</table>
|
||||
<h2>Machines :</h2>
|
||||
<h4><a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:new-machine' user.id %}"><i class="glyphicon glyphicon-phone"></i> Ajouter une machine</a></h4>
|
||||
|
|
|
@ -6,6 +6,5 @@
|
|||
<p><a href="{% url "users:index" %}">Liste des adhérents</a></p>
|
||||
<p><a href="{% url "search:search" %}">Ajouter un bannissement</a></p>
|
||||
<p><a href="{% url "search:search" %}">Gérer les bannissements</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 %}
|
||||
|
|
|
@ -11,7 +11,7 @@ urlpatterns = [
|
|||
url(r'^edit_ban/(?P<banid>[0-9]+)$', views.edit_ban, name='edit-ban'),
|
||||
url(r'^add_whitelist/(?P<userid>[0-9]+)$', views.add_whitelist, name='add-whitelist'),
|
||||
url(r'^edit_whitelist/(?P<whitelistid>[0-9]+)$', views.edit_whitelist, name='edit-whitelist'),
|
||||
url(r'^add_right/$', views.add_right, name='add-right'),
|
||||
url(r'^add_right/(?P<userid>[0-9]+)$', views.add_right, name='add-right'),
|
||||
url(r'^del_right/$', views.del_right, name='del-right'),
|
||||
url(r'^profil/$', views.profil, name='profil'),
|
||||
url(r'^$', views.index, name='index'),
|
||||
|
|
|
@ -7,6 +7,7 @@ from django.core.context_processors import csrf
|
|||
from django.template import Context, RequestContext, loader
|
||||
from django.contrib import messages
|
||||
from django.db.models import Max
|
||||
from django.db import IntegrityError
|
||||
from django.utils import timezone
|
||||
|
||||
from users.models import User, Right, Ban, DelRightForm, UserForm, InfoForm, PasswordForm, StateForm, RightForm, BanForm, ProfilForm, Whitelist, WhitelistForm
|
||||
|
@ -128,11 +129,21 @@ def password(request, userid):
|
|||
return redirect("/users/")
|
||||
return form({'userform': user_form}, 'users/user.html', request)
|
||||
|
||||
def add_right(request):
|
||||
def add_right(request, userid):
|
||||
try:
|
||||
user = User.objects.get(pk=userid)
|
||||
except User.DoesNotExist:
|
||||
messages.error(request, u"Utilisateur inexistant" )
|
||||
return redirect("/users/")
|
||||
right = RightForm(request.POST or None)
|
||||
if right.is_valid():
|
||||
right.save()
|
||||
messages.success(request, "Droit ajouté")
|
||||
right = right.save(commit=False)
|
||||
right.user = user
|
||||
try:
|
||||
right.save()
|
||||
messages.success(request, "Droit ajouté")
|
||||
except IntegrityError:
|
||||
pass
|
||||
return redirect("/users/")
|
||||
return form({'userform': right}, 'users/user.html', request)
|
||||
|
||||
|
@ -226,7 +237,8 @@ def profil(request):
|
|||
end_bans=end_ban(users)
|
||||
if(is_whitelisted(users)):
|
||||
end_whitelists=end_whitelist(users)
|
||||
return render(request, 'users/profil.html', {'user': users, 'machine_list' :machines, 'facture_list':factures, 'ban_list':bans, 'white_list':whitelists,'end_ban':end_bans,'end_whitelist':end_whitelists, 'end_adhesion':end_adhesion(users), 'actif':has_access(users)})
|
||||
list_droits = Right.objects.filter(user=users)
|
||||
return render(request, 'users/profil.html', {'user': users, 'machine_list' :machines, 'facture_list':factures, 'ban_list':bans, 'white_list':whitelists,'end_ban':end_bans,'end_whitelist':end_whitelists, 'end_adhesion':end_adhesion(users), 'actif':has_access(users), 'list_droits': list_droits})
|
||||
return redirect("/users/")
|
||||
return redirect("/users/")
|
||||
|
||||
|
|
Loading…
Reference in a new issue