Esempio n. 1
0
def comment_format(objs):
    for obj in objs:
        obj.gravatar = "http://www.gravatar.com/avatar/%s" % md5(obj.email).hexdigest()
        obj.add_time = time_from_now(int(obj.add_time))

        if obj.visible:
            obj.short_content = HTML_REG.sub("", obj.content[:RECENT_COMMENT_CUT_WORDS])
        else:
            obj.short_content = "Your comment is awaiting moderation."[:RECENT_COMMENT_CUT_WORDS]

        obj.content = obj.content.replace("\n", "<br/>")
    return objs
Esempio n. 2
0
def post_list_format(posts):
    for obj in posts:
        obj.absolute_url = "%s/topic/%d/%s" % (BASE_URL, obj.id, slugfy(obj.title))
        obj.taglist = ", ".join(
            ["""<a href="%s/tag/%s/" rel="tag">%s</a>""" % (BASE_URL, tag, tag) for tag in obj.tags.split(",")]
        )

        if "<!--more-->" in obj.content:
            obj.shorten_content = obj.content.split("<!--more-->")[0]
        else:
            obj.shorten_content = HTML_REG.sub("", obj.content[:SHORTEN_CONTENT_WORDS])

        obj.add_time_fn = time_from_now(int(obj.add_time))
    return posts
Esempio n. 3
0
def post_detail_formate(obj):
    if obj:
        slug = slugfy(obj.title)
        obj.slug = slug
        obj.absolute_url = "%s/topic/%d/%s" % (BASE_URL, obj.id, slug)
        obj.shorten_url = "%s/t/%s" % (BASE_URL, obj.id)
        if "[/code]" in obj.content:
            obj.highlight = True
        else:
            obj.highlight = False
        obj.content = tran_content(obj.content, obj.highlight)
        obj.taglist = ", ".join(
            ["""<a href="%s/tag/%s/" rel="tag">%s</a>""" % (BASE_URL, tag, tag) for tag in obj.tags.split(",")]
        )
        obj.add_time_fn = time_from_now(int(obj.add_time))
        obj.last_modified = timestamp_to_datetime(obj.edit_time)
        obj.keywords = obj.tags
        obj.description = HTML_REG.sub("", obj.content[:DESCRIPTION_CUT_WORDS])
        # get prev and next obj
        obj.prev_obj = sdb.get("SELECT `id`,`title` FROM `sp_posts` WHERE `id` > %s LIMIT 1" % str(obj.id))
        if obj.prev_obj:
            obj.prev_obj.slug = slugfy(obj.prev_obj.title)
        obj.next_obj = sdb.get(
            "SELECT `id`,`title` FROM `sp_posts` WHERE `id` < %s ORDER BY `id` DESC LIMIT 1" % str(obj.id)
        )
        if obj.next_obj:
            obj.next_obj.slug = slugfy(obj.next_obj.title)
        # get relative obj base tags
        obj.relative = []
        if obj.tags:
            idlist = []
            getit = False
            for tag in obj.tags.split(","):
                tagobj = Tag.get_tag_by_name(tag)
                if tagobj and tagobj.content:
                    pids = tagobj.content.split(",")
                    for pid in pids:
                        if pid != str(obj.id) and pid not in idlist:
                            idlist.append(pid)
                            if len(idlist) >= RELATIVE_POST_NUM:
                                getit = True
                                break
                if getit:
                    break
            #
            if idlist:
                obj.relative = sdb.query(
                    "SELECT `id`,`title` FROM `sp_posts` WHERE `id` in(%s) LIMIT %s"
                    % (",".join(idlist), str(len(idlist)))
                )
                if obj.relative:
                    for robj in obj.relative:
                        robj.slug = slugfy(robj.title)
        # get comment
        obj.coms = []
        if obj.comment_num > 0:
            if obj.comment_num >= EACH_PAGE_COMMENT_NUM:
                first_limit = EACH_PAGE_COMMENT_NUM
            else:
                first_limit = obj.comment_num
            obj.coms = Comment.get_post_page_comments_by_id(obj.id, 0, first_limit)
    return obj