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'}
def add_comments(generator, content): try: # the article unique id is its relative source path, # so the comments are not dependant on the URL. source_path = content.get_relative_source_path() article_uuid = source_path.encode('utf8') thread = ArticleThread(storage_dir, article_uuid) thread = thread.asjson() for comment in thread['comments']: html = rst2html(comment['text'], theme='acr', body_only=True) comment['html'] = html content.metadata["comments"] = thread except: # XXX for some reason Pelican does not print plugins exceptions traceback.print_exc() raise
def test_empty_commemts(self): tempdir = self.get_tempdir() ath = ArticleThread(tempdir) self.assertEquals(ath.asjson()["comments"], []) self.assertEquals(len(ath.render().split("\n")), 1)
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