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


Python DBSession.query方法代码示例

本文整理汇总了Python中pi_director.models.models.DBSession.query方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.query方法的具体用法?Python DBSession.query怎么用?Python DBSession.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pi_director.models.models.DBSession的用法示例。


在下文中一共展示了DBSession.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_pi_info

# 需要导入模块: from pi_director.models.models import DBSession [as 别名]
# 或者: from pi_director.models.models.DBSession import query [as 别名]
def get_pi_info(uid):
    tags = []
    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.lastseen = datetime.now()
        row.description = ""
        row.orientation = 0
        row.browser = True
        DBSession.add(row)
        DBSession.flush()
    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:PeterGrace,项目名称:pi_director,代码行数:27,代码来源:controllers.py

示例2: view_api_screenshot_save

# 需要导入模块: from pi_director.models.models import DBSession [as 别名]
# 或者: from pi_director.models.models.DBSession import query [as 别名]
def view_api_screenshot_save(request):
    uid = request.matchdict['uid']
    imgblob = request.POST['screenshot'].file

    '''first, delete previous screenshot'''
    DBSession.query(Screenshot).filter(Screenshot.uuid == uid).delete()

    '''Now, lets make a new screenshot'''
    foo = Screenshot()
    foo.uuid = uid
    foo.image = imgblob.read()
    DBSession.add(foo)
    DBSession.flush()
开发者ID:selfcommit,项目名称:pi_director,代码行数:15,代码来源:api.py

示例3: view_api_log_save

# 需要导入模块: from pi_director.models.models import DBSession [as 别名]
# 或者: from pi_director.models.models.DBSession import query [as 别名]
def view_api_log_save(request):
    uid = request.matchdict['uid']
    pi_log = request.POST['pi_log']
    filename = request.POST['filename']
    DBSession.query(Logs).filter(
        Logs.uuid == uid).filter(
        Logs.filename == filename).delete()

    new_log = Logs()
    new_log.filename = filename
    new_log.uuid = uid
    new_log.log = pi_log
    DBSession.add(new_log)
    DBSession.flush()
开发者ID:selfcommit,项目名称:pi_director,代码行数:16,代码来源:api.py

示例4: make_an_admin

# 需要导入模块: from pi_director.models.models import DBSession [as 别名]
# 或者: from pi_director.models.models.DBSession import query [as 别名]
def make_an_admin(request):
    email=request.matchdict['email']

    '''First, make sure there aren't already admins in the system'''
    res=DBSession.query(UserModel).filter(UserModel.AccessLevel==2).first()
    if res != None:
        msg="User already an admin: {user}".format(user=res.email)
        return False
    user=DBSession.query(UserModel).filter(UserModel.email==email).first()
    if user == None:
        user=UserModel()
        user.email=email
        DBSession.add(user)
    user.AccessLevel=2
    DBSession.flush()    
    return True
开发者ID:selfcommit,项目名称:pi_director,代码行数:18,代码来源:user_controls.py

示例5: view_ajax_set_commands

# 需要导入模块: from pi_director.models.models import DBSession [as 别名]
# 或者: from pi_director.models.models.DBSession import query [as 别名]
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,代码行数:35,代码来源:ajax.py

示例6: get_pi_cmd_info

# 需要导入模块: from pi_director.models.models import DBSession [as 别名]
# 或者: from pi_director.models.models.DBSession import query [as 别名]
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,代码行数:18,代码来源:controllers.py

示例7: view_api_refresh_get

# 需要导入模块: from pi_director.models.models import DBSession [as 别名]
# 或者: from pi_director.models.models.DBSession import query [as 别名]
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,代码行数:29,代码来源:api.py

示例8: LookupUser

# 需要导入模块: from pi_director.models.models import DBSession [as 别名]
# 或者: from pi_director.models.models.DBSession import query [as 别名]
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,代码行数:10,代码来源:security.py

示例9: groupfinder

# 需要导入模块: from pi_director.models.models import DBSession [as 别名]
# 或者: from pi_director.models.models.DBSession import query [as 别名]
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,代码行数:10,代码来源:security.py

示例10: view_ajax_get_command_results

# 需要导入模块: from pi_director.models.models import DBSession [as 别名]
# 或者: from pi_director.models.models.DBSession import query [as 别名]
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,代码行数:12,代码来源:ajax.py

示例11: view_ajax_set_command_results

# 需要导入模块: from pi_director.models.models import DBSession [as 别名]
# 或者: from pi_director.models.models.DBSession import query [as 别名]
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,代码行数:13,代码来源:ajax.py

示例12: view_api_screenshow_show

# 需要导入模块: from pi_director.models.models import DBSession [as 别名]
# 或者: from pi_director.models.models.DBSession import query [as 别名]
def view_api_screenshow_show(request):
    uid = request.matchdict['uid']
    shot = DBSession.query(Screenshot).filter(Screenshot.uuid == uid).first()
    if shot:
        with BytesIO() as ss:
            ss.write(shot.image)
            return Response(content_type='image/png', content_length=len(ss.getvalue()), body=ss.getvalue())
    else:
        with BytesIO() as ss:
            emptypng = '89504E470D0A1A0A0000000D49484452000000010000000108000000003A7E9B550000000A4944' \
                       '4154789C63FA0F0001050102CFA02ECD0000000049454E44AE426082'.decode('hex')
            ss.write(emptypng)
            return Response(content_type='image/png', content_length=len(ss.getvalue()), body=ss.getvalue())
开发者ID:selfcommit,项目名称:pi_director,代码行数:15,代码来源:api.py

示例13: get_tagged_pis

# 需要导入模块: from pi_director.models.models import DBSession [as 别名]
# 或者: from pi_director.models.models.DBSession import query [as 别名]
def get_tagged_pis(tags):
    splitter = shlex.shlex(tags)
    splitter.whitespace += ','
    splitter.whitespace += ';'
    splitter.whitespace_split = True
    taglist = list(splitter)

    taglist_str = ""
    for tag in taglist:
        taglist_str += "\'{tag}\',".format(tag=tag)
    taglist_str = taglist_str.rstrip(taglist_str[-1:])

    tagged_pis = []

    if (len(taglist) > 1):
        query_str = """
    SELECT t1.uuid,count(*) AS ct
      FROM Tags t1
      JOIN Tags t2 ON t1.tag!=t2.tag AND t1.uuid==t2.uuid
     WHERE 1
       AND t1.tag IN ({taglist})
       AND t2.tag IN ({taglist})
  GROUP BY t1.uuid
    HAVING ct >= {args}
        """.format(taglist=taglist_str, args=len(taglist))

        result = DBSession.get_bind().execute(query_str)

        for row in result:
            tagged_pis.append(row[0])
    else:
        PisWithTags = DBSession.query(Tags).filter(Tags.tag.in_(taglist)).all()
        for pi in PisWithTags:
            tagged_pis.append(pi.uuid)

    PiList = DBSession.query(RasPi).filter(RasPi.uuid.in_(tagged_pis)).order_by(desc(RasPi.lastseen)).all()
    return PiList
开发者ID:selfcommit,项目名称:pi_director,代码行数:39,代码来源:controllers.py

示例14: view_api_ping

# 需要导入模块: from pi_director.models.models import DBSession [as 别名]
# 或者: from pi_director.models.models.DBSession import query [as 别名]
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,代码行数:19,代码来源:api.py

示例15: login_complete_view

# 需要导入模块: from pi_director.models.models import DBSession [as 别名]
# 或者: from pi_director.models.models.DBSession import query [as 别名]
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,代码行数:19,代码来源:LoginLogout.py


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