本文整理汇总了Python中pyramid_zodbconn.get_connection函数的典型用法代码示例。如果您正苦于以下问题:Python get_connection函数的具体用法?Python get_connection怎么用?Python get_connection使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_connection函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: 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)
site.catalog = make_catalog()
index_doc(site)
index_doc(site["example_page"])
transaction.commit()
return root["site"]
开发者ID:chrisrossi,项目名称:zodb_presentation,代码行数:13,代码来源:application.py
示例17: external_login_complete
def external_login_complete(request):
profile = request.context.profile
email = ''
if 'verifiedEmail' in profile:
email = profile['verifiedEmail']
if 'emails' in profile:
emails = profile['emails']
email = emails[0]['value']
came_from = request.session.get('came_from', request.application_url)
connection = get_connection(request)
site_root = connection.root()['app_root']
principals = find_service(site_root, 'principals')
users = principals['users']
user = [user for user in users.values() if user.email == email]
if not user or not email:
return external_login_denied(request)
headers = remember(request, oid_of(user[0]))
request.session.flash('Welcome!', 'success')
return HTTPFound(location=came_from, headers=headers)
开发者ID:cguardia,项目名称:substanced_velruse,代码行数:19,代码来源:auth.py
示例18: go
def go(root, request, zodb_path, queue):
runner = None
try:
poconn = get_connection(request, 'postoffice')
runner = MailinRunner2(root, poconn.root(), zodb_path, queue)
runner()
transaction.commit()
p_jar = getattr(root, '_p_jar', None)
if p_jar is not None:
# Attempt to fix memory leak
p_jar.db().cacheMinimize()
except ConflictError:
transaction.abort()
log.info('ZODB conflict error: retrying later')
except:
transaction.abort()
raise
开发者ID:araymund,项目名称:karl,代码行数:21,代码来源:mailin.py
示例19: undo_one
def undo_one(request):
needle = 'hash:' + request.params['hash']
undo = None
conn = get_connection(request)
db = conn.db()
for record in db.undoInfo(): # by default, the last 20 transactions
description = record['description']
if needle in description:
undo = dict(record)
undo['clean_description'] = description.replace(needle, '')
break
if undo is None:
request.session.flash('Could not undo, sorry', 'error')
else:
try:
db.undo(undo['id'])
msg = 'Undone: %s' % undo['clean_description']
request.session.flash(msg, 'success')
except ZODB.POSException.POSError:
msg = 'Could not undo, sorry'
request.session.flash(msg, 'error')
return HTTPFound(request.referrer or request.mgmt_path(request.context))
开发者ID:ericrasmussen,项目名称:substanced,代码行数:22,代码来源:__init__.py
示例20: root_factory
def root_factory(cls, request, transaction=transaction,
get_connection=get_connection):
""" A classmethod which can be used as a Pyramid ``root_factory``.
It accepts a request and returns an instance of Site."""
# this is a classmethod so that it works when Site is subclassed.
conn = get_connection(request)
zodb_root = conn.root()
if not 'app_root' in zodb_root:
settings = request.registry.settings
password = settings.get(
'substanced.initial_password')
if password is None:
raise ConfigurationError(
'You must set a substanced.initial_password '
'in your configuration file')
username = settings.get(
'substanced.initial_login', 'admin')
email = settings.get(
'substanced.initial_email', '[email protected]')
app_root = cls(username, email, password)
zodb_root['app_root'] = app_root
transaction.commit()
return zodb_root['app_root']
开发者ID:ericrasmussen,项目名称:substanced,代码行数:23,代码来源:__init__.py
注:本文中的pyramid_zodbconn.get_connection函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论