better avatar pic: use name initial as avatar

This commit is contained in:
Son NK 2019-08-16 11:57:19 +02:00
parent 83abbe5406
commit 28d475ea22
3 changed files with 13 additions and 3 deletions

View File

@ -24,8 +24,9 @@
<div class="form-label">Profile picture</div>
{{ form.profile_picture(class="form-control-file") }}
{{ render_field_errors(form.profile_picture) }}
<img src="{{ current_user.profile_picture_url() }}" class="profile-picture">
{% if current_user.profile_picture_id %}
<img src="{{ current_user.profile_picture_url() }}" class="profile-picture">
{% endif %}
</div>
<button class="btn btn-primary">Update</button>

View File

@ -230,6 +230,10 @@ class User(db.Model, ModelMixin, UserMixin):
return self.name, [other_name, "Anonymous", "whoami"]
def get_name_initial(self) -> str:
names = self.name.split(" ")
return "".join([n[0].upper() for n in names if n])
class ActivationCode(db.Model, ModelMixin):
"""For activate user account"""

View File

@ -23,7 +23,12 @@
</div>
<div class="dropdown">
<a href="#" class="nav-link pr-0 leading-none" data-toggle="dropdown">
<span class="avatar" style="background-image: url('{{ current_user.profile_picture_url() }}')"></span>
{% if current_user.profile_picture_id %}
<span class="avatar" style="background-image: url('{{ current_user.profile_picture_url() }}')"></span>
{% else %}
<span class="avatar avatar-blue">{{ current_user.get_name_initial() }}</span>
{% endif %}
<span class="ml-2 d-none d-lg-block">
<span class="text-default">{{ current_user.name }}</span>
<small class="text-muted d-block mt-1">{{ current_user.email }}</small>