本文整理汇总了Python中transaction.commit方法的典型用法代码示例。如果您正苦于以下问题:Python transaction.commit方法的具体用法?Python transaction.commit怎么用?Python transaction.commit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类transaction
的用法示例。
在下文中一共展示了transaction.commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_system_user
# 需要导入模块: import transaction [as 别名]
# 或者: from transaction import commit [as 别名]
def create_system_user(config):
log.info('Creating system user')
crypt = cryptacular.bcrypt.BCRYPTPasswordManager()
settings = config.registry.settings
try:
auth_model = config.registry.auth_model
s_user = settings['system.user']
s_pass = str(crypt.encode(settings['system.password']))
s_email = settings['system.email']
defaults = dict(
password=s_pass,
email=s_email,
groups=['admin'],
)
if config.registry.database_acls:
defaults['_acl'] = [(Allow, 'g:admin', ALL_PERMISSIONS)]
user, created = auth_model.get_or_create(
username=s_user, defaults=defaults)
if created:
transaction.commit()
except KeyError as e:
log.error('Failed to create system user. Missing config: %s' % e)
示例2: evolve_wg
# 需要导入模块: import transaction [as 别名]
# 或者: from transaction import commit [as 别名]
def evolve_wg(root, registry):
from novaideo.views.filter import find_entities
from novaideo.content.interface import IWorkingGroup
import transaction
contents = find_entities(interfaces=[IWorkingGroup])
len_entities = str(len(contents))
for index, wg in enumerate(contents):
if hasattr(wg, 'first_decision'):
wg.first_improvement_cycle = wg.first_decision
wg.reindex()
if index % 1000 == 0:
log.info("**** Commit ****")
transaction.commit()
log.info(str(index) + "/" + len_entities)
log.info('Working groups evolved.')
示例3: update_len_comments
# 需要导入模块: import transaction [as 别名]
# 或者: from transaction import commit [as 别名]
def update_len_comments(root, registry):
from novaideo.views.filter import find_entities
from novaideo.content.interface import ICommentable
import transaction
contents = find_entities(interfaces=[ICommentable])
len_entities = str(len(contents))
for index, content in enumerate(contents):
content.update_len_comments()
if index % 1000 == 0:
log.info("**** Commit ****")
transaction.commit()
log.info(str(index) + "/" + len_entities)
log.info('Len comments updated')
示例4: update_len_selections
# 需要导入模块: import transaction [as 别名]
# 或者: from transaction import commit [as 别名]
def update_len_selections(root, registry):
from novaideo.views.filter import find_entities, get_users_by_preferences
from novaideo.content.interface import ISearchableEntity
import transaction
contents = find_entities(interfaces=[ISearchableEntity])
len_entities = str(len(contents))
for index, content in enumerate(contents):
result = get_users_by_preferences(content)
content.len_selections = len(result)
if index % 1000 == 0:
log.info("**** Commit ****")
transaction.commit()
log.info(str(index) + "/" + len_entities)
log.info('Len comments updated')
示例5: evolve_alerts
# 需要导入模块: import transaction [as 别名]
# 或者: from transaction import commit [as 别名]
def evolve_alerts(root, registry):
from novaideo.views.filter import find_entities
from novaideo.content.interface import IAlert
from BTrees.OOBTree import OOBTree
import transaction
contents = find_entities(interfaces=[IAlert])
len_entities = str(len(contents))
for index, alert in enumerate(contents):
alert.users_toexclude = OOBTree()
alert.reindex()
if index % 1000 == 0:
log.info("**** Commit ****")
transaction.commit()
log.info(str(index) + "/" + len_entities)
log.info('Alerts evolved')
示例6: start
# 需要导入模块: import transaction [as 别名]
# 或者: from transaction import commit [as 别名]
def start(self, context, request, appstruct, **kw):
root = getSite()
user = get_current(request)
mask = user.get_mask(root) if hasattr(user, 'get_mask') else user
author = mask if appstruct.get('anonymous', False) and mask else user
answer = appstruct['_object_data']
context.addtoproperty('answers', answer)
answer.init_title()
answer.format(request)
answer.state = PersistentList(['published'])
answer.reindex()
if getattr(answer, 'option', None) is not None:
answer.question.add_selected_option(user, answer.option)
transaction.commit()
grant_roles(user=author, roles=(('Owner', answer), ))
answer.setproperty('author', author)
if appstruct.get('associated_contents', []):
answer.set_associated_contents(
appstruct['associated_contents'], author)
self._alert_users(context, request, author, answer)
context.reindex()
user.set_read_date(answer.channel, datetime.datetime.now(tz=pytz.UTC))
return {}
示例7: process
# 需要导入模块: import transaction [as 别名]
# 或者: from transaction import commit [as 别名]
def process(self, data):
""" submitted by user
send mail to manager
"""
req = Request.by_id(self.session, data['req_id'])
# send mail to manager
src = req.user.email
dst = req.user.manager_mail
if 'reminder' in data:
content = """A request from %s is still waiting your approval
Request details: %s""" % (req.user.name, req.summarymail)
else:
content = """New request from %s
Request details: %s""" % (req.user.name, req.summarymail)
try:
self.send_mail(sender=src, target=dst, request=req,
content=content)
# update request status after sending email
req.notified = True
except Exception as err:
self.log.exception('Error while sending mail')
req.flag_error(str(err), self.session)
self.session.flush()
transaction.commit()
示例8: test_view_testing_item
# 需要导入模块: import transaction [as 别名]
# 或者: from transaction import commit [as 别名]
def test_view_testing_item(self):
setRoles(self.portal, TEST_USER_ID, ['Manager'])
api.content.create(
type='TestingItem',
title='Bar',
description='This is a description',
container=self.portal,
)
import transaction
transaction.commit()
self.browser.open(self.portal_url + '/bar')
self.assertTrue('Bar' in self.browser.contents)
self.assertIn('This is a description', self.browser.contents)
示例9: setup_schema
# 需要导入模块: import transaction [as 别名]
# 或者: from transaction import commit [as 别名]
def setup_schema(command, conf, vars):
"""Place any commands to setup depotexample here"""
# Load the models
# <websetup.websetup.schema.before.model.import>
from depotexample import model
# <websetup.websetup.schema.after.model.import>
# <websetup.websetup.schema.before.metadata.create_all>
print("Creating tables")
model.metadata.create_all(bind=config['tg.app_globals'].sa_engine)
# <websetup.websetup.schema.after.metadata.create_all>
transaction.commit()
print('Initializing Migrations')
import alembic.config, alembic.command
alembic_cfg = alembic.config.Config()
alembic_cfg.set_main_option("script_location", "migration")
alembic_cfg.set_main_option("sqlalchemy.url", config['sqlalchemy.url'])
alembic.command.stamp(alembic_cfg, "head")
示例10: commit
# 需要导入模块: import transaction [as 别名]
# 或者: from transaction import commit [as 别名]
def commit(self,*args,**kw):
transaction.commit(*args,**kw)
示例11: __exit__
# 需要导入模块: import transaction [as 别名]
# 或者: from transaction import commit [as 别名]
def __exit__(self, exc_type=None, exc_value=None, exc_tb=None):
if exc_type is None:
if self.meta.should_pack():
_log.debug('Packing database')
self._db.pack()
transaction.commit()
else:
transaction.abort()
self._connection.close()
self._connection = None
self._db = None
示例12: reindex
# 需要导入模块: import transaction [as 别名]
# 或者: from transaction import commit [as 别名]
def reindex(self):
"""Regenerate product index."""
_log.info('Reindexing database')
del self._root['by_product']
bp = OOBTree.OOBTree()
for vuln in self._root['advisory'].values():
if vuln.nodes:
for prod in (n.product for n in vuln.nodes):
bp.setdefault(prod, [])
bp[prod].append(vuln)
self._root['by_product'] = bp
transaction.commit()
示例13: github_full_scan
# 需要导入模块: import transaction [as 别名]
# 或者: from transaction import commit [as 别名]
def github_full_scan(settings=None):
url_like = 'https://github.com/%/releases/download/%'
urls = DBSession.query(URL).filter_by(active=True).filter(URL.url.like(url_like)).all()
api_urls = []
if urls:
for url in urls:
(repouser, reponame) = github_parse_user_repo(url)
api_urls.append(github_user_repo_to_api(repouser, reponame))
api_urls = set(api_urls)
headers = {}
headers['User-Agent'] = 'Mozilla/5.0 (Nintendo 3DS; Mobile; rv:10.0) Gecko/20100101 TitleDB/1.0'
for github_api_url in api_urls:
userpass = json.load(open("private/github_credentials.json"))
req = requests.get(github_api_url, headers=headers, auth=(userpass['username'],userpass['password']))
data = json.loads(req.text)
#import pdb; pdb.set_trace()
if 'assets' in data:
for asset in data['assets']:
try:
with transaction.manager:
with DBSession.begin_nested():
titledb.magic.process_url(asset['browser_download_url'], settings=settings)
#transaction.commit()
except:
transaction.rollback()
else:
log.info("GitHub API Failure: %s", github_api_url)
示例14: test_all_uid
# 需要导入模块: import transaction [as 别名]
# 或者: from transaction import commit [as 别名]
def test_all_uid(db):
# Test for https://gist.github.com/micxjo/a097698b33fc4669b0b4
page = Page(title="Test page", text="Hello world")
with transaction.manager:
db.add(page)
del page
# Clear in-memory and on-disk caches
db._storage._cache.clear()
db._connection._cache.full_sweep()
for item in db[Page].all():
assert hasattr(item, "_p_uid")
del item
db._storage._cache.clear()
db._connection._cache.full_sweep()
for uid in db[Page].all_uids():
obj = db[Page][uid]
assert hasattr(obj, "_p_uid")
del obj
db._storage._cache.clear()
db._connection._cache.full_sweep()
uids = list(islice(db[Page].all_uids(), 10))
objs = db[Page][uids]
for obj in objs:
assert hasattr(obj, "_p_uid")
objs = list(db[Page].all())
obj = objs[0]
obj._p_activate()
assert hasattr(obj, "_p_uid")
objs[1].text += " xxx"
transaction.commit()
for obj in objs:
assert hasattr(obj, "_p_uid")
示例15: __init__
# 需要导入模块: import transaction [as 别名]
# 或者: from transaction import commit [as 别名]
def __init__(self, db, model):
"""
:param zerodb.DB db: Database to link model to
:param model: Data model (subclass of zerodb.models.Model)
"""
self._model = model
self._db = db
self._catalog_name = "catalog__" + model.__modelname__
self._intid_name = "store__" + model.__modelname__
if not transaction.manager._txn and \
(self._intid_name not in db._root or self._catalog_name not in db._root):
transaction.begin()
commit = True
else:
commit = False
if self._intid_name not in db._root:
_objects = model.create_store()
db._root[self._intid_name] = _objects
if self._catalog_name not in db._root:
_catalog = model.create_catalog()
db._root[self._catalog_name] = _catalog
if commit:
transaction.commit()