Merge pull request #24 from LQDJudge/features/allow-change-fullname

Allow user change fullname
This commit is contained in:
Phuoc Dinh Le 2022-10-15 12:05:48 -05:00 committed by GitHub
commit af74edecbb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 312 additions and 295 deletions

View file

@ -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:

View file

@ -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

View file

@ -108,7 +108,6 @@ body {
position: relative;
min-height: 100%;
margin: 0 auto;
max-width: 107em;
font-size: $base_font_size;
line-height: 1.231;
background: $background_light_gray;
@ -322,6 +321,7 @@ nav {
&:first-child {
a.active {
border-top: 1px solid $widget_black;
background-color: darkcyan !important;
}
}
}
@ -477,7 +477,6 @@ noscript #noscript {
#nav-placeholder {
height: 47px;
max-width: 107em;
background: white;
border-right: 1px solid $border_gray;
border-left: 1px solid $border_gray;

View file

@ -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>

View file

@ -7,12 +7,12 @@
.user-gravatar {
display: block;
padding-right: 15px;
width: 135px;
width: 145px;
}
.user-gravatar img {
width: 135px;
height: 135px;
width: 145px;
height: 145px;
display: block;
border-radius: 6px;
}
@ -62,10 +62,11 @@
.user-stat {
text-align: right;
font-weight: bold;
margin-right: 0.5em;
}
.user-stat-container {
display: flex;
justify-content: space-between;
margin-bottom: 0.5em;
}
@ -89,13 +90,13 @@
<div class="user-info-page">
<div class="user-sidebar">
<div class="user-gravatar">
<img src="{{ gravatar(user, 135) }}" width="135px" height="135px">
<img src="{{ gravatar(user, 145) }}" width="145px" height="145px">
</div>
<br>
{% if request.user != user.user %}
<form method="post">
{% csrf_token %}
<button class="small {{ 'unfollow' if followed else 'follow' }}" style="width:135px">
<button class="small {{ 'unfollow' if followed else 'follow' }}" style="width:145px">
{% if followed %}
<i class="fa fa-remove"></i>
{{ _('Unfollow') }}
@ -109,7 +110,7 @@
<br>
<div>
<form action="{{ url('all_user_submissions', user.user.username) }}">
<input type="submit" value="{{ _('View submissions') }}" class="small" style="width:135px; padding-left: 1px; padding-right: 1px">
<input type="submit" value="{{ _('View submissions') }}" class="small" style="width:145px; padding-left: 1px; padding-right: 1px">
</form>
</div>
{% if request.user.is_authenticated %}
@ -118,7 +119,7 @@
<form action="{{ url('get_or_create_room') }}" method="POST">
{% csrf_token %}
<input type="hidden" value="{{ chat_param(request.profile, user) }}" name="other">
<input type="submit" value="{{ _('Send message') }}" style="width:135px" class="small btn-midnightblue">
<input type="submit" value="{{ _('Send message') }}" style="width:145px" class="small btn-midnightblue">
</form>
</div>
{% endif %}