Added support for profile pictures

This commit is contained in:
Julian Müller 2022-08-06 18:56:39 +02:00
parent f5bf77fbed
commit ca160781dd
7 changed files with 88 additions and 35 deletions

View file

@ -45,10 +45,13 @@ class CustomUserAdmin(UserAdmin):
fieldsets_ = list((*UserAdmin.fieldsets,))
fieldsets_.insert(1, (
"Balance",
{"fields": ("balance", "allow_order_with_negative_balance")},
)
)
"Balance",
{"fields": ("balance", "allow_order_with_negative_balance")},
))
fieldsets_.insert(2, (
"Profile Picture",
{"fields": ("profile_picture_filename",)},
))
fieldsets = tuple(fieldsets_)
list_display = ["username", "balance", "is_active", "allow_order_with_negative_balance"]

View file

@ -20,6 +20,7 @@ class User(AbstractUser):
balance = models.DecimalField(max_digits=8, decimal_places=2, default=0.00)
allow_order_with_negative_balance = models.BooleanField(default=False)
profile_picture_filename = models.CharField(default="default.svg", max_length=25)
def delete(self, *args, **kwargs):
self.balance = 0

View file

@ -2,6 +2,7 @@
{% extends "baseLayout.html" %}
{% load i18n %}
{% load static %}
{% block title %}
{% translate "Drinks - Login" %}
@ -68,19 +69,20 @@
<ul class="userlist">
{% for user_ in user_list %}
<li class="userlistButton button" data-username="{{ user_.username }}">
{% if user_.first_name %}
<img src="{% static 'profilepictures/'|add:user_.profile_picture_filename %}">
<div>
{% if user_.first_name %}
{% if user_.last_name %}
{{ user_.last_name }},
{% if user_.last_name %}
{{ user_.last_name }},
{% endif %}
{{ user_.first_name }}
{% else %}
{{ user_.username }}
{% endif %}
{{ user_.first_name }}
{% else %}
{{ user_.username }}
{% endif %}
</div>
</li>
{% endfor %}
</ul>

View file

@ -1,18 +1,22 @@
{% load i18n %}
{% load static %}
<div class="userPanel">
<div class="userInfo">
{% if user.first_name != "" %}
{% translate "User" %}: {{ user.first_name }} {{ user.last_name }} ({{ user.username }})
{% else %}
{% translate "User" %}: {{ user.username }}
{% endif %}
&nbsp;-&nbsp;
{% if user.balance < 0.01 %}
<span class="userBalanceWarn">{% translate "Balance" %}: {{ user.balance }}{{ currency_suffix }}</span>
{% else %}
<span>{% translate "Balance" %}: {{ user.balance }}{{ currency_suffix }}</span>
{% endif %}
<img src="{% static 'profilepictures/'|add:user.profile_picture_filename %}">
<span>
{% if user.first_name != "" %}
{% translate "User" %}: {{ user.first_name }} {{ user.last_name }} ({{ user.username }})
{% else %}
{% translate "User" %}: {{ user.username }}
{% endif %}
&nbsp;-&nbsp;
{% if user.balance < 0.01 %}
<span class="userBalanceWarn">{% translate "Balance" %}: {{ user.balance }}{{ currency_suffix }}</span>
{% else %}
<span>{% translate "Balance" %}: {{ user.balance }}{{ currency_suffix }}</span>
{% endif %}
</span>
</div>
<div class="horizontalButtonList">
<a class="button" id="navBarBtnHome" href="/">Home</a>