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


Python Category.description方法代码示例

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


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

示例1: new_category

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import description [as 别名]
def new_category():
    """ Add new category """

    # Check if the user is loged in
    if 'username' not in login_session:
        return redirect('/login')

    if request.method == 'POST':

        # Get data from the front-end
        name = request.form['name']
        description = request.form['description']

        # Put the data into a model
        category = Category(name=name, user_id=login_session['user_id'])

        # Save description if there are one
        if description:
            category.description = description

        session.add(category)
        session.commit()

        return redirect(url_for('categories'))

    return render_template('categories/new_category.html')
开发者ID:Ilyes-Hammadi,项目名称:sportia,代码行数:28,代码来源:views.py

示例2: post

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import description [as 别名]
    def post(self):
        json = {}
        if not self.current_user:
            json = {
                'error': 1,
                'msg': self._('Access denied')
            }
            self.write(json)
            return

        title = self.get_argument('title', None)
        slug = self.get_argument('slug', None)
        description = self.get_argument('description', '')
        # valid arguments
        if not title:
            json = {
                'error': 1,
                'msg': self._('Title field can not be empty')
            }
            self.write(json)
            return
        if not slug:
            json = {
                'error': 1,
                'msg': self._('Slug field can not be empty')
            }
            self.write(json)
            return
        elif self.get_category_by_slug(slug):
            json = {
                'error': 1,
                'msg': self._('Slug already exists')
            }
            self.write(json)
            return
        # create category
        category = Category()
        category.title = title
        category.slug = slug
        category.description = description
        self.db.add(category)
        self.db.commit()
        # delete cache
        keys = ['CategoryList', 'SystemStatus']
        self.cache.delete_multi(keys)

        json = {
            'error': 0,
            'msg': self._('Successfully created'),
            'category': {
                'id': category.id,
                'title': category.title,
                'slug': category.slug,
                'description': category.description,
                'permalink': category.permalink,
                'post_count': category.post_count
            }
        }
        self.write(json)
开发者ID:messense,项目名称:YaBlog,代码行数:61,代码来源:api.py

示例3: category

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import description [as 别名]
def category():
    loc = "nav-category"
    if request.method == "POST" and request.form["action"] == "insert":
        #insert new category
        description = request.form["description"]
        category_type = request.form["categorytype"]
        success = False

        category = Category(g.user.id, description, category_type)
        if not category.isExists():
            db.session.add(category)
            db.session.commit()
            success = (True if category.id != -1 else False)
        return render_template("category.html", success = success, locid = loc)
    elif request.method == "POST" and request.form["action"] == "add":
        #show add category
        return render_template("category.html", action = "add", locid = loc)
    elif request.method == "POST" and request.form["action"] == "edit":
        #show edit category
        category_id = request.form["categoryid"]
        return render_template("category.html", action = "edit", category = Category.query.filter_by(id=category_id).one(), locid = loc)
    elif request.method == "POST" and request.form["action"] == "fin-edit":
        #show finalise edit category
        category_id = request.form["categoryid"]
        description = request.form["description"]
        category_type = request.form["categorytype"]
        success = False

        category = Category(g.user.id, description, category_type)
        if not category.isExists():
            category = Category.query.get(category_id)
            category.description = description
            category.category_type = category_type
            db.session.commit()
            success = True

        return render_template("category.html", action = "edit-fin", success = success, locid = loc)
    elif request.method == "POST" and request.form["action"] == "delete":
        #delete category
        category_id = request.form["categoryid"]
        category = Category.query.get(category_id)
        db.session.delete(category)
        db.session.commit()
        return render_template("category.html", action = "delete-fin", locid = loc)
    else:
        #show category list
        rs = db.session.query(Category).filter_by(user_id=g.user.id)
        return render_template("category.html", action = "show", category = rs, locid = loc)
开发者ID:nicopineda,项目名称:somewebapp,代码行数:50,代码来源:app.py


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