8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-27 07:02:26 +00:00

Redirections une fois une modification effectuée

This commit is contained in:
chirac 2016-07-02 02:42:04 +02:00
parent f22c098ccc
commit f2b2a39091
3 changed files with 46 additions and 9 deletions

View file

@ -1,6 +1,6 @@
from django.contrib import admin from django.contrib import admin
from .models import User, School from .models import User, School, Right, ListRight
class UserAdmin(admin.ModelAdmin): class UserAdmin(admin.ModelAdmin):
list_display = ('name','surname','pseudo','email', 'school', 'state') list_display = ('name','surname','pseudo','email', 'school', 'state')
@ -8,5 +8,13 @@ class UserAdmin(admin.ModelAdmin):
class SchoolAdmin(admin.ModelAdmin): class SchoolAdmin(admin.ModelAdmin):
list_display = ('name',) list_display = ('name',)
class ListRightAdmin(admin.ModelAdmin):
list_display = ('listright',)
class RightAdmin(admin.ModelAdmin):
list_display = ('user', 'right')
admin.site.register(User, UserAdmin) admin.site.register(User, UserAdmin)
admin.site.register(School, SchoolAdmin) admin.site.register(School, SchoolAdmin)
admin.site.register(Right, RightAdmin)
admin.site.register(ListRight, ListRightAdmin)

View file

@ -25,12 +25,25 @@ class User(models.Model):
def __str__(self): def __str__(self):
return self.name return self.name
class Right(models.Model):
user = models.ForeignKey('User', on_delete=models.PROTECT)
right = models.ForeignKey('ListRight', on_delete=models.PROTECT)
class Meta:
unique_together = ("user", "right")
class School(models.Model): class School(models.Model):
name = models.CharField(max_length=255) name = models.CharField(max_length=255)
def __str__(self): def __str__(self):
return self.name return self.name
class ListRight(models.Model):
listright = models.CharField(max_length=255)
def __str__(self):
return self.listright
class UserForm(ModelForm): class UserForm(ModelForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(InfoForm, self).__init__(*args, **kwargs) super(InfoForm, self).__init__(*args, **kwargs)
@ -67,3 +80,13 @@ class SchoolForm(ModelForm):
class Meta: class Meta:
model = School model = School
fields = ['name'] fields = ['name']
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']

View file

@ -18,13 +18,11 @@ def form(ctx, template, request):
return render_to_response(template, c, context_instance=RequestContext(request)) return render_to_response(template, c, context_instance=RequestContext(request))
def new_user(request): def new_user(request):
if request.method == 'POST': user = InfoForm(request.POST or None)
user = InfoForm(request.POST)
if user.is_valid(): if user.is_valid():
user.save() user.save()
return form({'userform': user}, 'users/user.html', request) messages.success(request, "L'utilisateur a été crée")
else: return redirect("/users/")
user = InfoForm()
return form({'userform': user}, 'users/user.html', request) return form({'userform': user}, 'users/user.html', request)
def edit_info(request, userid): def edit_info(request, userid):
@ -36,6 +34,8 @@ def edit_info(request, userid):
user = InfoForm(request.POST or None, instance=user) user = InfoForm(request.POST or None, instance=user)
if user.is_valid(): if user.is_valid():
user.save() user.save()
messages.success(request, "L'user a bien été modifié")
return redirect("/users/")
return form({'userform': user}, 'users/user.html', request) return form({'userform': user}, 'users/user.html', request)
def state(request, userid): def state(request, userid):
@ -47,6 +47,8 @@ def state(request, userid):
user = StateForm(request.POST or None, instance=user) user = StateForm(request.POST or None, instance=user)
if user.is_valid(): if user.is_valid():
user.save() user.save()
messages.success(request, "Etat changé avec succès")
return redirect("/users/")
return form({'userform': user}, 'users/user.html', request) return form({'userform': user}, 'users/user.html', request)
def password(request, userid): def password(request, userid):
@ -63,12 +65,16 @@ def password(request, userid):
user.pwd_ssha = makeSecret(user_form.cleaned_data['passwd1']) user.pwd_ssha = makeSecret(user_form.cleaned_data['passwd1'])
user.pwd_ntlm = hashNT(user_form.cleaned_data['passwd1']) user.pwd_ntlm = hashNT(user_form.cleaned_data['passwd1'])
user.save() user.save()
messages.success(request, "Le mot de passe a changé")
return redirect("/users/")
return form({'userform': user_form}, 'users/user.html', request) return form({'userform': user_form}, 'users/user.html', request)
def add_right(request): def add_right(request):
right = RightForm(request.POST or None) right = RightForm(request.POST or None)
if right.is_valid(): if right.is_valid():
right.save() right.save()
messages.success(request, "Droit ajouté")
return redirect("/users/")
return form({'userform': right}, 'users/user.html', request) return form({'userform': right}, 'users/user.html', request)
def index(request): def index(request):