Skip to content

[SHARE-511][Feature] Store user favicons as a blob#565

Merged
chrisseto merged 19 commits intoCenterForOpenScience:developfrom
aaxelb:feature/blob-favicons
Feb 3, 2017
Merged

[SHARE-511][Feature] Store user favicons as a blob#565
chrisseto merged 19 commits intoCenterForOpenScience:developfrom
aaxelb:feature/blob-favicons

Conversation

@aaxelb
Copy link
Copy Markdown
Contributor

@aaxelb aaxelb commented Jan 17, 2017

Store favicons as a blob in the database.

https://openscience.atlassian.net/browse/SHARE-511

@aaxelb aaxelb changed the title [WIP][SHAREFeature/blob favicons [WIP][SHARE-511][Feature] Store user favicons as a blob Jan 17, 2017
@aaxelb aaxelb changed the title [WIP][SHARE-511][Feature] Store user favicons as a blob [SHARE-511][Feature] Store user favicons as a blob Jan 18, 2017
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bot migrations can be removed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll only add to apps with ProviderAppConfigs.

Comment thread share/robot.py Outdated
with open(os.path.join(self.config.path, 'favicon.ico'), 'rb') as f:
user.favicon.save(user.username, File(f))
except OSError:
pass
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exception shouldn't be caught. Anything that has this migration should have a favicon as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I'll add the missing favicons, then, too.

Comment thread share/models/core.py
return ContentFile(favicon.image)

def _save(self, name, content):
user = ShareUser.objects.get(username=name)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would a join in update_or_create work?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd tried user__username=name but it complained that user_id was missing. Apparently it's not smart enough for that.

Comment thread share/models/core.py Outdated
@@ -75,6 +81,37 @@ def create_robot_user(self, username, robot, long_title='', home_page=''):
return user


class FaviconImage(models.Model):
user = models.OneToOneField('ShareUser', on_delete=DATABASE_CASCADE, primary_key=True)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let django handle the primary key. Things have a tendency to get weird when you don't.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread share/graphql/base.py
@@ -26,7 +26,7 @@ def resolve_title(cls, instance, context, request, info):

@classmethod
def resolve_favicon(cls, instance, context, request, info):
return '/static/{}/img/favicon.ico'.format(instance.robot.replace('providers.', '', 1))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for sanity's sake, can you use django's reverse URL look up here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, yes.

Comment thread requirements.txt
@@ -55,3 +55,4 @@ newrelic==2.68.0.50
raven==5.23.0
graphene==1.0.2
graphene-django==1.0
pillow==4.0.0
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is pillow actually being used for anything?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's required by ImageField, to validate that uploaded files are images.

@aaxelb
Copy link
Copy Markdown
Contributor Author

aaxelb commented Jan 20, 2017

@chrisseto changes made

@aaxelb aaxelb force-pushed the feature/blob-favicons branch from 78c825a to d3b4f6a Compare January 31, 2017 19:21
Comment thread api/views/share.py Outdated


def user_favicon_view(request, username):
user = ShareUser.objects.get(username=username)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this guy 500's rather than 404's if it fails

This should also only respond to GETs, just for semantic correctness.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, derp. Didn't think about the user not existing. Fixed.

@chrisseto chrisseto merged commit d9a1987 into CenterForOpenScience:develop Feb 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants