Skip to content

Instantly share code, notes, and snippets.

@cacheleocode
Created December 20, 2014 21:12
Show Gist options
  • Select an option

  • Save cacheleocode/5eff152436c816c8ec57 to your computer and use it in GitHub Desktop.

Select an option

Save cacheleocode/5eff152436c816c8ec57 to your computer and use it in GitHub Desktop.
determine signature image
def signature_image2(self):
# image or attachment
if self.image:
if self.image.height == self.image.width or self.image.size <= 50000: # legacy pre-cropped, pre-sized square image, smaller than about 50KB
if self.image_attachments():
attachments = sorted(self.image_attachments(), key=lambda x: x.file.size, reverse=True)
for attachment in attachments:
if attachment.selected:
return attachment.file
# get biggest attachment
return attachments[0].file
else: # non-legacy image
return self.image
else:
# redundant for now...
if self.image_attachments():
attachments = sorted(self.image_attachments(), key=lambda x: x.file.size, reverse=True)
for attachment in attachments:
if attachment.selected:
return attachment.file
# get biggest attachment
return attachments[0].file
# series
if self.series and self.series.image:
return self.series.image
# author
author_imgs = []
if self.authors:
for a in self.get_authors():
if a.image:
author_imgs.append(a.image)
if author_imgs and author_imgs[0]:
return author_imgs[0]
# icon
return ARTICLE_ICON
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment