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


Python Post.status方法代码示例

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


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

示例1: add_initial_data

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import status [as 别名]
def add_initial_data():
    """Insert initial data into the database"""
    # open database session
    db_session = DB(db).get_session()

    # ask user for an admin username and password
    username = raw_input('Please enter the admin username: ')
    password = getpass.getpass(prompt='Please enter the admin password: ')

    # add user to database
    u = User(username, encrypt_password(app.config['SECRET_KEY'], password))
    db_session.add(u)

    # create statuses
    s1 = Status('draft')
    s2 = Status('private')
    s3 = Status('public')
    db_session.add(s1)
    db_session.add(s2)
    db_session.add(s3)

    # create formats
    f = Format('rest')
    f2 = Format('markdown')
    db_session.add(f)
    db_session.add(f2)

    # Tags
    t1 = Tag('imposter')
    t2 = Tag('weblog')

    # build initial post and put it in the database
    initial_post_summary = """
Installed Correctly!
"""
    initial_post_content = """
Imposter was installed correctly!

This is just a sample post to show Imposter works.

**Have a lot of fun blogging!**
"""
    p1 = Post('Welcome to Imposter!', initial_post_summary, initial_post_content)
    p1.slug = slugify(p1.title)
    p1.createdate = datetime.now()
    p1.lastmoddate = datetime.now()
    p1.pubdate = datetime.now()
    p1.format = f
    p1.status = s3
    p1.user = u
    p1.tags = [t1, t2]
    p1.compile()
    db_session.add(p1)
    db_session.commit()
开发者ID:jkossen,项目名称:imposter,代码行数:56,代码来源:dbmanage.py

示例2: add_post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import status [as 别名]
def add_post(data, instance_id=""):
    if instance_id:
        post = Post.get_by_id(int(instance_id))
    else:
        post = Post()

    if data["name"]:
        post.name = data["name"]

    if data["email"]:
        post.email = data["email"]

    if data["twitter"]:
        post.twitter = data["twitter"]

    if data["facebook"]:
        post.facebook = data["facebook"]

    if data["phone"]:
        post.phone = data["phone"]

    if data["message"]:
        post.message = data["message"]

    if data["post_type"]:

        types = []
        for this_type in data["post_type"]:
            post_type = this_type.replace(" ", "_")
            types.append(post_type.upper())
        if post.post_type:
            for item in types:
                post.post_type.append(item)
        else:
            post.post_type = types
    else:
        post.post_type = ['NEED']

    if data["expiry"]:
        post.expiry = data["expiry"]

    if data["status"]:
        post.status = data["status"].upper()

    if data["location"]:
        post.location = data["location"]

    post.put()
    return post
开发者ID:albertpadin,项目名称:bangonph,代码行数:51,代码来源:functions.py

示例3: test_post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import status [as 别名]
    def test_post(self):
        title = "Some title"

        # DRAFT post must throw 404
        post = Post(title=title, status=DRAFT)
        post.save()
        resp = self.client.get(post.get_absolute_url())
        self.assertEqual(resp.status_code, 404)

        # PUBLISHED returns normal post
        post.status = PUBLISHED
        post.save()
        resp = self.client.get(post.get_absolute_url())
        self.assertEqual(resp.status_code, 200)
        self.assertTrue('post' in resp.context)
        self.assertEqual(resp.context['post'].pk, post.id)
        self.assertEqual(resp.context['post'].title, title)

        #test unexisting post (must throw 404)
        resp = self.client.get(reverse('post_without_slug', args=[post.id + 1]))
        self.assertEqual(resp.status_code, 404)
开发者ID:bbenko,项目名称:shinkicker,代码行数:23,代码来源:tests.py

示例4: add_post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import status [as 别名]
def add_post(data, instance_id=""):
    if instance_id:
        post = Post.get_by_id(int(instance_id))
    else:
        post = Post()

    if data["name"]:
        post.name = data["name"]

    if data["email"]:
        post.email = data["email"]

    if data["twitter"]:
        post.twitter = data["twitter"]

    if data["facebook"]:
        post.facebook = data["facebook"]

    if data["phone"]:
        post.phone = data["phone"]

    if data["message"]:
        post.message = data["message"]

    if data["post_type"]:
        post.post_type = data["post_type"]

    if data["expiry"]:
        post.expiry = data["expiry"]

    if data["status"]:
        post.status = data["status"].upper()

    if data["location"]:
        post.location = data["location"]

    post.put()
    return post
开发者ID:rileonard15,项目名称:bangonph,代码行数:40,代码来源:functions.py

示例5: save_post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import status [as 别名]
def save_post(post_id=None):
    """Save Post to database

    If post_id is None a new Post will be inserted in the database. Otherwise
    the existing Post will be updated.
    """
    message = 'Post updated'
    orig_tags = []

    post_form = PostForm(request.form)

    if not post_form.validate():
        flash('ERROR: errors detected. Post NOT saved!', category='error')
        return edit_post(post_id=post_id, post_form=post_form)

    # test if we're creating a new post, or updating an existing one
    if post_id is None:
        post = Post()
        post.status_id = 1
        post.user_id = session['user_id']
        post.createdate = datetime.now()
    else:
        post = get_post(post_id)
        orig_tags = [tag for tag in post.tags]

    post_form.populate_obj(post)
    post.lastmoddate = datetime.now()

    # compile input to html
    post.compile(app.config['REPL_TAGS'])

    # update pubdate if post's pubdate is None and its status is set
    # to public
    if request.form['status'] == 'public' and \
           unicode(post.status) != 'public' and \
           post.pubdate is None:
        post.pubdate = datetime.now()

    post.status = get_status(request.form['status'])

    if post.slug is None:
        post.slug = slugify(post.title)

    if post_id is None:
        db_session.add(post)
        message = 'New post was successfully added'

    db_session.commit()

    for tag in orig_tags:
        recalculate_tagcount(tag)

    for tag in post.tags:
        if tag not in orig_tags:
            recalculate_tagcount(tag)

    db_session.commit()

    flash(message, category='info')

    return redirect(url_for('edit_post', post_id=post.id))
开发者ID:jkossen,项目名称:imposter,代码行数:63,代码来源:admin.py


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