当前位置: 首页>>代码示例>>Python>>正文


Python models.DBSession类代码示例

本文整理汇总了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'}
开发者ID:selfcommit,项目名称:pi_director,代码行数:27,代码来源:api.py

示例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()
开发者ID:PeterGrace,项目名称:pi_director,代码行数:34,代码来源:__init__.py

示例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)
开发者ID:selfcommit,项目名称:pi_director,代码行数:33,代码来源:ajax.py

示例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()
开发者ID:PeterGrace,项目名称:pi_director,代码行数:31,代码来源:initializedb.py

示例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()
开发者ID:selfcommit,项目名称:pi_director,代码行数:8,代码来源:api.py

示例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)
开发者ID:selfcommit,项目名称:pi_director,代码行数:9,代码来源:tests.py

示例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'}
开发者ID:selfcommit,项目名称:pi_director,代码行数:11,代码来源:ajax.py

示例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)
开发者ID:selfcommit,项目名称:pi_director,代码行数:13,代码来源:initializedb.py

示例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
开发者ID:selfcommit,项目名称:pi_director,代码行数:16,代码来源:controllers.py

示例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
开发者ID:selfcommit,项目名称:pi_director,代码行数:8,代码来源:security.py

示例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()
开发者ID:selfcommit,项目名称:pi_director,代码行数:17,代码来源:api.py

示例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()
开发者ID:selfcommit,项目名称:pi_director,代码行数:17,代码来源:LoginLogout.py

示例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
开发者ID:selfcommit,项目名称:pi_director,代码行数:8,代码来源:security.py

示例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}
开发者ID:selfcommit,项目名称:pi_director,代码行数:10,代码来源:ajax.py

示例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)
开发者ID:selfcommit,项目名称:pi_director,代码行数:21,代码来源:views.py


注:本文中的pi_director.models.models.DBSession类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。