From 97de26ea85e7410ba0e470886f11d8e7ac8fd2f8 Mon Sep 17 00:00:00 2001
From: Michael Hall
Date: Sun, 18 Mar 2018 12:26:32 -0400
Subject: [PATCH] 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
---
events/forms.py | 4 +-
events/models/profiles.py | 7 +++-
events/templates/events/profile_form.html | 2 +-
.../static/img/avatar_placeholder.png | Bin 0 -> 2449 bytes
.../new_user/setup_1_confirm_profile.html | 10 +----
get_together/tests/__init__.py | 12 +-----
get_together/tests/events.py | 38 ++++++++++++++++++
get_together/views/new_user.py | 2 +-
8 files changed, 49 insertions(+), 26 deletions(-)
create mode 100644 get_together/static/img/avatar_placeholder.png
create mode 100644 get_together/tests/events.py
diff --git a/events/forms.py b/events/forms.py
index 9fe6f79..90010be 100644
--- a/events/forms.py
+++ b/events/forms.py
@@ -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:
diff --git a/events/models/profiles.py b/events/models/profiles.py
index ec66d89..7127dfb 100644
--- a/events/models/profiles.py
+++ b/events/models/profiles.py
@@ -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
diff --git a/events/templates/events/profile_form.html b/events/templates/events/profile_form.html
index c8fd498..6772da3 100644
--- a/events/templates/events/profile_form.html
+++ b/events/templates/events/profile_form.html
@@ -1,4 +1,4 @@
-{{ user_form }}
{{ profile_form }}
+{{ user_form }}
diff --git a/get_together/static/img/avatar_placeholder.png b/get_together/static/img/avatar_placeholder.png
new file mode 100644
index 0000000000000000000000000000000000000000..fd5cf254cc17b88ea07e926557a3083aca89227f
GIT binary patch
literal 2449
zcmWlb2{hFE7r=kNF&HD7nH14uESb?L`&c4_!I)&H$-ZTKEn^g($RISvHq;x6Xl(gs
zEt03KFH4bn!l}eWPnHZ%C|mRYIp6dB-gED{=X=h*-+Mpz%W`tCl|srR0RWJ)qmW%7
z$=urrG3e|$74QlYVu7b^$$)Tgl|HY^hb$6w%DE^2kUX%rLEui29Ap%~Vt2+`d|Cv9
zk`U#F9QK0T6z#|sZm}PhieEXp`pBjynt3A+$s{rCZZlYTtQ-{x$`twSX2H#*g0R3M
zqgg2rxs34IrV6v=&Zd&8nLML=m~k8`bCdQr8;?evGejUWLw*Opk`%b$*bwflWu?Q8#|B7
zT{N+QvS`oKV*fxqtqd#+KExtZ<1WfLuun0)gQ4a5U`l<*BChWrY~;wrHuIo}P&i
zKmbQsqs`3BVpsU!fu%;z+NY5-Vw#5}B^uE7_V)a(^+o&UfeXa4*4D!(xNJD$=n1Z*
zl$6x3+opfMnZGh85U7Keb}=!AYjI|eXE0edDTRfHF<2Q*Ev>TZYSujQj=lP`Yd2GRVz6>@`^1cnNDF4iO^UPO2(gk=2_II9
z+x@k5buD4=lAo+WPqm7=Mv=aft?p?#~JFV;v%oVTfeFf-gj_q9m}`|(#&m{=Rh8h
zhf+{@m9Uk=W~+i@1Yo&}PEo^9D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