本文整理汇总了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"]
示例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
示例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
示例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
}
示例5: db
def db(self):
from pyramid_zodbconn import get_connection
conn = get_connection(self.request)
db = conn.db()
return db
示例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))
示例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, [])
示例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
示例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]
示例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
示例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
示例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"]
示例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']
示例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"))
示例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']