Skip to content

Commit b1303ac

Browse files
committed
Add gravatar to admin, use app name in toolbar back button
1 parent 762c092 commit b1303ac

File tree

5 files changed

+31
-6
lines changed

5 files changed

+31
-6
lines changed

plain-admin/plain/admin/templates.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def get_context(self, context, *args, **kwargs):
1717
else:
1818
cls = settings.ADMIN_TOOLBAR_CLASS
1919
context.vars["toolbar"] = cls(request=context["request"])
20+
context.vars["app_name"] = settings.APP_NAME
2021
return context
2122

2223

plain-admin/plain/admin/templates/admin/base.html

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,24 @@
166166
<div class="mt-8 flex flex-col text-sm pb-3 pt-3 text-stone-400 sticky bottom-0 bg-stone-950/95 pl-3.5 pr-5">
167167
<div class="flex items-center justify-between space-x-1.5">
168168
<div class="flex items-center truncate">
169-
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="w-4 h-4 mr-1.5 flex-shrink-0 bi bi-person-circle" viewBox="0 0 16 16">
170-
<path d="M11 6a3 3 0 1 1-6 0 3 3 0 0 1 6 0z"/>
171-
<path fill-rule="evenodd" d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8zm8-7a7 7 0 0 0-5.468 11.37C3.242 11.226 4.805 10 8 10s4.757 1.225 5.468 2.37A7 7 0 0 0 8 1z"/>
172-
</svg>
169+
{% set gravatar_url = get_gravatar_url(request.user) %}
170+
{% if gravatar_url %}
171+
<img
172+
src="{{ gravatar_url }}"
173+
alt="{{ request.user }}"
174+
class="w-5 h-5 mr-1.5 flex-shrink-0 rounded-full"
175+
/>
176+
{% else %}
177+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="w-4 h-4 mr-1.5 flex-shrink-0 bi bi-person-circle" viewBox="0 0 16 16">
178+
<path d="M11 6a3 3 0 1 1-6 0 3 3 0 0 1 6 0z"/>
179+
<path fill-rule="evenodd" d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8zm8-7a7 7 0 0 0-5.468 11.37C3.242 11.226 4.805 10 8 10s4.757 1.225 5.468 2.37A7 7 0 0 0 8 1z"/>
180+
</svg>
181+
{% endif %}
173182
<span class="truncate">
174183
{{ request.user }}
175184
</span>
176185
</div>
177-
<form method="POST" action="{{ url('logout') }}" class="flex items-center flex-shrink-0">
186+
<form method="POST" action="{{ url('logout') }}" class="flex items-center flex-shrink-0 ml-2">
178187
<button type="submit" class="hover:text-white flex items-center" title="Log out">
179188
<admin.Icon name="box-arrow-right" />
180189
</button>

plain-admin/plain/admin/templates/toolbar/toolbar.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
{% endfor %}
6868

6969
{% if is_admin_view|default(false) %}
70-
<a href="/" class="hover:underline">Back to app</a>
70+
<a href="/" class="hover:underline">Back to {{ app_name }}</a>
7171
{% else %}
7272
<a href="{{ url('admin:index') }}" class="hover:underline">Admin</a>
7373
{% endif %}

plain-admin/plain/admin/utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import hashlib
2+
3+
4+
def get_gravatar_url(user):
5+
"""Generate gravatar URL for the given user if they have an email address."""
6+
if not user or not hasattr(user, "email") or not user.email:
7+
return None
8+
9+
# Create hash of email
10+
email_hash = hashlib.md5(user.email.lower().strip().encode("utf-8")).hexdigest()
11+
12+
# Return gravatar URL with default identicon fallback
13+
return f"https://www.gravatar.com/avatar/{email_hash}?s=64&d=identicon"

plain-admin/plain/admin/views/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
TemplateView,
99
)
1010

11+
from ..utils import get_gravatar_url
1112
from .registry import registry
1213
from .types import Img
1314

@@ -62,6 +63,7 @@ def get_template_context(self):
6263
context["is_admin_view"] = True
6364
context["view_class"] = self.__class__
6465
context["app_name"] = settings.APP_NAME
66+
context["get_gravatar_url"] = get_gravatar_url
6567
return context
6668

6769
@classmethod

0 commit comments

Comments
 (0)