mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-25 18:44:23 +00:00
Basic user profile edit form
This commit is contained in:
parent
259182c1c4
commit
ebcdcf4245
@ -42,12 +42,19 @@ class LoginForm(AuthenticationForm):
|
|||||||
params={'username': self.username_field.verbose_name},
|
params={'username': self.username_field.verbose_name},
|
||||||
)
|
)
|
||||||
|
|
||||||
class EditUserForm(UserChangeForm):
|
class UserEditForm(UserChangeForm):
|
||||||
error_css_class = 'error'
|
error_css_class = 'error'
|
||||||
required_css_class = 'required'
|
required_css_class = 'required'
|
||||||
class Meta:
|
class Meta:
|
||||||
model = User
|
model = User
|
||||||
fields = ('first_name', 'last_name', 'email', 'date_of_birth', 'groups', 'user_permissions')
|
fields = ('first_name', 'last_name', 'nick_name', 'email', 'date_of_birth', 'groups', 'user_permissions',)
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(UserEditForm, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
def clean_password(self):
|
||||||
|
"""We never handle password in this form"""
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
class PagePropForm(forms.ModelForm):
|
class PagePropForm(forms.ModelForm):
|
||||||
|
@ -65,6 +65,17 @@ class User(AbstractBaseUser, PermissionsMixin):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.username
|
return self.username
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
return self.__dict__
|
||||||
|
|
||||||
|
def get_profile(self):
|
||||||
|
return {
|
||||||
|
"last_name": self.last_name,
|
||||||
|
"first_name": self.first_name,
|
||||||
|
"nick_name": self.nick_name,
|
||||||
|
"date_of_birth": self.date_of_birth,
|
||||||
|
}
|
||||||
|
|
||||||
def get_full_name(self):
|
def get_full_name(self):
|
||||||
"""
|
"""
|
||||||
Returns the first_name plus the last_name, with a space in between.
|
Returns the first_name plus the last_name, with a space in between.
|
||||||
|
@ -17,6 +17,7 @@ User list
|
|||||||
<p><a href="{% url 'core:user_edit' profile.id %}">Edit</a></p>
|
<p><a href="{% url 'core:user_edit' profile.id %}">Edit</a></p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<p>You're seeing the profile of <strong>{{ profile.get_display_name }}</strong></p>
|
<p>You're seeing the profile of <strong>{{ profile.get_display_name }}</strong></p>
|
||||||
|
<p>{{ profile.nick_name }}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if user_list %}
|
{% if user_list %}
|
||||||
|
@ -2,9 +2,10 @@ from django.shortcuts import render, redirect, get_object_or_404
|
|||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.contrib.auth import logout as auth_logout
|
from django.contrib.auth import logout as auth_logout
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.contrib.auth.forms import PasswordChangeForm
|
||||||
|
|
||||||
from .models import User, Page
|
from .models import User, Page
|
||||||
from .forms import RegisteringForm, LoginForm, EditUserForm, PageEditForm, PagePropForm
|
from .forms import RegisteringForm, LoginForm, UserEditForm, PageEditForm, PagePropForm
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -89,8 +90,19 @@ def user_edit(request, user_id=None):
|
|||||||
if user_id is not None:
|
if user_id is not None:
|
||||||
user_id = int(user_id)
|
user_id = int(user_id)
|
||||||
if request.user.is_authenticated() and (request.user.pk == user_id or request.user.is_superuser):
|
if request.user.is_authenticated() and (request.user.pk == user_id or request.user.is_superuser):
|
||||||
context['profile'] = get_object_or_404(User, pk=user_id)
|
p = get_object_or_404(User, pk=user_id)
|
||||||
context['user_form'] = EditUserForm(instance=context['profile']).as_p()
|
if request.method == 'POST':
|
||||||
|
f = UserEditForm(request.POST, instance=p)
|
||||||
|
# Saving user
|
||||||
|
if f.is_valid():
|
||||||
|
f.save()
|
||||||
|
context['tests'] = "USER_SAVED"
|
||||||
|
else:
|
||||||
|
context['tests'] = "USER_NOT_SAVED"
|
||||||
|
else:
|
||||||
|
f = UserEditForm(instance=p)
|
||||||
|
context['profile'] = p
|
||||||
|
context['user_form'] = f.as_p()
|
||||||
return render(request, "core/edit_user.html", context)
|
return render(request, "core/edit_user.html", context)
|
||||||
return user(request, user_id)
|
return user(request, user_id)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user