Пример #1
0
def create_comment(url, author_name, author_site, author_gravatar, message):
    created = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    comment = Comment(
        url=url,
        author_name=author_name,
        author_site=author_site,
        author_gravatar=author_gravatar,
        content=message,
        created=created,
        notified=None,
        published=None,
    )
    comment.save()
    return comment
Пример #2
0
    def generate(self):
        md = markdown.Markdown()

        items = []
        for row in (Comment.select().where(
                Comment.published).order_by(-Comment.published).limit(10)):
            item_link = "%s://%s%s" % (self._rss_proto, self._site_url,
                                       row.url)
            items.append(
                PyRSS2Gen.RSSItem(
                    title="%s - %s://%s%s" % (self._rss_proto, row.author_name,
                                              self._site_url, row.url),
                    link=item_link,
                    description=md.convert(row.content),
                    guid=PyRSS2Gen.Guid("%s/%d" % (item_link, row.id)),
                    pubDate=row.published,
                ))

        rss_title = 'Commentaires du site "%s"' % self._site_name
        rss = PyRSS2Gen.RSS2(
            title=rss_title,
            link="%s://%s" % (self._rss_proto, self._site_url),
            description=rss_title,
            lastBuildDate=datetime.now(),
            items=items,
        )
        rss.write_xml(open(self._rss_file, "w"), encoding="utf-8")
Пример #3
0
def find_comment_by_id(id):
    return Comment.get_by_id(id)
Пример #4
0
def count_published_comments(url):
    return (Comment.select(Comment).where(
        (Comment.url == url) & (Comment.published.is_null(False))).count()
            if url else Comment.select(Comment).where(
                Comment.published.is_null(False)).count())
Пример #5
0
def find_published_comments_by_url(url):
    return (Comment.select(Comment).where((Comment.url == url) & (
        Comment.published.is_null(False))).order_by(+Comment.published))
Пример #6
0
def find_not_published_comments():
    return Comment.select().where(Comment.published.is_null())
Пример #7
0
def find_not_notified_comments():
    return Comment.select().where(Comment.notified.is_null())
Пример #8
0
def delete_comment(comment: Comment):
    comment.delete_instance()
Пример #9
0
def publish_comment(comment: Comment):
    comment.published = datetime.now().strftime(TIME_FORMAT)
    comment.save()
Пример #10
0
def notify_comment(comment: Comment):
    comment.notified = datetime.now().strftime(TIME_FORMAT)
    comment.save()