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:
parent
39719c5896
commit
97de26ea85
8 changed files with 49 additions and 26 deletions
|
@ -220,7 +220,7 @@ class UserForm(forms.ModelForm):
|
||||||
class UserProfileForm(forms.ModelForm):
|
class UserProfileForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = UserProfile
|
model = UserProfile
|
||||||
fields = ['realname', 'avatar', 'send_notifications']
|
fields = ['avatar', 'realname', 'tz', 'send_notifications']
|
||||||
labels = {
|
labels = {
|
||||||
'send_notifications': _('Send me notification emails'),
|
'send_notifications': _('Send me notification emails'),
|
||||||
}
|
}
|
||||||
|
@ -228,7 +228,7 @@ class UserProfileForm(forms.ModelForm):
|
||||||
class ConfirmProfileForm(forms.ModelForm):
|
class ConfirmProfileForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = UserProfile
|
model = UserProfile
|
||||||
fields = ['realname', 'tz']
|
fields = ['avatar', 'realname', 'tz']
|
||||||
|
|
||||||
class SendNotificationsForm(forms.ModelForm):
|
class SendNotificationsForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
@ -22,7 +22,8 @@ class UserProfile(models.Model):
|
||||||
avatar = ProcessedImageField(verbose_name=_("Photo Image"),
|
avatar = ProcessedImageField(verbose_name=_("Photo Image"),
|
||||||
upload_to='avatars',
|
upload_to='avatars',
|
||||||
processors=[ResizeToFill(128, 128)],
|
processors=[ResizeToFill(128, 128)],
|
||||||
format='PNG')
|
format='PNG',
|
||||||
|
blank=True)
|
||||||
|
|
||||||
web_url = models.URLField(verbose_name=_('Website URL'), blank=True, null=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)
|
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"
|
return "Unknown Profile"
|
||||||
|
|
||||||
def avatar_url(self):
|
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
|
return self.avatar.name
|
||||||
else:
|
else:
|
||||||
return self.avatar.url
|
return self.avatar.url
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<table>
|
<table>
|
||||||
{{ user_form }}
|
|
||||||
{{ profile_form }}
|
{{ profile_form }}
|
||||||
|
{{ user_form }}
|
||||||
</table>
|
</table>
|
||||||
|
|
BIN
get_together/static/img/avatar_placeholder.png
Normal file
BIN
get_together/static/img/avatar_placeholder.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.4 KiB |
|
@ -8,7 +8,7 @@
|
||||||
<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 enctype="multipart/form-data" action="{% url 'setup-1-confirm-profile' %}" method="POST" class="form">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<p>{% include "events/profile_form.html" %}</p>
|
<p>{% include "events/profile_form.html" %}</p>
|
||||||
<p><button type="submit" class="btn btn-success pl-5 pr-5">Continue</button></p>
|
<p><button type="submit" class="btn btn-success pl-5 pr-5">Continue</button></p>
|
||||||
|
@ -19,12 +19,4 @@
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block javascript %}
|
|
||||||
<script type="text/javascript">
|
|
||||||
$(document).ready(function(){
|
|
||||||
$("#id_tz").selectmenu();
|
|
||||||
});
|
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
{% endblock %}
|
|
||||||
|
|
|
@ -1,14 +1,4 @@
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
# Create your tests here.
|
from .events import *
|
||||||
class BaseTest(TestCase):
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
super().setUp()
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
super().tearDown()
|
|
||||||
|
|
||||||
def test_harness(self):
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
38
get_together/tests/events.py
Normal file
38
get_together/tests/events.py
Normal 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)
|
||||||
|
|
|
@ -35,7 +35,7 @@ def setup_1_confirm_profile(request):
|
||||||
return render(request, 'get_together/new_user/setup_1_confirm_profile.html', context)
|
return render(request, 'get_together/new_user/setup_1_confirm_profile.html', context)
|
||||||
elif request.method == 'POST':
|
elif request.method == 'POST':
|
||||||
user_form = UserForm(request.POST, instance=user)
|
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():
|
if user_form.is_valid() and profile_form.is_valid():
|
||||||
saved_user = user_form.save()
|
saved_user = user_form.save()
|
||||||
profile_form.save()
|
profile_form.save()
|
||||||
|
|
Loading…
Reference in a new issue