本文整理汇总了Python中ming.odm.session函数的典型用法代码示例。如果您正苦于以下问题:Python session函数的具体用法?Python session怎么用?Python session使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了session函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: skip_last_updated
def skip_last_updated(model_cls):
skip_last_updated = getattr(session(model_cls)._get(), 'skip_last_updated', False)
session(model_cls)._get().skip_last_updated = True
try:
yield
finally:
session(model_cls)._get().skip_last_updated = skip_last_updated
示例2: test_send_no_configured_webhooks
def test_send_no_configured_webhooks(self, send_webhook):
self.wh.delete()
session(self.wh).flush(self.wh)
sender = RepoPushWebhookSender()
with h.push_config(c, app=self.git):
sender.send(dict(arg1=1, arg2=2))
assert_equal(send_webhook.post.call_count, 0)
示例3: test_edit_validation
def test_edit_validation(self):
invalid = M.Webhook(
type='invalid type',
app_config_id=None,
hook_url='http://httpbin.org/post',
secret='secret')
session(invalid).flush(invalid)
self.app.get(self.url + '/repo-push/%s' % invalid._id, status=404)
data = {'url': u'http://httpbin.org/post',
'secret': u'secret'}
self.create_webhook(data).follow()
wh = M.Webhook.query.get(hook_url=data['url'], type='repo-push')
# invalid id in hidden field, just in case
r = self.app.get(self.url + '/repo-push/%s' % wh._id)
data = {k: v[0].value for (k, v) in r.forms[0].fields.items()}
data['webhook'] = unicode(invalid._id)
self.app.post(self.url + '/repo-push/edit', data, status=404)
# empty values
data = {'url': '', 'secret': '', 'webhook': str(wh._id)}
r = self.app.post(self.url + '/repo-push/edit', data)
self.find_error(r, 'url', 'Please enter a value', 'edit')
data = {'url': 'qwe', 'secret': 'qwe', 'webhook': str(wh._id)}
r = self.app.post(self.url + '/repo-push/edit', data)
self.find_error(r, 'url',
'You must provide a full domain name (like qwe.com)', 'edit')
示例4: create
def create(self, **kwargs):
try:
entry = self.model(**request.json)
except Invalid as exc:
abort(400, exc.message)
session(entry).flush()
return entry
示例5: execute
def execute(cls, options):
models = [M.Post, ForumPost]
app_config_id = cls.get_tool_id(options.tool)
# Find all posts that have parent_id, but does not have actual parent
# and create fake parent for them
for model in models:
q = {'parent_id': {'$ne': None},
'app_config_id': app_config_id}
for chunk in chunked_find(model, q):
for post in chunk:
if not post.parent:
log.info('Creating deleted parent for %s %s',
model.__mongometa__.name, post._id)
c.project = post.app_config.project
slug = post.slug.rsplit('/', 1)[0]
full_slug = post.full_slug.rsplit('/', 1)[0]
author = c.project.admins()[0]
deleted_post = model(
_id=post.parent_id,
deleted=True,
text="Automatically created in place of deleted post",
app_id=post.app_id,
app_config_id=post.app_config_id,
discussion_id=post.discussion_id,
thread_id=post.thread_id,
author_id=author._id,
slug=slug,
full_slug=full_slug,
)
if options.dry_run:
session(deleted_post).expunge(deleted_post)
else:
session(deleted_post).flush(deleted_post)
示例6: test_update_limit
def test_update_limit(self, dt_mock):
_now = dt.datetime(2015, 02, 02, 13, 39)
dt_mock.datetime.utcnow.return_value = _now
assert_equal(self.wh.last_sent, None)
self.wh.update_limit()
session(self.wh).expunge(self.wh)
assert_equal(M.Webhook.query.get(_id=self.wh._id).last_sent, _now)
示例7: test_project_is_deleted
def test_project_is_deleted(self):
p = M.Project.query.get(shortname=self.p_shortname)
assert p is not None, 'Can not find project to delete'
self.run_script(['p/{}'.format(p.shortname)])
session(p).expunge(p)
p = M.Project.query.get(shortname=p.shortname)
assert p is None, 'Project is not deleted'
示例8: add_webhooks
def add_webhooks(suffix, n):
for i in range(n):
webhook = M.Webhook(
type='repo-push',
app_config_id=self.git.config._id,
hook_url='http://httpbin.org/{}/{}'.format(suffix, i),
secret='secret')
session(webhook).flush(webhook)
示例9: verify_and_remove_code
def verify_and_remove_code(self, user, code):
self.enforce_rate_limit(user)
rc = RecoveryCode.query.get(user_id=user._id, code=code)
if rc:
rc.query.delete()
session(rc).flush(rc)
return True
else:
raise InvalidRecoveryCode
示例10: test_subproject_is_deleted
def test_subproject_is_deleted(self):
p = M.Project.query.get(shortname='test/sub1')
assert p is not None, 'Can not find subproject to delete'
self.run_script(['p/test/sub1'])
session(p).expunge(p)
p = M.Project.query.get(shortname='test/sub1')
assert p is None, 'Project is not deleted'
p = M.Project.query.get(shortname='test')
assert p is not None, 'Parent project should not be deleted'
示例11: merge
def merge(merge_request_id):
from allura import model as M
mr = M.MergeRequest.query.get(_id=merge_request_id)
mr.app.repo.merge(mr)
mr.add_meta_post(changes={'Status': [mr.status, 'merged']})
mr.status = 'merged'
g.director.create_activity(c.user, 'merged', mr,
related_nodes=[c.project], tags=['merge-request'])
session(mr).flush(mr)
示例12: test_delete_with_reason
def test_delete_with_reason(self, log, post_event):
p = M.Project.query.get(shortname=self.p_shortname)
pid = p._id
assert p is not None, 'Can not find project to delete'
self.run_script(['-r', 'The Reason', 'p/{}'.format(p.shortname)])
session(p).expunge(p)
p = M.Project.query.get(shortname=p.shortname)
assert p is None, 'Project is not deleted'
log.info.assert_called_once_with('Purging %s Reason: %s', '/p/test-delete/', 'The Reason')
post_event.assert_called_once_with('project_deleted', project_id=pid, reason='The Reason')
示例13: subscribe
def subscribe(self, **kw):
threads = kw.pop('threads', [])
for t in threads:
thread = self.M.Thread.query.get(_id=t['_id'])
if t.get('subscription'):
thread.subscribe()
else:
thread.unsubscribe()
session(self.M.Thread)._get().skip_mod_date = True
session(self.M.Thread)._get().skip_last_updated = True
redirect(request.referer)
示例14: installable_tools_for
def installable_tools_for(project):
tools = []
for name, App in g.entry_points['tool'].iteritems():
cfg = M.AppConfig(project_id=project._id, tool_name=name)
app = App(project, cfg)
if app.installable:
tools.append(dict(name=name, app=App))
session(cfg).expunge(cfg) # prevent from saving temporary config to db
tools.sort(key=lambda t: (t['app'].status_int(), t['app'].ordinal))
return [t for t in tools
if t['app'].status in project.allowed_tool_status]
示例15: test_deleted_post
def test_deleted_post(self):
r = self._make_post('This is a post')
reply_form = r.html.find(
'div', {'class': 'edit_post_form reply'}).find('form')
post_link = str(reply_form['action']).rstrip('/')
_, slug = post_link.rsplit('/', 1)
r = self.app.get(post_link, status=200)
post = M.Post.query.get(slug=slug)
post.deleted = True
session(post).flush(post)
r = self.app.get(post_link, status=404)