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


Python pyramid_zodbconn.get_connection函数代码示例

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


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

示例1: evolve_root_factory

def evolve_root_factory(request_or_connection):
    if isinstance(request_or_connection, (Request, DummyRequest)):
        conn = get_connection(request_or_connection)
    else:
        conn = request_or_connection
    zodb_root = conn.root()
    return zodb_root["repoze.evolution"]
开发者ID:rcommande,项目名称:papaye,代码行数:7,代码来源:factories.py

示例2: default_root_factory

def default_root_factory(request_or_connection):
    if isinstance(request_or_connection, (Request, DummyRequest)):
        conn = get_connection(request_or_connection)
    else:
        conn = request_or_connection
    zodb_root = conn.root()
    return zodb_root
开发者ID:rcommande,项目名称:papaye,代码行数:7,代码来源:factories.py

示例3: list_apartment

def list_apartment(request):
    places = Places(get_connection(request))
    ret = list()
    for apartment in places.list_apartments():
        data = {
            'address': {
                'city': apartment.address.city,
                'street': apartment.address.street,
                'housenumber': apartment.address.housenumber,
            },
            'contact': {
                'phone': apartment.contact.phone,
                'nickname': apartment.contact.nickname,
                'email': apartment.contact.email,
                'person_name': apartment.contact.person_name,
            },
            'info': {
                'memo': apartment.info.memo,
                'price': apartment.info.price,
                'available_since': str(apartment.info.available_since),
                'rooms': apartment.info.rooms,
                'sqm': apartment.info.sqm,
            },
        }
        ret.append(data)
    return ret
开发者ID:isbm,项目名称:swg,代码行数:26,代码来源:views.py

示例4: view_query

def view_query(request):
    conn = get_connection(request)
    root = conn.root()
    schema = Store_Number()
    myform = Form(schema, buttons=('submit',))
    if 'submit' in request.POST:
        controls = request.POST.items()
        try:
            appstruct = myform.validate(controls)
        except ValidationFailure, e:
            return {
                'project': 'Network Deployment Automation System',
                'page': root['app_root'],
                'form': e.render(),
                'values': False,
                }
        values = {
            'store_number': appstruct['store_number'],
            }     
        return {
            'project': 'Network Deployment Automation System',
            'page': root['app_root'],
            'form': myform.render(),
            'values': values
            }
开发者ID:yenlinsu,项目名称:training.python_web,代码行数:25,代码来源:views.py

示例5: db

    def db(self):

        from pyramid_zodbconn import get_connection
        conn = get_connection(self.request)
        db = conn.db()

        return db
开发者ID:wyldebeast-wunderliebe,项目名称:w20e.pycms,代码行数:7,代码来源:site.py

示例6: __init__

    def __init__(self, context, request=None):
        """Initialize application for each request
        """
        # Support initialization as a view class instance
        if issubclass(context.__class__, self.__class__):
            self.__dict__.update(context.__dict__)
            return

        # Continue initialization as a root object instance
        self.data = request  # 'request' is either None or a mockup db like {}
        self.request = context  # 'context' is the request for root_factory

        # Get database root from ZODB when no mockup db was given
        if self.data is None:
            self.data = get_connection(self.request).root()

        # Prepare database
        if not hasattr(self.data, "players"):
            self.data.players = Players()
        if not hasattr(self.data, "catalog"):
            self.data.catalog = Catalog()
            self.data.catalog["type"] = FieldIndex()
            self.data.catalog["size"] = FieldIndex()
            self.data.catalog["created"] = FieldIndex()
            self.data.catalog["player_id"] = FieldIndex()
            self.data.catalog["keywords"] = KeywordIndex()

        # Migrate data over possible schema changes
        migrate(self.data)

        # Set registered games (available games could be filtered here)
        self.games = dict(self.request.registry.getAdapters((self,), IGame))
开发者ID:datakurre,项目名称:TIEA221_Tyomuistipeli,代码行数:32,代码来源:app.py

示例7: groupfinder

def groupfinder(userid, request):
    conn = get_connection(request)
    app_root = conn.root()['cintra_root']
    userslogininfo = app_root['security']['userslogininfo']

    if userid in userslogininfo:
        return app_root['security']['groupsinfo'].get(userid, [])
开发者ID:charlesbo,项目名称:cintra,代码行数:7,代码来源:security.py

示例8: add_apartment

def add_apartment(request):
    ret = dict()
    places = Places(get_connection(request))

    if len(request.json_body) != 4:
        ret['error_code'] = 1
        ret['error_message'] = "JSON request is not correctly encoded"
    else:
        errors = list()
        rq_addr,rq_contact, rq_info, rq_apt = request.json_body

        rq_addr, err = _get_address(rq_addr)
        errors.append(err)
        rq_contact, err = _get_contact(rq_contact)
        errors.append(err)
        rq_info = _get_info(rq_info)
        if rq_addr and rq_contact and rq_info:
            rq_apt = _get_apartment(rq_apt, rq_addr, rq_contact, rq_info)
        else:
            rq_apt = None

        errors = [item for item in errors if item]
        if not errors and rq_apt:
            places.add_apartment(rq_apt)
            places.commit()
            ret['error_code'] = 0
            ret['error_message'] = 'Apartment has been added'
        else:
            ret['error_code'] = 2
            ret['error_message'] = ', '.join(errors)

    return ret
开发者ID:isbm,项目名称:swg,代码行数:32,代码来源:views.py

示例9: root_factory

    def root_factory(request, name='site'):
        def finished(request):
            # closing the primary also closes any secondaries opened
            now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
            elapsed = time.time() - before
            if elapsed > connstats_threshhold:
                loads_after, stores_after = connection.getTransferCounts()
                loads = loads_after - loads_before
                stores = stores_after - stores_before
                with open(connstats_file, 'a', 0) as f:
                    f.write('"%s", "%s", "%s", %f, %d, %d\n' %
                               (now,
                                request.method,
                                request.path_url,
                                elapsed,
                                loads,
                                stores,
                               )
                           )
                    f.flush()

        if connstats_file is not None:
            request.add_finished_callback(finished)

        # NB: Finished callbacks are executed in the order they've been added
        # to the request.  pyramid_zodbconn's ``get_connection`` registers a
        # finished callback which closes the ZODB database.  Because the
        # finished callback it registers closes the database, we need it to
        # execute after the "finished" function above.  As a result, the above
        # call to ``request.add_finished_callback`` *must* be executed before
        # we call ``get_connection`` below.

        # Rationale: we want the call to getTransferCounts() above to happen
        # before the ZODB database is closed, because closing the ZODB database
        # has the side effect of clearing the transfer counts (the ZODB
        # activity monitor clears the transfer counts when the database is
        # closed).  Having the finished callbacks called in the "wrong" order
        # will result in the transfer counts being cleared before the above
        # "finished" function has a chance to read their per-request values,
        # and they will appear to always be zero.
            
        connection = get_connection(request)
        if connstats_file is not None:
            before = time.time()
            loads_before, stores_before = connection.getTransferCounts()
        folder = connection.root()
        if name not in folder:
            bootstrapper = queryUtility(IBootstrapper, default=populate)
            bootstrapper(folder, name, request)

            # Use pgtextindex
            if 'pgtextindex.dsn' in settings:
                site = folder.get(name)
                index = lookup(KarlPGTextIndex)(get_weighted_textrepr)
                site.catalog['texts'] = index

            transaction.commit()

        return folder[name]
开发者ID:karlproject,项目名称:karlserve,代码行数:59,代码来源:instance.py

示例10: _to_python

 def _to_python(self,value,state):
     context = get_connection(state.request).root()['app_root']
     if value in context['users']:
         raise Invalid(
             'That username already exists.',
             value, state
         )
     return value
开发者ID:tojuhaka,项目名称:easyblog,代码行数:8,代码来源:schemas.py

示例11: groupfinder

def groupfinder(userid, request):
    conn = get_connection(request)
    app_root = conn.root()['cintra_root']
    users = app_root['users']

    if userid in users:
        user = users[userid]
        return user.group
开发者ID:charlesbo,项目名称:cintra1,代码行数:8,代码来源:security.py

示例12: user_root_factory

def user_root_factory(request_or_connection):
    if isinstance(request_or_connection, (Request, DummyRequest)):
        conn = get_connection(request_or_connection)
    else:
        conn = request_or_connection
    zodb_root = conn.root()
    if not "{}_root".format(APP_NAME) in zodb_root:
        return None
    return zodb_root[APP_ROOT_NAME]["user"]
开发者ID:rcommande,项目名称:papaye,代码行数:9,代码来源:factories.py

示例13: root_factory

def root_factory(request):
    conn = pyramid_zodbconn.get_connection(request)
    database = conn.root()
    if 'root' not in database:
        root = Root()
        database['root'] = root
        import transaction
        transaction.commit()
    return database['root']
开发者ID:ilogue,项目名称:ploy,代码行数:9,代码来源:webapp.py

示例14: pack

 def pack(self):
     conn = get_connection(self.request)
     try:
         days = int(self.request.POST["days"])
     except:
         self.request.session.flash("Invalid number of days", "error")
     conn.db().pack(days=days)
     self.request.session.flash("Database packed to %s days" % days)
     return HTTPFound(location=self.request.mgmt_path(self.context, "@@manage_db"))
开发者ID:ericrasmussen,项目名称:substanced,代码行数:9,代码来源:views.py

示例15: root_factory

def root_factory(request):
    connection = get_connection(request)
    root = connection.root()
    if not 'site' in root:
        root['site'] = site = Site(u'Sure, Bro!', front_page)
        site.upload_image('image/gif',
            pkg_resources.resource_stream('surebro', 'static/pyramid-ufo.gif'))
        site['example_page'] = Page('Example Page', example_page)
        transaction.commit()

    return root['site']
开发者ID:chrisrossi,项目名称:zodb_presentation,代码行数:11,代码来源:application.py


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