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


Python Item.user_id方法代码示例

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


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

示例1: create

# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import user_id [as 别名]
def create():
    form = CreateItemForm(request.form)
    if request.method == 'POST' and form.validate():
        sheetmusic_id = form.sheetmusic_id.data
        sheetmusic = Sheetmusic.query.filter_by(id=sheetmusic_id).one()
        new_item = Item()
        form.populate_obj(new_item)

        new_item.user_id = g.user.id

        g.db.add(new_item)
        g.db.commit()

        for file in request.files.getlist('images'):
            if file:
                ext = file.filename.rsplit('.', 1)[-1]
                filename = g.user.username + '_' + str(uuid4()) + '.' + ext
                image = ItemImage(filename)
                save_image(file, filename)
                new_item._images.append(image)
        g.db.commit()

        flash("You just made a new item!", "success")
        return redirect(url_for('items.index', item_id=new_item.id))

    sheetmusic_id = int(request.args.get('sheetmusic_id', 0))
    if sheetmusic_id:
        form.sheetmusic_id.data = sheetmusic_id
    return render_template('items/create_item.html', form=form)
开发者ID:sohail288,项目名称:sheetswap,代码行数:31,代码来源:controllers.py

示例2: new_item

# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import user_id [as 别名]
def new_item(category_id):
    """ Route that renders the page to add a new item.

    This method validate that the user is logged in.
    The item is associated with the current logged in user.

    Args:
        category_id: The id of the category of the item to be added.

    Raises:
        If an error occurs the application will redirect to index page and a flash message
        will be displayed with the proper Exception message.
    """
    try:
        logged_in = 'username' in login_session
        if not logged_in:
            flash("You must be logged to perform this operation", category="error")
            return redirect(url_for('index'))
        form = ItemForm()
        item = Item()
        item.name = "New item"
        if form.validate_on_submit():
            form.populate_obj(item)
            item.user_id = login_session["user_id"]
            db_session.add(item)
            if len(secure_filename(form.photo.data.filename)) > 0:
                db_session.flush()
                filename = 'images/uploads/' + str(item.id) + '/' + \
                           secure_filename(form.photo.data.filename)
                ensure_dir('static/' + filename)
                form.photo.data.save('static/' + filename)
                item.image_path = filename
                db_session.add(item)
            db_session.commit()
            flash("Item '{}' successfully added".format(item.name))
            return redirect(url_for('get_item_by_category', category_id=item.category_id,
                                    item_id=item.id))
        else:
            categories = db_session.query(Category).order_by(Category.name).all()
            return render_template('new_item.html', categories=categories,
                                   active_category=int(category_id), item=item, form=form,
                                   logged_in=logged_in, login_session=login_session)
    except Exception as e:
        flash('An error has occurred: {}'.format(str(e)), 'error')
        return redirect(url_for('index'))
开发者ID:aristoteles-nunez,项目名称:Item-Catalog,代码行数:47,代码来源:app.py


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