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


Python DBSession.add方法代码示例

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


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

示例1: get_pi_info

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

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

示例3: main

# 需要导入模块: from pi_director.models.models import DBSession [as 别名]
# 或者: from pi_director.models.models.DBSession import add [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(uuid="default", url="http://www.facebook.com")
        DBSession.add(model)
开发者ID:selfcommit,项目名称:pi_director,代码行数:15,代码来源:initializedb.py

示例4: setUp

# 需要导入模块: from pi_director.models.models import DBSession [as 别名]
# 或者: from pi_director.models.models.DBSession import add [as 别名]
 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)
     Base.metadata.create_all(engine)
     with transaction.manager:
         model = RasPi(name='one', value=55)
         DBSession.add(model)
开发者ID:selfcommit,项目名称:pi_director,代码行数:15,代码来源:tests.py

示例5: view_api_screenshot_save

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

示例6: view_api_log_save

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

示例7: make_an_admin

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

示例8: login_complete_view

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

示例9: view_api_ping

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

示例10: redirect_me

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

示例11: main

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

示例12: view_json_set_pi

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


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