Add a placeholder local avatar image for users who don't set one. Fix screens where a missing avatar caused errors. Fixes #53, Fixes #50

This commit is contained in:
Michael Hall 2018-03-18 12:26:32 -04:00
parent 39719c5896
commit 97de26ea85
8 changed files with 49 additions and 26 deletions

View file

@ -220,7 +220,7 @@ class UserForm(forms.ModelForm):
class UserProfileForm(forms.ModelForm):
class Meta:
model = UserProfile
fields = ['realname', 'avatar', 'send_notifications']
fields = ['avatar', 'realname', 'tz', 'send_notifications']
labels = {
'send_notifications': _('Send me notification emails'),
}
@ -228,7 +228,7 @@ class UserProfileForm(forms.ModelForm):
class ConfirmProfileForm(forms.ModelForm):
class Meta:
model = UserProfile
fields = ['realname', 'tz']
fields = ['avatar', 'realname', 'tz']
class SendNotificationsForm(forms.ModelForm):
class Meta:

View file

@ -22,7 +22,8 @@ class UserProfile(models.Model):
avatar = ProcessedImageField(verbose_name=_("Photo Image"),
upload_to='avatars',
processors=[ResizeToFill(128, 128)],
format='PNG')
format='PNG',
blank=True)
web_url = models.URLField(verbose_name=_('Website URL'), blank=True, null=True)
twitter = models.CharField(verbose_name=_('Twitter Name'), max_length=32, blank=True, null=True)
@ -45,7 +46,9 @@ class UserProfile(models.Model):
return "Unknown Profile"
def avatar_url(self):
if self.avatar.name.startswith('http'):
if self.avatar is None or self.avatar == '':
return settings.STATIC_URL + 'img/avatar_placeholder.png'
elif self.avatar.name.startswith('http'):
return self.avatar.name
else:
return self.avatar.url

View file

@ -1,4 +1,4 @@
<table>
{{ user_form }}
{{ profile_form }}
{{ user_form }}
</table>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View file

@ -8,7 +8,7 @@
<p><img class="align-bottom" border="1" src="{{profile.avatar_url}}" height="64px"/></p>
<h3>Please confirm your profile information</h3>
<form action="{% url 'setup-1-confirm-profile' %}" method="POST" class="form">
<form enctype="multipart/form-data" action="{% url 'setup-1-confirm-profile' %}" method="POST" class="form">
{% csrf_token %}
<p>{% include "events/profile_form.html" %}</p>
<p><button type="submit" class="btn btn-success pl-5 pr-5">Continue</button></p>
@ -19,12 +19,4 @@
</div>
{% endblock %}
{% block javascript %}
<script type="text/javascript">
$(document).ready(function(){
$("#id_tz").selectmenu();
});
</script>
{% endblock %}

View file

@ -1,14 +1,4 @@
from django.test import TestCase
# Create your tests here.
class BaseTest(TestCase):
def setUp(self):
super().setUp()
def tearDown(self):
super().tearDown()
def test_harness(self):
return
from .events import *

View file

@ -0,0 +1,38 @@
from django.test import TestCase, Client
from model_mommy import mommy
from django.contrib.auth.models import User
from events.models import Event, Attendee, UserProfile
# Create your tests here.
class EventDisplayTests(TestCase):
def setUp(self):
super().setUp()
def tearDown(self):
super().tearDown()
def test_show_event(self):
event = mommy.make(Event)
event.save()
event_url = event.get_absolute_url()
c = Client()
response = c.get(event_url)
assert(response.status_code == 200)
def test_show_event_attendee_without_avatar(self):
event = mommy.make(Event)
event.save()
profile = mommy.make(UserProfile, avatar='')
profile.save()
attendee = mommy.make(Attendee, event=event, user=profile, role=Attendee.NORMAL, status= Attendee.YES)
attendee.save()
c = Client()
response = c.get(event.get_absolute_url())
assert(response.status_code == 200)

View file

@ -35,7 +35,7 @@ def setup_1_confirm_profile(request):
return render(request, 'get_together/new_user/setup_1_confirm_profile.html', context)
elif request.method == 'POST':
user_form = UserForm(request.POST, instance=user)
profile_form = ConfirmProfileForm(request.POST, instance=profile)
profile_form = ConfirmProfileForm(request.POST, request.FILES, instance=profile)
if user_form.is_valid() and profile_form.is_valid():
saved_user = user_form.save()
profile_form.save()