Skip to content

Commit

Permalink
Merge pull request #1007 from abulte/gh-1006-fix-avatar-placeholders
Browse files Browse the repository at this point in the history
Fix avatar placeholders
  • Loading branch information
abulte committed Jul 4, 2017
2 parents f9a147b + 1eff97b commit 25e2d63
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
[#1009](https://github.com/opendatateam/udata/issues/1009)
- Reindex datasets when their parent organization is purged
[#1008](https://github.com/opendatateam/udata/issues/1008)
- Fix image placeholders display in various places
[#1006](https://github.com/opendatateam/udata/issues/1006)

## 1.0.11 (2017-05-25)

Expand Down
6 changes: 4 additions & 2 deletions js/components/organization/profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<small v-if="org.acronym">{{org.acronym}}</small>
</h3>
<div class="profile-body">
<image-button :src="org.logo_thumbnail" :size="100" class="logo-button"
<image-button :src="logoSrc" :size="100" class="logo-button"
:endpoint="endpoint">
</image-button>
<div v-markdown="org.description"></div>
Expand All @@ -46,6 +46,7 @@ import API from 'api';
import badges from 'models/badges';
import Box from 'components/containers/box.vue';
import ImageButton from 'components/widgets/image-button.vue';
import placeholders from 'helpers/placeholders';
export default {
name: 'organization-profile',
Expand All @@ -58,7 +59,8 @@ export default {
data() {
return {
toggled: false,
badges: badges.organization
badges: badges.organization,
logoSrc: this.org.logo_thumbnail || placeholders.organization,
}
},
components: {Box, ImageButton},
Expand Down
4 changes: 3 additions & 1 deletion js/components/user/profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<box :title="title" icon="user" boxclass="user-profile-widget">
<h3>{{user.fullname}}</h3>
<div class="profile-body">
<image-button :src="user.avatar_thumbnail" :size="100" class="avatar-button"
<image-button :src="avatarSrc" :size="100" class="avatar-button"
:endpoint="endpoint">
</image-button>
<div v-markdown="user.about"></div>
Expand All @@ -36,13 +36,15 @@
import API from 'api';
import Box from 'components/containers/box.vue';
import ImageButton from 'components/widgets/image-button.vue';
import placeholders from 'helpers/placeholders';
export default {
name: 'user-profile',
props: ['user'],
data() {
return {
title: this._('Profile'),
avatarSrc: this.user.avatar_thumbnail || placeholders.user,
};
},
computed: {
Expand Down
28 changes: 13 additions & 15 deletions udata/frontend/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,26 +131,24 @@ def obfuscate(email):


@front.app_template_filter()
@front.app_template_global()
def avatar_url(obj, size):
@contextfilter
def avatar_url(ctx, obj, size):
if hasattr(obj, 'avatar') and obj.avatar:
return obj.avatar(size)
elif hasattr(obj, 'logo') and obj.logo:
return obj.logo(size)
else:
return placeholder(None, 'user')
return placeholder(ctx, None, name='user')


@front.app_template_global()
@front.app_template_filter()
def owner_avatar_url(obj, size=32):
def owner_avatar_url(ctx, obj, size=32):
if hasattr(obj, 'organization') and obj.organization:
return (obj.organization.logo(size)
if obj.organization.logo
else placeholder(None, 'organization'))
else placeholder(ctx, None, name='organization'))
elif hasattr(obj, 'owner') and obj.owner:
return avatar_url(obj.owner, size)
return placeholder(None, 'user')
return avatar_url(ctx, obj.owner, size)
return placeholder(ctx, None, name='user')


@front.app_template_global()
Expand All @@ -164,8 +162,8 @@ def owner_url(obj):


@front.app_template_filter()
@front.app_template_global()
def avatar(user, size, classes=''):
@contextfilter
def avatar(ctx, user, size, classes=''):
markup = '''
<a class="avatar {classes}" href="{url}" title="{title}">
<img src="{avatar_url}" class="avatar" alt="{title}"
Expand All @@ -176,15 +174,15 @@ def avatar(user, size, classes=''):
url=(url_for('users.show', user=user)
if user and getattr(user, 'id', None) else '#'),
size=size,
avatar_url=avatar_url(user, size),
avatar_url=avatar_url(ctx, user, size),
classes=classes
)
return Markup(markup)


@front.app_template_global()
@front.app_template_filter()
def owner_avatar(obj, size=32):
@contextfilter
def owner_avatar(ctx, obj, size=32):
markup = '''
<a class="avatar" href="{url}" title="{title}">
<img src="{avatar_url}" class="avatar" alt="{title}"
Expand All @@ -195,7 +193,7 @@ def owner_avatar(obj, size=32):
title=owner_name(obj),
url=owner_url(obj),
size=size,
avatar_url=owner_avatar_url(obj, size),
avatar_url=owner_avatar_url(ctx, obj, size),
))


Expand Down

0 comments on commit 25e2d63

Please sign in to comment.