Allow user change fullname
This commit is contained in:
parent
7fafe394c5
commit
81a490ca93
4 changed files with 302 additions and 285 deletions
|
@ -3,6 +3,7 @@ from operator import attrgetter
|
|||
import pyotp
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.forms import AuthenticationForm
|
||||
from django.core.exceptions import ValidationError, ObjectDoesNotExist
|
||||
from django.core.validators import RegexValidator
|
||||
|
@ -51,6 +52,12 @@ def fix_unicode(string, unsafe=tuple("\u202a\u202b\u202d\u202e")):
|
|||
string + (sum(k in unsafe for k in string) - string.count("\u202c")) * "\u202c"
|
||||
)
|
||||
|
||||
class UserForm(ModelForm):
|
||||
class Meta:
|
||||
model = User
|
||||
fields = [
|
||||
"first_name",
|
||||
]
|
||||
|
||||
class ProfileForm(ModelForm):
|
||||
if newsletter_id is not None:
|
||||
|
|
|
@ -34,7 +34,7 @@ from django.views.generic import DetailView, ListView, TemplateView
|
|||
from django.template.loader import render_to_string
|
||||
from reversion import revisions
|
||||
|
||||
from judge.forms import ProfileForm, newsletter_id
|
||||
from judge.forms import UserForm, ProfileForm, newsletter_id
|
||||
from judge.models import Profile, Rating, Submission, Friend
|
||||
from judge.performance_points import get_pp_breakdown
|
||||
from judge.ratings import rating_class, rating_progress
|
||||
|
@ -384,9 +384,11 @@ def edit_profile(request):
|
|||
if profile.mute:
|
||||
raise Http404()
|
||||
if request.method == "POST":
|
||||
form_user = UserForm(request.POST, instance=request.user)
|
||||
form = ProfileForm(request.POST, instance=profile, user=request.user)
|
||||
if form.is_valid():
|
||||
if form_user.is_valid() and form.is_valid():
|
||||
with transaction.atomic(), revisions.create_revision():
|
||||
form_user.save()
|
||||
form.save()
|
||||
revisions.set_user(request.user)
|
||||
revisions.set_comment(_("Updated on site"))
|
||||
|
@ -422,6 +424,7 @@ def edit_profile(request):
|
|||
|
||||
return HttpResponseRedirect(request.path)
|
||||
else:
|
||||
form_user = UserForm(instance=request.user)
|
||||
form = ProfileForm(instance=profile, user=request.user)
|
||||
if newsletter_id is not None:
|
||||
try:
|
||||
|
@ -441,7 +444,7 @@ def edit_profile(request):
|
|||
"user/edit-profile.html",
|
||||
{
|
||||
"edit_name_url": settings.REGISTER_NAME_URL,
|
||||
"require_staff_2fa": settings.DMOJ_REQUIRE_STAFF_2FA,
|
||||
"require_staff_2fa": settings.DMOJ_REQUIRE_STAFF_2FA, 'form_user': form_user,
|
||||
"form": form,
|
||||
"title": _("Edit profile"),
|
||||
"profile": profile,
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -104,6 +104,12 @@
|
|||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="block-header" style="display:flex;">
|
||||
<div style="margin: auto 0;"> {{ _('Fullname') }}: </div>
|
||||
<div style="margin-left: 30px;"> {{ form_user.first_name }} </div>
|
||||
</div>
|
||||
<hr>
|
||||
|
||||
<div style="padding-top:0.5em" class="block-header">{{ _('Self-description') }}:</div>
|
||||
{{ form.about }}
|
||||
<hr>
|
||||
|
|
Loading…
Reference in a new issue