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


Python Article.select_one方法代码示例

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


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

示例1: post

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import select_one [as 别名]
 def post(self):
     """Edit Artilce."""
     data = self.request.data(title='', tag='', category='', \
             raw_content='', old_tag='', created_at='')
     created_at = data.created_at
     title = data.title
     old_tag = data.old_tag
     tag = data.tag
     category = data.category
     raw_content = data.raw_content
     content = (markdown2.markdown(raw_content)).encode('utf-8')
     u_id = self.get_current_user()
     admin = User.get_by_primary_key(u_id)
     created_at_now = int(time.time())
     # new article
     if not created_at:
         article = Article(title=title,content=content,\
                 raw_content=raw_content,category=category, \
                 author=admin.name, created_at=created_at_now)
         article.insert()
         new_article = Article.select_one('created_at=?', created_at_now)
         article_id = new_article.id
         # tag
         tag_d = Tag.select_one('tag_name=?', tag)
         # tag doesn't exists
         if not tag_d:
             new_tag = Tag(tag_name=tag)
             new_tag.insert()
             get_tag = Tag.select_one('tag_name=?', tag)
             tag_id = get_tag.id
         # tag exists
         else:
             tag_id = tag_d.id
         article_tag = ArticleTag(article_id=article_id, tag_id=tag_id)
         article_tag.insert()
     # update old article
     else:
         article = Article(title=title, content=content, \
                 raw_content=raw_content, author=admin.name, \
                 category=category, created_at=created_at_now)
         article.update('created_at=?', created_at)
         new_article = Article.select_one('created_at=?', created_at_now)
         article_id = new_article.id
         old_tag = Tag.select_one('tag_name=?', old_tag)
         new_tag = Tag(tag_name=tag)
         other_article_tag = ArticleTag.select_all('tag_id=?', old_tag.id)
         # other article doesn't have this article
         if len(other_article_tag) >= 1:
             tag_id = old_tag.id
             new_tag.update('id=?', tag_id)
         # other article has this tag
         else:
             new_tag.insert()
             get_tag = Tag.select('tag_name=?', tag)
             tag_id = get_tag.id
         article_tag = ArticleTag(tag_id=tag_id)
         article_tag.update('article_id=?', article_id)
     self.redirect('/admin/articles')
开发者ID:damnever,项目名称:LTsite,代码行数:60,代码来源:urls.py

示例2: get

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import select_one [as 别名]
 def get(self):
     params = self.request.url_params
     print params
     category = params[0]
     which = params[1]
     article, comment, comments, user = None, None, None, None
     if category == 'article':
         # delete article and all related comments
         old_article = Article.select_one('created_at=?', which)
         article = old_article
         old_article.delete()
         old_comments = Comment.select_all('article_id=?', article.id)
         comments = old_comments
         if old_comments:
             for comment in old_comments:
                 comment.delete()
     elif category == 'user':
         old_user = User.select_one('id=?', which)
         user = old_user
         old_user.delete()
     elif category == 'comment':
         old_comment = Comment.select_one('id=?', which)
         comment = old_comment
         old_comment.delete()
     return self.render('_delete.html', article=article, comment=comment, \
             comments=comments, user=user)
开发者ID:damnever,项目名称:LTsite,代码行数:28,代码来源:urls.py


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