def _create_comments(self): tempdir = self.get_tempdir() # thread 1: 4 comments with 2 inactive thread = Thread(tempdir) now = datetime.datetime.now() later = now + datetime.timedelta(days=1) way_later = later + datetime.timedelta(days=15) far_later = way_later + datetime.timedelta(seconds=1) # linked to 2 articles article_thread = ArticleThread(tempdir, "/post/mypost", thread.uuid) article_thread2 = ArticleThread(tempdir, "/post/mypost2", thread.uuid) article_thread.add_comment(u"Ouai **ouai**", date=now, active=True) article_thread.add_comment(u"Ouai **ouai2**", date=later) article_thread.add_comment(u"Ouai **ouai3**", date=way_later, active=True) article_thread.add_comment(u"Ouai **ouai4**", date=far_later) # XXX see how we can sync related objects article_thread.save() article_thread2.load() article_thread2.save() thread.load() return thread, article_thread, article_thread2, tempdir
def new_comment(): data = request.json comments_dir = app._config['henet']['comments_dir'] article_uuid = data['source_path'] article_thread = ArticleThread(comments_dir, article_uuid) article_thread.add_comment(text=data['text'], author=data['author']) article_thread.save() notifs = app._config['notifications'] moderator = notifs.get('moderate_comment') if moderator is not None: app.send_email([moderator], u'Nouveau commentaire', MODERATE_BODY) emit(EVENT_CREATED_COMMENT, article_uuid=article_uuid) return {'result': 'OK'}