Add display name (first_name) shown instead of username on user-facing UI
All checks were successful
Docker / build (release) Successful in 9s
All checks were successful
Docker / build (release) Successful in 9s
This commit is contained in:
parent
28f279a4ab
commit
4e23d45472
4 changed files with 20 additions and 3 deletions
|
|
@ -29,6 +29,11 @@ def sync_user_fields(sender, request, sociallogin, **kwargs):
|
||||||
user.username = username
|
user.username = username
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
|
display_name = data.get("name") or data.get("preferred_username")
|
||||||
|
if display_name and user.first_name != display_name:
|
||||||
|
user.first_name = display_name
|
||||||
|
changed = True
|
||||||
|
|
||||||
staff_groups = settings.OAUTH_STAFF_GROUPS
|
staff_groups = settings.OAUTH_STAFF_GROUPS
|
||||||
if staff_groups:
|
if staff_groups:
|
||||||
oauth_groups = set(data.get("groups", []))
|
oauth_groups = set(data.get("groups", []))
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,12 @@ from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
|
||||||
class CustomSignupForm(SignupForm):
|
class CustomSignupForm(SignupForm):
|
||||||
|
first_name = forms.CharField(
|
||||||
|
label=_("Display name"),
|
||||||
|
max_length=150,
|
||||||
|
required=True,
|
||||||
|
)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
|
@ -16,6 +22,12 @@ class CustomSignupForm(SignupForm):
|
||||||
"Please enter a valid email address ending with `@ens-rennes.fr`"
|
"Please enter a valid email address ending with `@ens-rennes.fr`"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def save(self, request):
|
||||||
|
user = super().save(request)
|
||||||
|
user.first_name = self.cleaned_data["first_name"]
|
||||||
|
user.save()
|
||||||
|
return user
|
||||||
|
|
||||||
def clean_email(self):
|
def clean_email(self):
|
||||||
"""
|
"""
|
||||||
Check that the email address ends with a trusted domain.
|
Check that the email address ends with a trusted domain.
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
<footer>
|
<footer>
|
||||||
<p class="small text-center text-muted mt-1">
|
<p class="small text-center text-muted mt-1">
|
||||||
{% if request.user.is_authenticated %}
|
{% if request.user.is_authenticated %}
|
||||||
{% trans "Connected as" %} <code>{{ request.user.username }}</code> ·
|
{% trans "Connected as" %} <code>{{ request.user.first_name|default:request.user.username }}</code> ·
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<a class="text-reset" href="https://git.sinfonie.org/sinfonie/photo26">{% trans "Source code" %}</a>
|
<a class="text-reset" href="https://git.sinfonie.org/sinfonie/photo26">{% trans "Source code" %}</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
{% url 'photologue:pl-gallery-owner' slug=gallery.slug owner=owner.id as url %}
|
{% url 'photologue:pl-gallery-owner' slug=gallery.slug owner=owner.id as url %}
|
||||||
<a class="nav-link {% if request.path_info == url %}active{% endif %}" href="{{ url }}">
|
<a class="nav-link {% if request.path_info == url %}active{% endif %}" href="{{ url }}">
|
||||||
{% if owner.get_full_name %}{{ owner.get_full_name }}{% else %}{{ owner.username }}{% endif %}
|
{{ owner.first_name|default:owner.username }}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
@ -114,7 +114,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
data-height="{{ item.thumbnail_height|default:1 }}">
|
data-height="{{ item.thumbnail_height|default:1 }}">
|
||||||
<img src="{{ item.get_thumbnail_url }}" data-lazy="{{ item.get_thumbnail_url }}"
|
<img src="{{ item.get_thumbnail_url }}" data-lazy="{{ item.get_thumbnail_url }}"
|
||||||
class="{% if not item.is_public %}photo-private{% endif %}"
|
class="{% if not item.is_public %}photo-private{% endif %}"
|
||||||
alt="{{ item.title }}{% if not item.is_video and item.date_taken %} - {{ item.date_taken|date }} {{ item.date_taken|time }}{% endif %}{% if item.owner.get_full_name %} - {{ item.owner.get_full_name }}{% else %} - {{ item.owner.username }}{% endif %}{% if not item.is_video and item.license %} - {{ item.license }}{% endif %}{% if not item.is_public %} - !PRIVATE!{% endif %}">
|
alt="{{ item.title }}{% if not item.is_video and item.date_taken %} - {{ item.date_taken|date }} {{ item.date_taken|time }}{% endif %} - {{ item.owner.first_name|default:item.owner.username }}{% if not item.is_video and item.license %} - {{ item.license }}{% endif %}{% if not item.is_public %} - !PRIVATE!{% endif %}">
|
||||||
</a>
|
</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue