本文整理汇总了Python中pi_director.models.models.DBSession类的典型用法代码示例。如果您正苦于以下问题:Python DBSession类的具体用法?Python DBSession怎么用?Python DBSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DBSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: view_api_refresh_get
def view_api_refresh_get(request):
uid = request.matchdict['uid']
refresh_cmd={}
refresh_cmd['cmd']='su'
refresh_cmd['args']=['-c','/home/pi/refresh.sh','pi']
refresh_cmd['result']=''
row = DBSession.query(RasPi).filter(RasPi.uuid == uid).first()
if row is None:
return {'status': 'error'}
try:
# If there are already records to be run,
# we'll start with them in the array already
cmd_data = json.loads(row.requested_commands)
except (ValueError, TypeError):
cmd_data=[]
pass
cmd_data.append(refresh_cmd)
row.requested_commands = json.dumps(cmd_data)
DBSession.flush()
return {'status': 'OK'}
示例2: main
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
NotSoSecret = 'CIeUz0RK8fjRq1wJSrID'
authn_policy = AuthTktAuthenticationPolicy(NotSoSecret,
callback=groupfinder,
hashalg='sha512')
authz_policy = ACLAuthorizationPolicy()
session_factory = SignedCookieSessionFactory(NotSoSecret)
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.bind = engine
config = Configurator(settings=settings, root_factory=Root)
config.set_authentication_policy(authn_policy)
config.set_authorization_policy(authz_policy)
config.include('velruse.providers.google_oauth2')
config.set_session_factory(session_factory)
config.add_google_oauth2_login_from_settings(prefix='velruse.google.')
config.include('cornice')
config.include('pyramid_mako')
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_static_view('client_agent', 'client_agent', cache_max_age=3600)
config.add_route('home', '/')
config.add_route('tagged', '/tagged/{tags}')
config.add_route('users', '/users')
config.add_route('logout', '/logout')
config.add_route('redirectme', '/go/{uid}')
config.add_route('provision', '/provision')
config.add_route('logs', '/logs/{uuid}')
config.add_route('wall', '/wall/{tags}')
config.add_request_method(LookupUser, 'user', reify=True)
config.scan()
return config.make_wsgi_app()
示例3: view_ajax_set_commands
def view_ajax_set_commands(request):
uid = request.matchdict['uid']
response = request.json_body
row = DBSession.query(RasPi).filter(RasPi.uuid == uid).first()
if row is None:
return '{"status":"error"}'
# convert response into something with stable sorting
cmds = []
tmpcmds = sorted(response.items(), key=operator.itemgetter(0))
for tmptuple in tmpcmds:
# extract cmdid/cmd
cmdid = int(tmptuple[0])
cmd = tmptuple[1]['cmd']
del tmptuple[1]['cmd']
# extract arguments
tmpargs = sorted(tmptuple[1].items(), key=operator.itemgetter(0))
args = [item[1] for item in tmpargs]
# put into our cmd object in the correct order
cmds.insert(cmdid, {})
cmds[cmdid]['cmd'] = cmd
cmds[cmdid]['args'] = args
# command hasn't been run yet, so this is blank
cmds[cmdid]['result'] = ''
row.requested_commands = json.dumps(cmds)
DBSession.flush()
return str(cmds)
示例4: main
def main(argv=sys.argv):
if len(argv) < 2:
usage(argv)
config_uri = argv[1]
options = parse_vars(argv[2:])
setup_logging(config_uri)
settings = get_appsettings(config_uri, options=options)
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
with transaction.manager:
model = RasPi()
model.uuid = '11:22:33:44:55:66'
model.description = "Testing Pi"
model.url = "http://www.facebook.com"
model.orientation = 0
model.browser = True
model.lastseen = datetime.now()
DBSession.add(model)
tag = Tags()
tag.uuid = '11:22:33:44:55:66'
tag.tag = 'test'
DBSession.add(tag)
User = UserModel()
User.email = '[email protected]'
User.AccessLevel = 2
DBSession.add(User)
DBSession.flush()
示例5: view_api_post_new_tag
def view_api_post_new_tag(request):
uid=request.matchdict['uid']
tag=request.matchdict['tag']
newtag = Tags()
newtag.uuid=uid
newtag.tag=tag
DBSession.add(newtag)
DBSession.flush()
示例6: setUp
def setUp(self):
self.config = testing.setUp()
from sqlalchemy import create_engine
engine = create_engine('sqlite://')
from pi_director.models.models import (
Base,
RasPi,
)
DBSession.configure(bind=engine)
示例7: view_ajax_set_command_results
def view_ajax_set_command_results(request):
uid = request.matchdict['uid']
row = DBSession.query(RasPi).filter(RasPi.uuid == uid).first()
if row is None:
return {'status': 'error'}
row.requested_commands = ''
DBSession.flush()
return {'status': 'OK'}
示例8: main
def main(argv=sys.argv):
if len(argv) < 2:
usage(argv)
config_uri = argv[1]
options = parse_vars(argv[2:])
setup_logging(config_uri)
settings = get_appsettings(config_uri, options=options)
engine = engine_from_config(settings, "sqlalchemy.")
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
with transaction.manager:
model = RasPi(uuid="default", url="http://www.facebook.com")
DBSession.add(model)
示例9: get_pi_cmd_info
def get_pi_cmd_info(uid):
tags = []
row = DBSession.query(RasPi).filter(RasPi.uuid == uid).first()
if row is None:
return []
else:
try:
tagset = DBSession.query(Tags).filter(Tags.uuid==uid).all()
for tag in tagset:
tags.append(tag.tag)
except Exception:
pass
rowdict = row.get_dict()
rowdict['tags']=tags
return rowdict
示例10: LookupUser
def LookupUser(request):
userid=authenticated_userid(request)
try:
logging.debug("Looking up user session for %s", userid)
UserObject = DBSession.query(UserModel).filter(UserModel.email==userid).one()
return UserObject
except NoResultFound, e:
return None
示例11: view_api_ping
def view_api_ping(request):
uid = request.matchdict['uid']
now = datetime.now()
row = DBSession.query(RasPi).filter(RasPi.uuid == uid).first()
if row is None:
row = RasPi()
row.uuid = uid
row.url = "http://www.stackexchange.com"
row.landscape = True
row.orientation = 0
row.description = ""
row.lastseen = now
DBSession.add(row)
DBSession.flush()
示例12: login_complete_view
def login_complete_view(request):
context = request.context
result = {
'provider_type': context.provider_type,
'provider_name': context.provider_name,
'profile': context.profile,
'credentials': context.credentials,
}
email = context.profile['verifiedEmail']
try:
User = DBSession.query(UserModel).filter(UserModel.email==email).one()
except NoResultFound, e:
User = UserModel()
User.email = email
User.AccessLevel = 1
DBSession.add(User)
DBSession.flush()
示例13: groupfinder
def groupfinder(userid,request):
try:
user = DBSession.query(UserModel).filter(UserModel.email==userid).one()
if user is not None:
if user.AccessLevel >= 0:
return[AccessLevels[user.AccessLevel]]
except NoResultFound, e:
return None
示例14: view_ajax_get_command_results
def view_ajax_get_command_results(request):
uid = request.matchdict['uid']
row = DBSession.query(RasPi).filter(RasPi.uuid == uid).first()
if row is None:
return {'status': 'error'}
data = json.loads(row.requested_commands)
return {'status': 'OK', 'data': data}
示例15: redirect_me
def redirect_me(request):
uid = request.matchdict['uid']
url = "http://www.stackexchange.com"
try:
row = DBSession.query(RasPi).filter(RasPi.uuid==uid).first()
if row:
url = row.url
logging.info("UID {uid}: {page}".format(uid=row.uuid, page=url))
else:
row = RasPi()
row.uuid = uid
row.url = "http://www.stackexchange.com"
row.landscape = True
DBSession.add(row)
DBSession.flush()
logging.warn("UID {uid} NOT FOUND. ADDED TO TABLE WITH DEFAULT URL".format(uid=uid))
url = row.url
except Exception:
logging.error("Something went south with DB when searching for {uid}".format(uid=uid))
raise exc.HTTPFound(url)