本文整理汇总了Python中pyramid_basemodel.Session.flush方法的典型用法代码示例。如果您正苦于以下问题:Python Session.flush方法的具体用法?Python Session.flush怎么用?Python Session.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid_basemodel.Session
的用法示例。
在下文中一共展示了Session.flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_playlist_get_all_empty
# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import flush [as 别名]
def test_playlist_get_all_empty(self):
from balistos.models.playlist import Playlist
playlist = Playlist.get('test_playlist')
Session.delete(playlist)
Session.flush()
self.assertEqual(0, Playlist.get_all().count())
self.assertIsNone(Playlist.get('test_playlist'))
示例2: includeme
# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import flush [as 别名]
def includeme(config):
registry = config.registry
config.include('pyramid_basemodel')
config.include('pyramid_tm')
config.set_request_property(lib.user_property, 'user')
if not registry.queryUtility(interfaces.IDBSession):
registry.registerUtility(Session, interfaces.IDBSession)
if not registry.queryUtility(interfaces.IUserClass):
registry.registerUtility(User, interfaces.IUserClass)
if not registry.queryUtility(interfaces.IConsumerClass):
registry.registerUtility(Consumer, interfaces.IConsumerClass)
if not registry.queryUtility(interfaces.IActivationClass):
registry.registerUtility(Activation, interfaces.IActivationClass)
settings = config.get_settings()
key = settings['api.key']
secret = settings.get('api.secret')
ttl = settings.get('api.ttl', DEFAULT_TTL)
session = Session()
with transaction.manager:
consumer = Consumer.get_by_key(key)
if not consumer:
consumer = Consumer(key=key)
consumer.secret = secret
consumer.ttl = ttl
session.add(consumer)
session.flush()
registry.consumer = consumer
示例3: test_add_pclip
# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import flush [as 别名]
def test_add_pclip(self):
from balistos.models.clip import PlaylistClip
from balistos.models.clip import Clip
from balistos.models.playlist import Playlist
from datetime import datetime
playlist = Playlist(uri='test', title=u'Test')
clip = Clip(
youtube_video_id='test',
title=u'Test',
likes=5,
image_url='test_url',
duration=1
)
Session.add(clip)
Session.add(playlist)
Session.flush()
pclip = PlaylistClip(
playlist=playlist,
clip=clip,
likes=0,
state=0,
added=datetime.now()
)
Session.add(pclip)
Session.flush()
pclip = PlaylistClip.get_by_playlist_and_clip(playlist, clip)
self.assertEqual(playlist, pclip.playlist)
self.assertEqual(clip, pclip.clip)
self.assertEqual(0, pclip.state)
self.assertEqual(0, pclip.likes)
示例4: test_user_get_all_empty
# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import flush [as 别名]
def test_user_get_all_empty(self):
from balistos.models.user import User
user = User.get_by_username('test_user')
Session.delete(user)
Session.flush()
self.assertEqual(0, User.get_all().count())
self.assertIsNone(User.get_by_username('test_user'))
示例5: get_or_create_user_by_email
# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import flush [as 别名]
def get_or_create_user_by_email(email, cls=User):
"""Gets or creates an user given an email."""
# If the email is in the database we just return its user.
# First try by confirmed then just any email.
db_email = Email.query.filter_by(address=email, is_confirmed=True).first()
if db_email:
return db_email.user
# Now just by email.
db_email = Email.query.filter_by(address=email).first()
if db_email:
return db_email.user
# If we got this far it doesn't exist, create a new user...
username = generate_random_digest(num_bytes=15)
# Build a dict with keys that the user_cls.factory method expects.
# Note that the raw password will be encrypted before being saved.
data = {
'password': '',
'username': username,
}
user = cls(**data)
Session.add(user)
db_email = Email(user=user, address=email)
Session.add(db_email)
Session.flush()
return user
示例6: includeme
# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import flush [as 别名]
def includeme(config):
registry = config.registry
settings = registry.settings
config.include('pyramid_basemodel')
config.include('pyramid_tm')
models = [
(IActivationClass, Activation),
(IUserClass, User),
(IUIStrings, UIStringsBase),
(IConsumerClass, Consumer),
(IDBSession, Session)
]
for iface, imp in models:
if not registry.queryUtility(iface):
registry.registerUtility(imp, iface)
if asbool(settings.get('basemodel.should_create_all', True)):
key = settings['api.key']
secret = settings.get('api.secret')
ttl = settings.get('api.ttl', auth.DEFAULT_TTL)
session = Session()
consumer = session.query(Consumer).filter(Consumer.key == key).first()
if not consumer:
with transaction.manager:
consumer = Consumer(key=key, secret=secret, ttl=ttl)
session.add(consumer)
session.flush()
示例7: test_clip_get_all_empty
# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import flush [as 别名]
def test_clip_get_all_empty(self):
from balistos.models.clip import Clip
clips = Clip.get_all()
for clip in clips:
Session.delete(clip)
Session.flush()
self.assertEqual(0, Clip.get_all().count())
self.assertIsNone(Clip.get('cpV0ygkmhP4'))
示例8: test_pclip_get_all_empty
# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import flush [as 别名]
def test_pclip_get_all_empty(self):
from balistos.models.clip import PlaylistClip
pclips = PlaylistClip.get_all()
for pclip in pclips:
Session.delete(pclip)
Session.flush()
self.assertEqual(0, PlaylistClip.get_all().count())
self.assertEqual(0, PlaylistClip.get_all().count())
示例9: test_add_playlist
# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import flush [as 别名]
def test_add_playlist(self):
from balistos.models.playlist import Playlist
playlist = Playlist(uri='test', title=u'Test')
Session.add(playlist)
Session.flush()
playlist = Playlist.get('test')
self.assertEqual('test', playlist.uri)
self.assertEqual(u'Test', playlist.title)
示例10: test_add_user_username_only
# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import flush [as 别名]
def test_add_user_username_only(self):
from balistos.models.user import User
user = User(username='test')
Session.add(user)
Session.flush()
user = User.get_by_username('test')
self.assertEqual('test', user.username)
self.assertIsNone(user.email)
self.assertIsNone(user.fullname)
示例11: create_user
# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import flush [as 别名]
def create_user(self, update_data=None):
user = User(**self.user_data)
Session.add(user)
# Flush to put to the DB and generate defaults
Session.flush()
if update_data:
for update in update_data.items():
setattr(user, update[0], update[1])
transaction.commit()
示例12: reset_continue
# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import flush [as 别名]
def reset_continue(self):
'''
Method that serves password reset page
'''
user = self.request.matchdict.get('user')
if self.check_csrf:
token = self.request.session.get_csrf_token()
else:
token = ''
if self.request.method == 'POST':
# if turned on, check for csrf token
if self.check_csrf and token != self.request.POST.get('token'):
return {'status': False,
'msg': self.request._('csrf-mismatch',
default='CSRF token did not match.',
domain='pyramid_fullauth'),
'token': token}
password = self.request.POST.get('password', None)
password_confirm = self.request.POST.get('confirm_password', None)
if password == password_confirm:
try:
self.request.registry.notify(BeforeReset(self.request, user))
validate_passsword(self.request, password, user)
user.reset_key = None
try:
Session.query(AuthenticationProvider).filter(
AuthenticationProvider.user_id == user.id,
AuthenticationProvider.provider == u'email').one()
except NoResultFound:
user.providers.append(
AuthenticationProvider(provider=u'email',
provider_id=user.id))
Session.flush()
except (ValidateError, AttributeError) as e:
return {'status': False, 'msg': str(e), 'token': token}
try:
self.request.registry.notify(AfterReset(self.request, user))
except HTTPFound as redirect:
return redirect
else:
return {'status': False,
'msg': self.request._('password-mismatch',
default='Password doesn\'t match',
domain='pyramid_fullauth'),
'token': token}
return {'status': True, 'token': token}
示例13: create_api_consumer
# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import flush [as 别名]
def create_api_consumer(target, connection, **kwargs):
key = settings['api.key']
secret = settings.get('api.secret')
ttl = settings.get('api.ttl', auth.DEFAULT_TTL)
session = Session()
consumer = session.query(Consumer).filter(Consumer.key == key).first()
if not consumer:
with transaction.manager:
consumer = Consumer(key=key, secret=secret, ttl=ttl)
session.add(consumer)
session.flush()
示例14: dispatch_user_notifications
# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import flush [as 别名]
def dispatch_user_notifications(user, user_notifications):
""" 4. for each channel loop and either write out a single or a batch dispatch task with the
NotificationDispatcher ids e.g: /dispatch_email, /dispatch_sms and etc.
"""
for ch in AVAILABLE_CHANNELS:
# XXX check for preferences e.g: and user.channel == ch
to_dispatch = [d for d in user_notifications if d.category == ch]
for dispatch in to_dispatch:
post_notification_dispatch(dispatch)
else:
print "nothing here", to_dispatch
Session.flush()
示例15: test_add_user
# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import flush [as 别名]
def test_add_user(self):
from balistos.models.user import User
user = User(
username='test',
email='[email protected]',
fullname=u'Főo čar'
)
Session.add(user)
Session.flush()
user = User.get_by_username('test')
self.assertEqual('test', user.username)
self.assertEqual('[email protected]', user.email)
self.assertEqual(u'Főo čar', user.fullname)