Fix error when trying to display a speaker bio without an avatar on the speaker or on the user profile
This commit is contained in:
parent
93dc62c322
commit
e647984e4a
4 changed files with 17 additions and 2 deletions
|
@ -67,7 +67,7 @@ class UserProfile(models.Model):
|
|||
|
||||
def avatar_url(self):
|
||||
try:
|
||||
if self.avatar is None or self.avatar.name is None:
|
||||
if self.avatar is None or self.avatar.name is None or self.avatar.name == '':
|
||||
return settings.STATIC_URL + 'img/avatar_placeholder.png'
|
||||
elif self.avatar.name.startswith('http'):
|
||||
return self.avatar.name
|
||||
|
|
|
@ -34,6 +34,13 @@ class Speaker(models.Model):
|
|||
else:
|
||||
return self.user.avatar
|
||||
|
||||
def headshot_url(self):
|
||||
if self.avatar is not None and self.avatar.name is not None and self.avatar.name != '':
|
||||
return self.avatar.url
|
||||
else:
|
||||
return self.user.avatar_url()
|
||||
|
||||
|
||||
def __str__(self):
|
||||
if self.title:
|
||||
return self.title
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-9">
|
||||
<img src="{{speaker.headshot.url}}"/><hr/>
|
||||
<img src="{{speaker.headshot_url}}"/><hr/>
|
||||
<h3>{{ speaker.user }}</h3>
|
||||
<h5 class="text-muted">{{ speaker.title }}</h5>
|
||||
<p>
|
||||
|
|
|
@ -42,3 +42,11 @@ class TalkCreationTests(TestCase):
|
|||
assert(response.status_code == 302)
|
||||
assert(response.url == resolve_url('user-talks'))
|
||||
|
||||
def test_show_speaker_without_avatar(self):
|
||||
user = User.objects.create(username='testuser', password='12345', is_active=True)
|
||||
speaker = Speaker.objects.create(user=user.profile)
|
||||
|
||||
c = Client()
|
||||
response = c.get(resolve_url('show-speaker', speaker.id))
|
||||
assert(response.status_code == 200)
|
||||
self.assertContains(response, 'avatar_placeholder.png')
|
Loading…
Reference in a new issue