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


Python BlogPost.update方法代码示例

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


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

示例1: post

# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import update [as 别名]
 def post(self, blog_id):
     blog = BlogPost.get_by_id(int(blog_id))
     title = self.request.get("title")
     slug = self.request.get("slug")
     text = self.request.get("text")
     if title and slug and text:
         blog = BlogPost.update(blog_post=blog, title=title, slug=slug, text=text)
     return self.redirect_to("blog-details", slug=blog.slug)
开发者ID:ramuta,项目名称:homepage,代码行数:10,代码来源:blog.py

示例2: single_post

# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import update [as 别名]
def single_post(post_id):
    if request.method == "POST" and request.form and request.form['_method']:
        if authenticate():
            if request.form['_method'] == "PUT" or request.form['_method'] == "PATCH":
                post = request.form
                error = False
                title = request.form['title'].strip() if request.form['title'] != None else None
                if title:
                    if re.search("^[ a-zA-Z0-9\,\?\!]+$", title) == None:
                        flash('Invalid characters detected in title')
                        error = True
                else:
                    flash('Title cannot be empty')
                    error = True
                content = request.form['content'].strip()
                if content:
                    regex = re.compile('^[ a-zA-Z0-9\.\?\,\!\"\(\)]+$', re.MULTILINE)
                    content = content.replace("\r","")
                    num_matches = len(regex.findall(content))
                    num_lines = len(list(filter(remove_blanks,content.split("\n"))))
                    if num_matches != num_lines:
                        flash('Invalid characters detected in article body')
                        error = True
                    if not error:
                        try:
                            q = BlogPost.update(
                                title=request.form['title'],
                                content=request.form['content']
                            ).where(BlogPost.id == post_id)
                            q.execute()
                        except IntegrityError:
                            flash('That title is already taken')
                            error = True
                        except BlogPost.DoesNotExist:
                            return redirect(url_for('blog'))
                else:
                    flash('Article body cannot be empty')
                    error = True
    
                if error:
                    return render_template('blog/edit.html', post=post)
                else:
                    return redirect(url_for('single_post', post_id=post_id))
            elif request.form['_method'] == "DELETE":
                try:
                    post = BlogPost.get(BlogPost.id == post_id)
                    post.delete_instance()
                    flash('Successfully deleted the blog post')
                    return redirect(url_for('blog'))
                except BlogPost.DoesNotExist:
                    return redirect(url_for('blog'))
    
            else:
                abort(405)
        else:
            flash('Not authorized to do that')
            return redirect(url_for('blog'))
    else:
        try:
            post = BlogPost.get(BlogPost.id == post_id)
            if post.tags:
                tags = post.tags.split(',')
            return render_template('blog/show.html', post=post, tags=tags)
        except BlogPost.DoesNotExist:
            return redirect(url_for('blog'))
开发者ID:brendanWeb,项目名称:old-brendanhenderson.com,代码行数:67,代码来源:views.py


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