当前位置: 首页>>代码示例>>Python>>正文


Python Post.create_time方法代码示例

本文整理汇总了Python中models.Post.create_time方法的典型用法代码示例。如果您正苦于以下问题:Python Post.create_time方法的具体用法?Python Post.create_time怎么用?Python Post.create_time使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Post的用法示例。


在下文中一共展示了Post.create_time方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import create_time [as 别名]
    def post(self, title):
        if self.form.validate():
            post = None

            if self.form.post_id.data:
                post = yield Post.asyncQuery(id=self.form.post_id.data).first()
            if post:
                post.modified_time = datetime.datetime.utcnow()
            else:
                post = Post()
                post.create_time = \
                    self.BeiJing2UTCTime(self.form.create_time.data)

            title = self.form.title.data.replace(' ', '-')
            content = self.form.content.data
            markdown_text = self.form.markdown.data
            tags = self.separate_tags(self.form.tags.data)
            category_str = self.form.category.data.capitalize()
            category = yield Category.asyncQuery(
                name=category_str).first()
            if not category:
                category = Category()
                category.name = category_str
                yield category.save()

            post.title = title
            post.content = content
            post.markdown = markdown_text
            post.category = category
            post.tags = tags
            post.author = self.current_user

            yield post.save()
            self.flash("compose finsh!")
            return self.redirect('/blog')
        self.render("compose.html", form=self.form)
开发者ID:chinakyc,项目名称:blog,代码行数:38,代码来源:blog.py

示例2: editpost

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import create_time [as 别名]
def editpost(post_id=None):
    """show the edit page, update the post
    choice of editor:
        while editing an existing post, use post.editor as the editor
        editing a new post, use request.args["editor"] as the editor
    """
    if request.method == "GET":
        if post_id is not None:
            post = Post.get_by_id(post_id=post_id, public_only=False)
            editor = post.editor
            if not post:
                abort(404)
        else:
            post = Post()
            editor = request.args.get("editor", "markdown")

        return render_template('admin/editpost.html',
                               admin_url="post_" + editor,
                               post=post,
                               editor=editor)
    elif request.method == "POST":
        data = request.json
        now_time = datetime.now()
        if data['post_id'] is not None:
            post = Post.get_by_id(
                post_id=int(data["post_id"]),
                public_only=False)
        else:
            post = Post()
            post.create_time = now_time
        post.editor = data.get("editor", "markdown")
        post.update_time = now_time
        post.title = data.get("title", "")
        post.update_tags(data.get("tags", ""))
        post.url = data.get("url", "")
        post.keywords = data.get("keywords", "")
        post.metacontent = data.get("metacontent", "")
        post.content = data.get("content", "")
        post.raw_content = Post.gen_raw_content(post.content, post.editor)
        post.allow_comment = data.get("allow_comment", True)
        post.allow_visit = data.get("allow_visit", True)
        post.is_original = data.get("is_original", True)
        post.need_key = data.get("need_key", False)
        post.password = data.get("password", "")
        post.save()
        return jsonify(success=True,
                       post_id=post.post_id)

    elif request.method == "DELETE":
        # Delete post by id
        if post_id is not None:
            post = Post.get_by_id(int(post_id), public_only=False)
            if post:
                post.delete()
        # Batch Delete method
        else:
            removelist = request.json
            for post_id in removelist:
                post = Post.get_by_id(post_id=int(post_id), public_only=False)
                if post:
                    post.delete()
        return jsonify(success=True)
开发者ID:minyoad,项目名称:Tyou,代码行数:64,代码来源:admin.py

示例3: import_blog

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import create_time [as 别名]
def import_blog():
    f = request.files["file"]

    try:
        data = f.stream.read().decode("utf-8")
        data = json.loads(data)
        links = data.pop("links", [])
        medias = data.pop("medias", [])
        posts = data.pop("posts", [])

        for link in links:
            new_link = Link.get_by_href(link["href"])
            if new_link:
                continue
            else:
                new_link = Link()

            for item in link:
                new_link.__dict__[item] = link[item]
            new_link.link_id = None
            new_link.create_time = \
                datetime.fromtimestamp(new_link.create_time)
            new_link.save()

        for media in medias:
            new_media = Media.get_by_fileid(media["fileid"])
            if new_media:
                continue
            else:
                new_media = Media()

            for item in media:
                new_media.__dict__[item] = media[item]

            # Notice, media id should not be set to None
            new_media.media_id = None
            new_media.create_time = \
                datetime.fromtimestamp(new_media.create_time)
            new_media.save()

        for post in posts:
            # If posts exist, continue
            new_post = Post.get_by_url(post["url"], public_only=False)
            if new_post:
                continue
            else:
                new_post = Post()

            for item in post:
                new_post.__dict__[item] = post[item]
            new_post.post_id = None
            new_post.create_time = \
                datetime.fromtimestamp(new_post.create_time)
            new_post.update_time = \
                datetime.fromtimestamp(new_post.update_time)

            new_post.raw_content = re.sub('<[^<]+?>', "", new_post.content)
            newtags = new_post.tags
            new_post.tags = ""
            new_post.update_tags(newtags)
            new_post.save()

            # Restore all posts
            comments = post["commentlist"]
            for comment in comments:
                new_comment = Comment()
                for item in comment:
                    new_comment.__dict__[item] = comment[item]
                new_comment.post_id = new_post.post_id
                new_comment.comment_id = None
                new_comment.create_time = \
                    datetime.fromtimestamp(new_comment.create_time)
                new_comment.save()
    except Exception as e:
        return str(e)

    return "Done"
开发者ID:minyoad,项目名称:Tyou,代码行数:79,代码来源:admin.py


注:本文中的models.Post.create_time方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。