Created
December 20, 2014 21:12
-
-
Save cacheleocode/5eff152436c816c8ec57 to your computer and use it in GitHub Desktop.
determine signature image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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