Show More
@@ -200,7 +200,12 b' class Post(models.Model, Viewable):' | |||||
200 | return self.get_view(need_op_data=True, *args, **kwargs) |
|
200 | return self.get_view(need_op_data=True, *args, **kwargs) | |
201 |
|
201 | |||
202 | def get_first_image(self) -> Attachment: |
|
202 | def get_first_image(self) -> Attachment: | |
203 | return self.attachments.filter(mimetype__in=FILE_TYPES_IMAGE).earliest('id') |
|
203 | image = None | |
|
204 | try: | |||
|
205 | image = self.attachments.filter(mimetype__in=FILE_TYPES_IMAGE).earliest('id') | |||
|
206 | except Attachment.DoesNotExist: | |||
|
207 | pass | |||
|
208 | return image | |||
204 |
|
209 | |||
205 | def set_global_id(self, key_pair=None): |
|
210 | def set_global_id(self, key_pair=None): | |
206 | """ |
|
211 | """ |
@@ -37,10 +37,10 b' class JsonExporter(Exporter):' | |||||
37 | 'title': post.title, |
|
37 | 'title': post.title, | |
38 | 'text': post.get_raw_text(), |
|
38 | 'text': post.get_raw_text(), | |
39 | } |
|
39 | } | |
40 | if post.attachments.exists(): |
|
40 | post_image = post.get_first_image() | |
41 | post_image = post.get_first_image() |
|
41 | if post_image: | |
42 | post_json['image'] = post_image.file.url |
|
42 | post_json['image'] = post_image.file.url | |
43 |
post_json['image_preview'] = post_image.get_ |
|
43 | post_json['image_preview'] = post_image.get_thumb_url() | |
44 | if include_last_update: |
|
44 | if include_last_update: | |
45 | post_json['bump_time'] = utils.datetime_to_epoch( |
|
45 | post_json['bump_time'] = utils.datetime_to_epoch( | |
46 | post.get_thread().bump_time) |
|
46 | post.get_thread().bump_time) |
General Comments 0
You need to be logged in to leave comments.
Login now