Skip to content

Commit

Permalink
[ch29134] Admin header: add href to current user
Browse files Browse the repository at this point in the history
  • Loading branch information
emaciupe committed Jun 6, 2022
1 parent be2ffa1 commit 03fccb2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/etools/applications/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import connection, models
from django.db.models.signals import post_save
from django.urls import reverse
from django.utils.functional import cached_property
from django.utils.translation import gettext_lazy as _

Expand Down Expand Up @@ -99,6 +100,10 @@ def get_staff_member_country(self):
return country
return None

def get_admin_url(self):
info = (self._meta.app_label, self._meta.model_name)
return reverse('admin:%s_%s_change' % info, args=(self.pk,))

def save(self, *args, **kwargs):
if self.email != self.email.lower():
raise ValidationError("Email must be lowercase.")
Expand Down
3 changes: 3 additions & 0 deletions src/etools/templates/admin/base_site.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@
<div id="user-tools">
{% block welcome-msg %}
{% trans 'Welcome,' %}
<a href="{{ user.get_admin_url }}">
<strong>{% firstof user.get_short_name user.get_username %}</strong>.
</a>

{% endblock %}
{% block userlinks %}
<a href="{% url 'admin:logout' %}">{% trans 'Log out' %}</a>
Expand Down

0 comments on commit 03fccb2

Please sign in to comment.