def create_comment(cls, text, commenter, post, parent_comment=None): post_comment = PostComment.objects.create(text=text, commenter=commenter, post=post, parent_comment=parent_comment) post_comment.language = get_language_for_text(text) post_comment.save() return post_comment
def reply_to_comment(self, commenter, text): post_comment = PostComment.create_comment(text=text, commenter=commenter, post=self.post, parent_comment=self) post_comment.language = get_language_for_text(text) post_comment.save() return post_comment
def assign_language_comments(self): PostComment = get_post_comment_model() post_comments = PostComment.objects.filter(text__isnull=False) for post_comment in post_comments: try: language = get_language_for_text(post_comment.text) except LangDetectException as e: print('Caught exception while detecting language, skipping') if language: post_comment.language = language post_comment.save() else: print('Could not detect language for id', post_comment.id)
def create_post(cls, creator, circles_ids=None, community_name=None, image=None, text=None, video=None, created=None, is_draft=False): if not community_name and not circles_ids: raise ValidationError( _('A post requires circles or a community to be posted to.')) if community_name and circles_ids: raise ValidationError( _('A post cannot be posted both to a community and to circles.' )) post = Post.objects.create(creator=creator, created=created) if image and video: raise ValidationError( _('A post must have an image or a video, not both.')) if text: post.text = text post.language = get_language_for_text(text) if image: post.add_media(file=image) elif video: post.add_media(file=video) if circles_ids: post.circles.add(*circles_ids) else: Community = get_community_model() post.community = Community.objects.get(name=community_name) # If on create we have a video or image, we automatically publish it # Backwards compat reasons. if not is_draft: post.publish() else: post.save() return post
def create_post(cls, creator, circles_ids=None, community_name=None, image=None, text=None, video=None, created=None): if not community_name and not circles_ids: raise ValidationError( _('A post requires circles or a community to be posted to.')) if community_name and circles_ids: raise ValidationError( _('A post cannot be posted both to a community and to circles.' )) if not text and not image and not video: raise ValidationError(_('A post requires text or an image/video.')) if image and video: raise ValidationError( _('A post must have an image or a video, not both.')) post = Post.objects.create(creator=creator, created=created) if text: post.text = text post.language = get_language_for_text(text) if image: PostImage.create_post_image(image=image, post_id=post.pk) if video: PostVideo.create_post_video(video=video, post_id=post.pk) if circles_ids: post.circles.add(*circles_ids) else: Community = get_community_model() post.community = Community.objects.get(name=community_name) post.save() return post
def update_comment(self, text): self.text = text self.is_edited = True self.language = get_language_for_text(text) self.save()
def update(self, text=None): self._check_can_be_updated(text=text) self.text = text self.is_edited = True self.language = get_language_for_text(text) self.save()