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


Python DBSession.flush方法代码示例

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


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

示例1: get_pi_info

# 需要导入模块: from pi_director.models.models import DBSession [as 别名]
# 或者: from pi_director.models.models.DBSession import flush [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_ajax_set_commands

# 需要导入模块: from pi_director.models.models import DBSession [as 别名]
# 或者: from pi_director.models.models.DBSession import flush [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

示例3: main

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

示例4: view_api_refresh_get

# 需要导入模块: from pi_director.models.models import DBSession [as 别名]
# 或者: from pi_director.models.models.DBSession import flush [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

示例5: view_api_post_new_tag

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

示例6: view_ajax_set_command_results

# 需要导入模块: from pi_director.models.models import DBSession [as 别名]
# 或者: from pi_director.models.models.DBSession import flush [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

示例7: view_api_screenshot_save

# 需要导入模块: from pi_director.models.models import DBSession [as 别名]
# 或者: from pi_director.models.models.DBSession import flush [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

示例8: view_api_log_save

# 需要导入模块: from pi_director.models.models import DBSession [as 别名]
# 或者: from pi_director.models.models.DBSession import flush [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

示例9: make_an_admin

# 需要导入模块: from pi_director.models.models import DBSession [as 别名]
# 或者: from pi_director.models.models.DBSession import flush [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

示例10: login_complete_view

# 需要导入模块: from pi_director.models.models import DBSession [as 别名]
# 或者: from pi_director.models.models.DBSession import flush [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

示例11: view_api_ping

# 需要导入模块: from pi_director.models.models import DBSession [as 别名]
# 或者: from pi_director.models.models.DBSession import flush [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

示例12: redirect_me

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

示例13: view_json_set_pi

# 需要导入模块: from pi_director.models.models import DBSession [as 别名]
# 或者: from pi_director.models.models.DBSession import flush [as 别名]
def view_json_set_pi(request):
    # TODO: move into controller(s)
    uid = request.matchdict['uid']
    response = request.json_body

    row = DBSession.query(RasPi).filter(RasPi.uuid == uid).first()
    if row is None:
        row = RasPi()
        row.uuid = uid
    row.url = response['url']
    row.description = response['description']
    row.orientation = response['orientation']
    row.browser = response['browser']
    DBSession.add(row)
    DBSession.flush()
    rowdict = {
        'uuid': row.uuid,
        'url': row.url,
        'description': row.description,
        'orientation': row.orientation,
        'browser': row.browser
    }
    return rowdict
开发者ID:selfcommit,项目名称:pi_director,代码行数:25,代码来源:ajax.py

示例14: view_api_reqcommands_post

# 需要导入模块: from pi_director.models.models import DBSession [as 别名]
# 或者: from pi_director.models.models.DBSession import flush [as 别名]
def view_api_reqcommands_post(request):
    uid = request.matchdict['uid']
    results = request.json_body
    results['data'] = json.loads(results['data'])

    row = DBSession.query(RasPi).filter(RasPi.uuid == uid).first()
    if row is None:
        return {'status': 'error'}

    cmd_data = json.loads(row.requested_commands)
    new_data = []

    for i, cmdinfo in enumerate(cmd_data):
        if results['status'] == 'OK':
            cmdinfo['result'] = results['data'][i]
        else:
            cmdinfo['result'] = results['msg']

        new_data.append(cmdinfo)

    row.requested_commands = json.dumps(new_data)
    DBSession.flush()

    return {'status': 'OK'}
开发者ID:selfcommit,项目名称:pi_director,代码行数:26,代码来源:api.py

示例15: authorize_user

# 需要导入模块: from pi_director.models.models import DBSession [as 别名]
# 或者: from pi_director.models.models.DBSession import flush [as 别名]
def authorize_user(email):
    user=DBSession.query(UserModel).filter(UserModel.email==email).one()
    user.AccessLevel=2
    DBSession.flush()
开发者ID:selfcommit,项目名称:pi_director,代码行数:6,代码来源:user_controls.py


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