Support both old-style avatar URLs and new-style upload avatar files

This commit is contained in:
Michael Hall 2018-03-17 16:21:38 -04:00
parent 03e54bbc3f
commit 3618ba6def
8 changed files with 15 additions and 9 deletions

View file

@ -45,10 +45,10 @@ class UserProfile(models.Model):
return "Unknown Profile" return "Unknown Profile"
def avatar_url(self): def avatar_url(self):
if self.avatar.url.startswith('http'): if self.avatar.name.startswith('http'):
return self.avatar.url return self.avatar.name
else: else:
return settings.MEDIA_URL + '/' + self.avatar.url return self.avatar.url
def get_timezone(self): def get_timezone(self):
try: try:

View file

@ -72,7 +72,7 @@ form {
{% if request.user.is_authenticated %} {% if request.user.is_authenticated %}
<li class="nav-item dropdown"> <li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarUserMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <a class="nav-link dropdown-toggle" href="#" id="navbarUserMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<img class="rounded-circle mr-1" src="{{request.user.profile.avatar.url}}" height="24px"/>{% if request.user.profile.realname %}{{ request.user.profile.realname }}{% else %}{{ request.user.username }}{% endif %} <img class="rounded-circle mr-1" src="{{request.user.profile.avatar_url}}" height="24px"/>{% if request.user.profile.realname %}{{ request.user.profile.realname }}{% else %}{{ request.user.username }}{% endif %}
</a> </a>
<div class="dropdown-menu" aria-labelledby="navbarUserMenuLink"> <div class="dropdown-menu" aria-labelledby="navbarUserMenuLink">
<a class="dropdown-item" href="{% url 'show-profile' request.user.profile.id %}">Profile</a> <a class="dropdown-item" href="{% url 'show-profile' request.user.profile.id %}">Profile</a>

View file

@ -72,7 +72,7 @@
{% for attendee in attendee_list %} {% for attendee in attendee_list %}
<div class="row mb-3"> <div class="row mb-3">
<div class="col media gt-profile"> <div class="col media gt-profile">
<img class="mr-1 gt-profile-avatar" src="{{attendee.user.avatar.url}}" width="32px" height="32px"> <img class="mr-1 gt-profile-avatar" src="{{attendee.user.avatar_url}}" width="32px" height="32px">
<span class="gt-profile-badges">{% for badge in attendee.user.user.account.badges.all %}<img class="mr-0 gt-profile-badge" src="{{badge.img_url}}" title="{{badge.name}}" width="16px" height="16px">{% endfor %}</span> <span class="gt-profile-badges">{% for badge in attendee.user.user.account.badges.all %}<img class="mr-0 gt-profile-badge" src="{{badge.img_url}}" title="{{badge.name}}" width="16px" height="16px">{% endfor %}</span>
<div class="media-body"> <div class="media-body">
<h6 class="mt-2 mb-0"> <h6 class="mt-2 mb-0">

View file

@ -5,7 +5,7 @@
<div class="row"> <div class="row">
<div class="col-12"> <div class="col-12">
<center> <center>
<p><img class="align-bottom" border="1" src="{{profile.avatar.url}}" height="64px"/></p> <p><img class="align-bottom" border="1" src="{{profile.avatar_url}}" height="64px"/></p>
<h3>Please confirm your profile information</h3> <h3>Please confirm your profile information</h3>
<form action="{% url 'setup-1-confirm-profile' %}" method="POST" class="form"> <form action="{% url 'setup-1-confirm-profile' %}" method="POST" class="form">

View file

@ -58,7 +58,7 @@
{% for member in member_list %} {% for member in member_list %}
<div class="row mb-3"> <div class="row mb-3">
<div class="col media gt-profile"> <div class="col media gt-profile">
<img class="mr-1 gt-profile-avatar" src="{{member.user.avatar.url}}" width="32px" height="32px"> <img class="mr-1 gt-profile-avatar" src="{{member.user.avatar_url}}" width="32px" height="32px">
<span class="gt-profile-badges">{% for badge in member.user.user.account.badges.all %}<img class="mr-0 gt-profile-badge" src="{{badge.img_url}}" title="{{badge.name}}" width="16px" height="16px">{% endfor %}</span> <span class="gt-profile-badges">{% for badge in member.user.user.account.badges.all %}<img class="mr-0 gt-profile-badge" src="{{badge.img_url}}" title="{{badge.name}}" width="16px" height="16px">{% endfor %}</span>
<div class="media-body"> <div class="media-body">
<h6 class="mt-0 mb-0"><a href="{% url 'show-profile' member.user.id %}" title="{{member.user}}'s profile">{{member.user}}</a></h6> <h6 class="mt-0 mb-0"><a href="{% url 'show-profile' member.user.id %}" title="{{member.user}}'s profile">{{member.user}}</a></h6>

View file

@ -4,7 +4,7 @@
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<img class="align-bottom" border="1" src="{{profile.avatar.url}}" height="128px"/> <img class="align-bottom" border="1" src="{{profile.avatar_url}}" height="128px"/>
<h2>Profile: {{user}}</h2> <h2>Profile: {{user}}</h2>
<form enctype="multipart/form-data" action="{% url "edit-profile" %}" method="post"> <form enctype="multipart/form-data" action="{% url "edit-profile" %}" method="post">
{% csrf_token %} {% csrf_token %}

View file

@ -8,7 +8,7 @@
<div class="col-md-2"></div> <div class="col-md-2"></div>
<div class="col-md-6"> <div class="col-md-6">
<div class="h2"> <div class="h2">
<img class="align-bottom" border="1" src="{{user.avatar.url}}" height="128px"/> {{user.user}} <img class="align-bottom" border="1" src="{{user.avatar_url}}" height="128px"/> {{user.user}}
{% if user.user.id == request.user.id %} {% if user.user.id == request.user.id %}
<a href="{% url 'edit-profile' %}" class="btn btn-secondary btn-sm">Edit Profile</a> <a href="{% url 'edit-profile' %}" class="btn btn-secondary btn-sm">Edit Profile</a>
{% endif %} {% endif %}

View file

@ -5,13 +5,19 @@ decorator==4.2.1
defusedxml==0.5.0 defusedxml==0.5.0
dj-database-url==0.4.2 dj-database-url==0.4.2
Django==2.0 Django==2.0
django-appconf==1.0.2
django-imagekit==4.0.2
django-imagekit-cropper==1.16
django-settings-export==1.2.1 django-settings-export==1.2.1
djangorestframework==3.7.7 djangorestframework==3.7.7
future==0.16.0 future==0.16.0
geocoder==1.36.0 geocoder==1.36.0
idna==2.6 idna==2.6
Markdown==2.6.11 Markdown==2.6.11
model-mommy==1.5.1
oauthlib==2.0.6 oauthlib==2.0.6
pilkit==2.0
Pillow==5.0.0
PyJWT==1.5.3 PyJWT==1.5.3
python3-openid==3.1.0 python3-openid==3.1.0
pytz==2017.3 pytz==2017.3