• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python context.store_context函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sqlalchemy_imageattach.context.store_context函数的典型用法代码示例。如果您正苦于以下问题:Python store_context函数的具体用法?Python store_context怎么用?Python store_context使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_store_context

def test_store_context():
    path = tempfile.mkdtemp()
    store = FileSystemStore(path, 'http://localhost/')
    with raises(ContextError):
        get_current_store()
    with raises(ContextError):
        current_store.get_current_object()
    store2 = Store()
    with store_context(store) as s:
        assert s is store
        assert get_current_store() is store
        assert current_store == store
        with store_context(store2) as s2:
            assert s2 is store2
            assert get_current_store() is store2
            assert current_store == store2
            with store_context(store) as s3:
                assert s3 is store
                assert get_current_store() is store
                assert current_store == store
            assert s2 is store2
            assert get_current_store() is store2
            assert current_store == store2
        assert s is store
        assert get_current_store() is store
        assert current_store == store
    with raises(ContextError):
        get_current_store()
    with raises(ContextError):
        current_store.get_current_object()
    shutil.rmtree(path)
开发者ID:RaminFP,项目名称:sqlalchemy-imageattach,代码行数:31,代码来源:context_test.py


示例2: newHobby

def newHobby(lizard_id):
    """newHobby: Displays new hobby creation form and posts new hobby to the
                database; requires login and that the logged-in user is also
                the user that created the lizard

    Arguments are derived from the url"""
    lizard = Lizard.query.filter_by(id=lizard_id).one()
    if request.method == "GET":
        with store_context(store):
            return render_template("newHobby.html",
                                   lizard=lizard,
                                   login_session=login_session)

    url = request.form.get("url")
    (url, error) = isURLImage(url)
    if error:
        return render_template("newHobby.html",
                               login_session=login_session,
                               lizard=lizard,
                               error=error)
    try:
        url_open = urlopen(url)
    except:
        error = "Unable to make a request to this URL: %s" % (url)
        return render_template("newHobby.html",
                               login_session=login_session,
                               lizard=lizard,
                               error=error)

    new_hobby = Hobby(
        name=request.form.get("name"),
        description=request.form.get("description"),
        lizard_id=lizard_id,
        user_id=lizard.user_id,
        picture_url=url)

    with store_context(store):
        new_hobby.picture.from_file(url_open)
        session.add(new_hobby)
        flash("New Hobby %s Successfully Created" % (new_hobby.name))
        session.commit()
        url_open.close()

    newest_hobby = Hobby.query.\
        filter_by(user_id=lizard.user_id).\
        order_by(db.desc("creation_instant")).limit(1)[0]

    change_log = ChangeLog(
        user_id=lizard.user_id,
        lizard_name=lizard.name,
        lizard_id=lizard_id,
        hobby_name=newest_hobby.name,
        hobby_id=newest_hobby.id,
        update_instant=newest_hobby.creation_instant,
        action="new",
        table="hobby")

    session.add(change_log)
    session.commit()
    return redirect(url_for("showHobby", lizard_id=lizard_id))
开发者ID:snackattas,项目名称:LizardApp,代码行数:60,代码来源:main.py


示例3: deleteLizard

def deleteLizard(lizard_id):
    """deleteLizard: Displays form to delete a lizard and posts that
                       information to the database; requires login

    Arguments are derived from the url"""
    lizard_to_delete = Lizard.query.filter_by(id=lizard_id).one()
    if request.method == "GET":
        with store_context(store):
            return render_template(
                "deleteLizard.html", lizard=lizard_to_delete,
                login_session=login_session)

    change_log = ChangeLog(
        user_id=lizard_to_delete.user_id,
        lizard_name=lizard_to_delete.name,
        update_instant=datetime.datetime.utcnow(),
        action="delete",
        table="lizard")

    session.add(change_log)

    Hobby.query.filter_by(lizard_id=lizard_to_delete.id).delete()
    session.delete(lizard_to_delete)
    flash("Lizard %s Successfully Deleted" % lizard_to_delete.name)
    with store_context(store):
        session.commit()
    return redirect(url_for("showLizard"))
开发者ID:snackattas,项目名称:LizardApp,代码行数:27,代码来源:main.py


示例4: deleteHobby

def deleteHobby(lizard_id, hobby_id):
    """deleteHobby: Displays form to delete an hobby and posts that information
                   to the database; requires login and that the logged-in user
                   is also the user that created the lizard

    Arguments are derived from the url"""
    lizard = Lizard.query.filter_by(id=lizard_id).one()
    hobby_to_delete = Hobby.query.\
        filter_by(id=hobby_id, lizard_id=lizard_id).one()
    if request.method == "GET":
        with store_context(store):
            return render_template("deleteHobby.html", lizard=lizard,
            hobby=hobby_to_delete, login_session=login_session)

    change_log = ChangeLog(
        user_id=hobby_to_delete.user_id,
        lizard_name=lizard.name,
        lizard_id=lizard_id,
        hobby_name=hobby_to_delete.name,
        update_instant=datetime.datetime.utcnow(),
        action="delete",
        table="hobby")

    session.add(change_log)
    session.delete(hobby_to_delete)
    flash("Hobby %s Successfully Deleted" % (hobby_to_delete.name))
    with store_context(store):
        session.commit()
    return redirect(url_for("showHobby", lizard_id=lizard_id))
开发者ID:snackattas,项目名称:LizardApp,代码行数:29,代码来源:main.py


示例5: test_from_blob_implicitly

def test_from_blob_implicitly(fx_session, tmp_store):
    with store_context(tmp_store):
        something = Something(name='some name')
        with open(os.path.join(sample_images_dir, 'iu.jpg'), 'rb') as f:
            expected = f.read()
            img = something.cover.from_blob(expected)
            assert something.cover.original is img
            with fx_session.begin():
                fx_session.add(something)
                assert something.cover.original is img
    assert something.cover.count() == 1
    assert img is something.cover.original
    with store_context(tmp_store):
        assert something.cover.make_blob() == expected
开发者ID:bpc,项目名称:sqlalchemy-imageattach,代码行数:14,代码来源:entity_test.py


示例6: test_from_blob_implicitly

def test_from_blob_implicitly(fx_session, fx_sample_image, tmp_store):
    filepath, mimetype, (width, height) = fx_sample_image
    with store_context(tmp_store):
        something = Something(name='some name')
        with open(filepath, 'rb') as f:
            expected = f.read()
            img = something.cover.from_blob(expected)
            assert something.cover.original is img
            with fx_session.begin():
                fx_session.add(something)
                assert something.cover.original is img
    assert something.cover.count() == 1
    assert img is something.cover.original
    with store_context(tmp_store):
        assert something.cover.make_blob() == expected
开发者ID:RaminFP,项目名称:sqlalchemy-imageattach,代码行数:15,代码来源:entity_test.py


示例7: showItem

def showItem(item_id):
    item = session.query(Item).get(item_id)
    with store_context(fs_store):
        picture_url = item.picture.locate()
    user_id = getUserID(login_session['email'])
    return render_template('item.html', item=item, login_session=login_session,
                           picture_url=picture_url, user_id=user_id)
开发者ID:osmdawy,项目名称:catalog,代码行数:7,代码来源:application.py


示例8: test_delete_from_persistence

def test_delete_from_persistence(fx_session, tmp_store):
    with store_context(tmp_store):
        something = Something(name='some name')
        with open(os.path.join(sample_images_dir, 'iu.jpg'), 'rb') as f:
            image = something.cover.from_file(f)
            assert something.cover.original is image
            with fx_session.begin():
                fx_session.add(something)
            assert something.cover.original is image
            args = ('samething-cover', image.object_id, image.width,
                    image.height, image.mimetype)
            fx_session.execute('INSERT INTO samething '
                               'SELECT * FROM something')
            fx_session.execute('INSERT INTO samething_cover '
                               'SELECT * FROM something_cover')
            f.seek(0)
            tmp_store.put_file(f, *(args + (False,)))
        cover = fx_session.query(SamethingCover) \
                          .filter_by(samething_id=something.id) \
                          .one()
        with fx_session.begin():
            fx_session.delete(cover)
        samething = fx_session.query(Samething).filter_by(id=something.id).one()
        assert samething.cover.original is None
        with raises(IOError):
            print(tmp_store.get_file(*args))
开发者ID:bpc,项目名称:sqlalchemy-imageattach,代码行数:26,代码来源:entity_test.py


示例9: fx_migration

def fx_migration(fx_session, fx_source_store):
    with store_context(fx_source_store):
        with fx_session.begin():
            a1 = Something(name='a1')
            fx_session.add(a1)
            with open(os.path.join(sample_images_dir, 'iu.jpg'), 'rb') as f:
                a1.cover.from_file(f)
            a1.cover.generate_thumbnail(height=480)
            a1.cover.generate_thumbnail(height=320)
            a1.cover.generate_thumbnail(height=160)
            a2 = Something(name='a2')
            fx_session.add(a2)
            with open(os.path.join(sample_images_dir, 'iu2.jpg'), 'rb') as f:
                a2.cover.from_file(f)
            b1 = Samething(name='b1')
            fx_session.add(b1)
            with open(os.path.join(sample_images_dir, 'asuka.jpg'), 'rb') as f:
                b1.cover.from_file(f)
            b1.cover.generate_thumbnail(height=375)
            b1.cover.generate_thumbnail(height=250)
            b1.cover.generate_thumbnail(height=125)
            b2 = Samething(name='b2')
            fx_session.add(b2)
            with open(os.path.join(sample_images_dir, 'shinji.jpg'), 'rb') as f:
                b2.cover.from_file(f)
开发者ID:bpc,项目名称:sqlalchemy-imageattach,代码行数:25,代码来源:migration_test.py


示例10: test_generate_thumbnail_implicitly

def test_generate_thumbnail_implicitly(fx_session, fx_sample_image, tmp_store):
    filepath, mimetype, (width, height) = fx_sample_image
    with store_context(tmp_store):
        something = Something(name='some name')
        with raises(IOError):
            something.cover.generate_thumbnail(ratio=0.5)
        with open(filepath, 'rb') as f:
            original = something.cover.from_file(f)
            assert something.cover.original is original
            double = something.cover.generate_thumbnail(ratio=2)
            thumbnail = something.cover.generate_thumbnail(height=height // 2)
            assert something.cover \
                            .generate_thumbnail(width=width * 2) is double
            with fx_session.begin():
                fx_session.add(something)
                assert something.cover.original is original
        assert something.cover.count() == 3
        assert original is something.cover.original
        assert double.size == (width * 2, height * 2)
        assert thumbnail.height == height // 2
        half_width = width // 2
        # workaround off-by-one error
        assert thumbnail.width in (half_width - 1, half_width, half_width + 1)
        half_width = thumbnail.width
        assert something.cover \
                        .generate_thumbnail(width=half_width) is thumbnail
        with fx_session.begin():
            x3 = something.cover.generate_thumbnail(width=width * 3)
        assert something.cover.count() == 4
        x3.size == (width * 3, height * 3)
开发者ID:RaminFP,项目名称:sqlalchemy-imageattach,代码行数:30,代码来源:entity_test.py


示例11: editItem

def editItem(item_id):
    if 'username' not in login_session:
        return redirect(url_for('showLogin'))
    item = session.query(Item).get(item_id)
    user_id = getUserID(login_session['email'])
    if item.user_id != user_id:
        response = make_response(
            json.dumps('You are not authorized to edit this item.'), 200)
        return response
    if request.method == 'POST':
        if request.form['item-name']:
            item.name = request.form['item-name']
        if request.form['description']:
            item.description = request.form['description']
        if request.files['item_photo']:
            try:
                with store_context(fs_store):
                    item.picture.from_file(request.files['item_photo'])
                    session.commit()
            except Exception:
                session.rollback()
                raise
        return redirect(url_for('showCategories'))
    else:
        categories = session.query(Category).order_by(asc(Category.name))
        return render_template('edititem.html', categories=categories,
                               item=item, login_session=login_session)
开发者ID:osmdawy,项目名称:catalog,代码行数:27,代码来源:application.py


示例12: post

    def post(self, *args, **kwargs):
        with store_context(store):
            message = self.db.query(Message).filter(Message.gid == kwargs.get('gid', 0)).first()
            if message is None:
                pass

            if message and message.id == message.thread.op().id:
                message.thread.deleted = True
                messages = self.db.query(Message).filter(Message.thread_id == message.thread_id).all()
                for mess in messages:
                    mess.deleted = True
                    if mess.picture:
                        try:
                            shutil.rmtree('%simages/%s' % (store.path, str(mess.id)))
                        except:
                            pass  # Ну нет, так нет
                        self.db.query(BoardImage).filter(BoardImage.message_gid == mess.id).delete()
            else:
                message.deleted = True
                if message.picture:
                    try:
                        shutil.rmtree('%simages/%s' % (store.path, str(message.id)))
                    except:
                        pass  # Что тут поделаешь...
                    self.db.query(BoardImage).filter(BoardImage.message_id == message.id).delete()
            self.db.commit()
            self.redirect(self.success_url)
开发者ID:Impish-,项目名称:echoba,代码行数:27,代码来源:views.py


示例13: createItem

def createItem():
    if 'username' not in login_session:
        return redirect(url_for('showLogin'))
    if request.method == 'POST':
        category = session.query(Category).filter_by(
            name=request.form['item-category']).first()
        newItem = Item()
        newItem.name = request.form['item-name']
        newItem.description = request.form['description']
        newItem.category = category
        newItem.user_id = getUserID(login_session['email'])
        try:
            with store_context(fs_store):
                if request.files['item_photo']:
                    newItem.picture.from_file(request.files['item_photo'])
                else:
                    newItem.picture.from_file(urlopen(dummy_item_photo))
                session.add(newItem)
                session.commit()
        except Exception:
            session.rollback()
            raise
        return redirect(url_for('showCategories'))
    else:
        categories = session.query(Category).order_by(asc(Category.name))
        return render_template('create_item.html', categories=categories,
                               login_session=login_session)
开发者ID:osmdawy,项目名称:catalog,代码行数:27,代码来源:application.py


示例14: delete_square

 def delete_square(self, square_id):
     with store_context(self.session_manager.fs_store):
         sess = self.session_manager.get_session()
         model = sess.query(Square).filter(Square.id == square_id).one()
         # self.delete_image(sess, model)
         sess.delete(model)
         sess.commit()
开发者ID:Nookie91,项目名称:RPG_Tracker,代码行数:7,代码来源:square_service.py


示例15: editLizard

def editLizard(lizard_id):
    """editLizard: Displays form to edit a lizard"s name and/or image url
                     and posts that information to the database; requires login

    Arguments are derived from the url"""
    edited_lizard = Lizard.query.filter_by(id=lizard_id).one()
    if request.method == "GET":
        with store_context(store):
            return render_template("editLizard.html",
                                   lizard=edited_lizard,
                                   login_session=login_session)

    url = request.form.get("url")
    (url, error) = isURLImage(url)
    if error:
        return render_template("editLizard.html",
                               login_session=login_session,
                               lizard=edited_lizard,
                               error=error)
    try:
        url_open = urlopen(url)
    except:
        error = "Unable to make a request to this URL: %s" % (url)
        return render_template("editLizard.html",
                               login_session=login_session,
                               lizard=edited_lizard,
                               error=error)

    change_log = ChangeLog(
        user_id=edited_lizard.user_id,
        lizard_name=request.form.get("name"),
        lizard_id=lizard_id,
        update_instant=datetime.datetime.utcnow(),
        action="update",
        table="lizard")

    edited_lizard.name = request.form.get("name")
    edited_lizard.picture_url = url
    # Add all info to session while in store_context
    with store_context(store):
        edited_lizard.picture.from_file(url_open)
        session.add(change_log)
        session.add(edited_lizard)
        flash("Lizard %s Successfully Edited"  % edited_lizard.name)
        session.commit()
        url_open.close()
    return redirect(url_for("showLizard"))
开发者ID:snackattas,项目名称:LizardApp,代码行数:47,代码来源:main.py


示例16: test_from_raw_file_implicitly

def test_from_raw_file_implicitly(fx_session, tmp_store):
    with store_context(tmp_store):
        something = Something(name='some name')
        with open(os.path.join(sample_images_dir, 'iu.jpg'), 'rb') as f:
            expected = f.read()
            f.seek(0)
            img = something.cover.from_raw_file(f, original=True)
            assert something.cover.original is img
            with fx_session.begin():
                fx_session.add(something)
                assert something.cover.original is img
    assert something.cover.count() == 1
    assert img is something.cover.original
    with store_context(tmp_store):
        with something.cover.open_file() as f:
            actual = f.read()
    assert actual == expected
开发者ID:bpc,项目名称:sqlalchemy-imageattach,代码行数:17,代码来源:entity_test.py


示例17: img_thumb

 def img_thumb(self):
     '''
         миниатюра(по идее в настройках борды будут задаваться размеры)
     '''
     with store_context(store):
         try:
             return self.picture.find_thumbnail(width=150).locate()
         except NoResultFound:
             return None
开发者ID:Impish-,项目名称:echoba,代码行数:9,代码来源:models.py


示例18: test_from_raw_file_implicitly

def test_from_raw_file_implicitly(fx_session, fx_sample_image, tmp_store):
    filepath, mimetype, (width, height) = fx_sample_image
    with store_context(tmp_store):
        something = Something(name='some name')
        with open(filepath, 'rb') as f:
            expected = f.read()
            f.seek(0)
            img = something.cover.from_raw_file(f, original=True)
            assert something.cover.original is img
            with fx_session.begin():
                fx_session.add(something)
                assert something.cover.original is img
    assert something.cover.count() == 1
    assert img is something.cover.original
    with store_context(tmp_store):
        with something.cover.open_file() as f:
            actual = f.read()
    assert actual == expected
开发者ID:RaminFP,项目名称:sqlalchemy-imageattach,代码行数:18,代码来源:entity_test.py


示例19: context_2

 def context_2():
     try:
         s = get_current_store()
     except ContextError:
         values.append('error')
     else:
         values.append(s)
     with store_context(store_2):
         values.append(get_current_store())
开发者ID:RaminFP,项目名称:sqlalchemy-imageattach,代码行数:9,代码来源:context_test.py


示例20: showLizard

def showLizard():
    "showLizard: Displays all lizards; requires login"
    lizards = Lizard.query.order_by(db.asc(Lizard.name)).all()
    total_lizards = len(lizards)
    with store_context(store):
        return render_template("lizard.html", lizards=lizards,
                               login_session=login_session,
                               recent_activity=recentActivity(),
                               pretty_date=pretty_date,
                               total_lizards=total_lizards)
开发者ID:snackattas,项目名称:LizardApp,代码行数:10,代码来源:main.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap