本文整理汇总了Python中apex.models.DBSession.query方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.query方法的具体用法?Python DBSession.query怎么用?Python DBSession.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apex.models.DBSession
的用法示例。
在下文中一共展示了DBSession.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_user
# 需要导入模块: from apex.models import DBSession [as 别名]
# 或者: from apex.models.DBSession import query [as 别名]
def create_user(**kwargs):
"""
::
from apex.lib.libapex import create_user
create_user(username='test', password='my_password', active='Y', group='group')
Returns: AuthUser object
"""
user = AuthUser()
if 'group' in kwargs:
try:
group = DBSession.query(AuthGroup). \
filter(AuthGroup.name==kwargs['group']).one()
user.groups.append(group)
except NoResultFound:
pass
del kwargs['group']
for key, value in kwargs.items():
setattr(user, key, value)
DBSession.add(user)
DBSession.flush()
return user
示例2: __acl__
# 需要导入模块: from apex.models import DBSession [as 别名]
# 或者: from apex.models.DBSession import query [as 别名]
def __acl__(self):
dbsession = DBSession()
groups = dbsession.query(AuthGroup.name).all()
defaultlist = [ (Allow, Everyone, 'view'),
(Allow, Authenticated, 'authenticated'),]
for g in groups:
defaultlist.append( (Allow, 'group:%s' % g, g[0]) )
return defaultlist
示例3: test_create_user
# 需要导入模块: from apex.models import DBSession [as 别名]
# 或者: from apex.models.DBSession import query [as 别名]
def test_create_user(self):
# create_user(**kwargs)
from apex.lib.libapex import create_user
from apex.models import (AuthUser,
DBSession)
create_user(username='libtest', password='password')
# check that auth_id, auth_user, auth_group are added
self.assertEqual('libtest', DBSession.query(AuthUser.login). \
filter(AuthUser.login=='libtest').one()[0])
示例4: create_user
# 需要导入模块: from apex.models import DBSession [as 别名]
# 或者: from apex.models.DBSession import query [as 别名]
def create_user(self, username):
user = AuthUser(username=username, password=self.data["password"], email=self.data["email"])
DBSession.add(user)
settings = get_current_registry().settings
if settings.has_key("apex.default_user_group"):
group = DBSession.query(AuthGroup).filter(AuthGroup.name == settings["apex.default_user_group"]).one()
user.groups.append(group)
DBSession.flush()
return user
示例5: apexid_from_token
# 需要导入模块: from apex.models import DBSession [as 别名]
# 或者: from apex.models.DBSession import query [as 别名]
def apexid_from_token(token):
""" Returns the apex id from the OpenID Token
"""
dbsession = DBSession()
auth = json.loads(dbsession.query(KeyStorage.value). \
filter(KeyStorage.key==token).one()[0])
if 'profile' in auth:
auth['id'] = auth['profile']['accounts'][0]['userid']
auth['provider'] = auth['profile']['accounts'][0]['domain']
return auth
return None
示例6: create_user
# 需要导入模块: from apex.models import DBSession [as 别名]
# 或者: from apex.models.DBSession import query [as 别名]
def create_user(self, auth_id, login):
id = DBSession.query(AuthID).filter(AuthID.id==auth_id).one()
user = AuthUser(
login=login,
password=self.data['password'],
email=self.data['email'],
)
id.users.append(user)
DBSession.add(user)
DBSession.flush()
return user
示例7: copy_game_to_step
# 需要导入模块: from apex.models import DBSession [as 别名]
# 或者: from apex.models.DBSession import query [as 别名]
def copy_game_to_step(game, step):
"""Make a copy of a game object, but only up to the step
(integer from 1 to 6)"""
new_game = Game()
for i in xrange(step):
attr_name = _STEPS[i] + "_id"
attached_object = game.__getattribute__(_STEPS[i])
new_game.__setattr__(attr_name, attached_object.id)
author = DBSession.query(PiktioProfile)\
.filter(PiktioProfile.id == attached_object.author_id).one()
new_game.authors.append(author)
return new_game
示例8: apexid_from_token
# 需要导入模块: from apex.models import DBSession [as 别名]
# 或者: from apex.models.DBSession import query [as 别名]
def apexid_from_token(token):
""" Returns the apex id from the OpenID Token
"""
dbsession = DBSession()
auth = json.loads(dbsession.query(KeyStorage.value). \
filter(KeyStorage.key==token).one()[0])
if 'profile' in auth:
id = apexid_from_url(auth['profile']['providerName'], \
auth['profile']['identifier'])
auth['apexid'] = id
return auth
return None
示例9: webhosts
# 需要导入模块: from apex.models import DBSession [as 别名]
# 或者: from apex.models.DBSession import query [as 别名]
def webhosts(request):
form = ProviderForm(request.POST)
providers = DBSession.query(Provider).order_by(Provider.name).all()
record = Provider()
if request.method == 'POST' and form.validate():
record = merge_session_with_post(record, request.POST.items())
DBSession.merge(record)
DBSession.flush()
return HTTPFound(location= \
route_url('apex_route53_webhosts', request))
return {'title':'Web Hosts', 'form':form, 'providers':providers}
示例10: apex_callback
# 需要导入模块: from apex.models import DBSession [as 别名]
# 或者: from apex.models.DBSession import query [as 别名]
def apex_callback(request):
""" apex_callback(request):
no return value, called with route_url('apex_callback', request)
This is the URL that Velruse returns an OpenID request to
"""
redir = request.GET.get('came_from', \
route_url(apex_settings('came_from_route'), request))
headers = []
if 'token' in request.POST:
auth = apexid_from_token(request.POST['token'])
if auth:
user = AuthUser.get_by_login(auth['id'])
if not user:
auth_info = auth['profile']['accounts'][0]
id = AuthID()
DBSession.add(id)
user = AuthUser(
login=auth_info['userid'],
provider=auth_info['domain'],
)
if auth['profile'].has_key('verifiedEmail'):
user.email = auth['profile']['verifiedEmail']
id.users.append(user)
if apex_settings('default_user_group'):
for name in apex_settings('default_user_group'). \
split(','):
group = DBSession.query(AuthGroup). \
filter(AuthGroup.name==name.strip()).one()
id.groups.append(group)
if apex_settings('create_openid_after'):
openid_after = get_module(apex_settings('create_openid_after'))
openid_after().after_signup(user)
DBSession.flush()
if apex_settings('openid_required'):
openid_required = False
for required in apex_settings('openid_required').split(','):
if not getattr(user, required):
openid_required = True
if openid_required:
request.session['id'] = id.id
request.session['userid'] = user.id
return HTTPFound(location='%s?came_from=%s' % \
(route_url('apex_openid_required', request), \
request.GET.get('came_from', \
route_url(apex_settings('came_from_route'), request))))
headers = apex_remember(request, user)
redir = request.GET.get('came_from', \
route_url(apex_settings('came_from_route'), request))
flash(_('Successfully Logged in, welcome!'), 'success')
return HTTPFound(location=redir, headers=headers)
示例11: referrer_update
# 需要导入模块: from apex.models import DBSession [as 别名]
# 或者: from apex.models.DBSession import query [as 别名]
def referrer_update(user, refer_id):
""" user = user object
refer_id = referring user ID
No return value
"""
try:
fkp = DBSession.query(ForeignKeyProfile). \
filter(ForeignKeyProfile.user_id==refer_id).one()
except:
fkp = ForeignKeyProfile(user_id = refer_id, score = 0)
fkp.score = fkp.score + 1
DBSession.merge(fkp)
try:
fkp = DBSession.query(ForeignKeyProfile). \
filter(ForeignKeyProfile.user_id==user.id).one()
except:
fkp = ForeignKeyProfile(user_id = user.id, score = 0)
fkp.parent_id = refer_id
DBSession.merge(fkp)
DBSession.flush()
示例12: create_user
# 需要导入模块: from apex.models import DBSession [as 别名]
# 或者: from apex.models.DBSession import query [as 别名]
def create_user(**kwargs):
"""
::
from apex.lib.libapex import create_user
create_user(username='test', password='my_password', active='Y')
Optional Parameters:
display_name
group
Returns: AuthID object
"""
auth_id = AuthID(active=kwargs.get('active', 'Y'))
if 'display_name' in kwargs:
auth_id.display_name = kwargs['display_name']
del kwargs['display_name']
user = AuthUser(login=kwargs['username'], password=kwargs['password'],
active=kwargs.get('active', 'Y'))
auth_id.users.append(user)
if 'group' in kwargs:
try:
group = DBSession.query(AuthGroup). \
filter(AuthGroup.name == kwargs['group']).one()
auth_id.groups.append(group)
except NoResultFound:
pass
del kwargs['group']
for key, value in list(kwargs.items()):
setattr(user, key, value)
DBSession.add(auth_id)
DBSession.add(user)
DBSession.flush()
return user
示例13: create_user
# 需要导入模块: from apex.models import DBSession [as 别名]
# 或者: from apex.models.DBSession import query [as 别名]
def create_user(self, login):
id = AuthID()
DBSession.add(id)
user = AuthUser(
login=login,
password=self.data['password'],
email=self.data['email'],
)
id.users.append(user)
DBSession.add(user)
settings = get_current_registry().settings
if settings.has_key('apex.default_user_group'):
group = DBSession.query(AuthGroup). \
filter(AuthGroup.name==settings['apex.default_user_group']).one()
id.groups.append(group)
DBSession.flush()
return user
示例14: change_password
# 需要导入模块: from apex.models import DBSession [as 别名]
# 或者: from apex.models.DBSession import query [as 别名]
def change_password(request):
""" change_password(request):
no return value, called with route_url('apex_change_password', request)
FIXME doesn't adjust auth_user based on local ID, how do we handle multiple
IDs that are local? Do we tell person that they don't have local
permissions?
"""
title = _('Change your Password')
came_from = get_came_from(request)
user = DBSession.query(AuthUser). \
filter(AuthUser.auth_id==authenticated_userid(request)). \
filter(AuthUser.provider=='local').first()
form = ChangePasswordForm(request.POST, user_id=user.id)
if request.method == 'POST' and form.validate():
#user = AuthID.get_by_id(authenticated_userid(request))
user.password = form.data['password']
DBSession.merge(user)
DBSession.flush()
return HTTPFound(location=came_from)
return {'title': title, 'form': form, 'action': 'changepass'}
示例15: __call__
# 需要导入模块: from apex.models import DBSession [as 别名]
# 或者: from apex.models.DBSession import query [as 别名]
def __call__(self, form, field):
message = _('"%s" is an already existing group.')
data = field.data
item = DBSession.query(AuthGroup).filter(AuthGroup.name == data).first()
if item is not None:
raise ValidationError(message % field.data)