• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python models.DBSession类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: entity_type_delete

def entity_type_delete(request):
    dbsession = DBSession()
    name = clean_matchdict_value(request, 'entity_type')
    entity_type = dbsession.query(EntityType).filter(EntityType.name == name).one()
    dbsession.delete(entity_type)
    transaction.commit()
    return {'status': 'success'}
开发者ID:vishakh,项目名称:metamkt,代码行数:7,代码来源:views.py


示例2: event_delete

def event_delete(request):
    dbsession = DBSession()
    id = clean_matchdict_value(request, 'event')
    event = dbsession.query(Event).filter(Event.id == id).one()
    dbsession.delete(event)
    transaction.commit()
    return {'status': 'success'}
开发者ID:vishakh,项目名称:metamkt,代码行数:7,代码来源:views.py


示例3: user_get

def user_get(request):
    dbsession = DBSession()
    name = clean_matchdict_value(request, 'user')
    user = dbsession.query(User).filter(User.name == name).one()
    user_data = dbsession.query(UserData).filter(UserData.user_id == user.id).one()
    user_json = convert.decodeUser(request, dbsession, user, user_data)
    return {'status': 'success', 'user': user_json}
开发者ID:vishakh,项目名称:metamkt,代码行数:7,代码来源:views.py


示例4: action_delete

def action_delete(request):
    dbsession = DBSession()
    name = clean_matchdict_value(request, 'action')
    action = dbsession.query(Action).filter(Action.name == name).one()
    dbsession.delete(action)
    transaction.commit()
    return {'status': 'success'}
开发者ID:vishakh,项目名称:metamkt,代码行数:7,代码来源:views.py


示例5: filemonitoring

    def filemonitoring(self):
        log = logging.getLogger(__name__)
        if self._request.params:
            # TODO: add this information to the file
            md5_enabled = True if 'withmd5' in self._request.params and self._request.params['withmd5'] == '0' else False
            all_files = self._request.params.getall('file')

            complete_file, filenames, folders = self._get_monitored_files(self._request.params['folder'] + '/')

            with transaction.manager:
                for f in all_files:
                    if f in complete_file:
                        log.debug('Skipping file {0}, because it is already monitored'.format(f))
                        continue
                    (path, filename) = os.path.split(f)
                    dbobj = MonitoredFile(path, filename, f)
                    DBSession.add(dbobj)
                DBSession.commit()
            files_not_mentioned = [c for c in complete_file if c not in all_files]
            # TODO: decide on this
            log.info('TODO: Still have to decide whether files which are not selected should be deleted or not.'
                     'Affected files would be: {0}'.format(files_not_mentioned))
        else:
            log.info('Got an empty request, going to redirect to start page')
            subreq = Request.blank('/')
            return self._request.invoke_subrequest(subreq)

        subreq = Request.blank(self._request.route_path('filebrowser'),
                               POST=dict(folder=self._request.params['folder'],
                                         currentfolder=self._request.params['currentfolder'],
                                         pathdescription='abs'))
        return self._request.invoke_subrequest(subreq)
开发者ID:meyerjo,项目名称:ClusterJobMonitor,代码行数:32,代码来源:fileviews.py


示例6: user_delete

def user_delete(request):
    dbsession = DBSession()
    name = clean_matchdict_value(request, 'user')
    user = dbsession.query(User).filter(User.name == name).one()
    dbsession.delete(user)
    transaction.commit()
    return {'status': 'success'}
开发者ID:vishakh,项目名称:metamkt,代码行数:7,代码来源:views.py


示例7: group_delete

def group_delete(request):
    dbsession = DBSession()
    name = clean_matchdict_value(request, 'group')
    group = dbsession.query(Group).filter(Group.name == name).one()
    dbsession.delete(group)
    transaction.commit()
    return {'status': 'success'}
开发者ID:vishakh,项目名称:metamkt,代码行数:7,代码来源:views.py


示例8: job_output

    def job_output(self):
        log = logging.getLogger(__name__)

        jobid = self._request.matchdict['jobid']
        log.info('Request job output for id:{0}'.format(jobid))

        ssh_holder = self._request.registry.settings['ssh_holder']
        ssh_jobmanager = SSHBasedJobManager(ssh_holder)

        jobs = self._get_current_jobs(ssh_jobmanager, self._coltitles)
        joboutput = ssh_jobmanager.get_job_output(jobid)

        if 'error' in joboutput and joboutput['error'] is None:
            db_joboutput = JobOutput(id=jobid, output=jsonpickle.encode(joboutput))
            DBSession.add(db_joboutput)
            DBSession.commit()

        if 'error' in joboutput and joboutput['error'] is not None:
            jobresult = joboutput['error']
        else:
            jobresult = joboutput['content']
            jobresult = ''.join(jobresult)
        if 'type' not in joboutput:
            joboutput['type'] = 'type field missing'

        return {'project': self._projectname,
                'jobs': jobs,
                'output': dict(jobid=jobid, output=jobresult, type=joboutput['type'])}
开发者ID:meyerjo,项目名称:ClusterJobMonitor,代码行数:28,代码来源:views.py


示例9: is_allowed

def is_allowed(request, routename, method='ALL', check_route=True):
    """
    Given a request_object, routename and method; returns True if current user has access to that route,
    otherwise returns False.

    If check_route if False, does not check the DB to see if the route is in the list of protected routes
    """

    if check_route:
        route = DBSession.query(RoutePermission).filter_by(route_name=routename).first()
        if not route:
            return True

    if not isinstance(method, list):
        method = [method, ]

    user_permissions = request.session.get('auth_user_permissions', [])
    if request.session.get('auth_static_permission', None):
        user_permissions.append(request.session.get('auth_static_permission', None))

    has_permission = DBSession.query(func.count(RoutePermission.permission)).filter(
                                            RoutePermission.route_name == routename).filter(
                                            RoutePermission.method.in_(method)).filter(
                                            RoutePermission.permission.in_(user_permissions)).scalar()

    if has_permission > 0:
        return True
    else:
        return False
开发者ID:AnamAtiq,项目名称:CDSR,代码行数:29,代码来源:auth.py


示例10: main

def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    LOG.debug("settings:{}".format(settings))
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    config = Configurator(settings=settings)
    config.include('pyramid_chameleon')
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_static_view('jasny-css', 'static/jasny-bootstrap/css', cache_max_age=3600)
    config.add_static_view('jasny-js', 'static/jasny-bootstrap/js', cache_max_age=3600)
    config.add_route('login', '/')
    config.add_route('logout', '/logout')
    config.add_route('show_empl', '/employee/{emp_no}',
                     factory=EmployeeRootFactory)
    config.add_route('show_dept', '/department/{dept_no}',
                     factory=DeptRootFactory)

    auth_engine = AuthEngine()
    config.add_settings(auth_engine=auth_engine)
    authn_policy = AuthTktAuthenticationPolicy(settings['secret_key'],
                                               callback=auth_engine.get_groups,
                                               hashalg='sha512')
    config.set_authentication_policy(authn_policy)
    config.set_authorization_policy(ACLAuthorizationPolicy())

    query_parser = FormQueryParser()
    config.add_settings(query_parser=query_parser)

    config.scan()

    return config.make_wsgi_app()
开发者ID:lseek,项目名称:empdb,代码行数:33,代码来源:__init__.py


示例11: post_entry

def post_entry(request):
	entry = m.Entry()
	entry.start_datetime = datetime.datetime.now()
	entry.updated_datetime = datetime.datetime.now()
	DBSession.add(entry)
	DBSession.flush()
	return entry.entry_id
开发者ID:aarongreenwald,项目名称:pim,代码行数:7,代码来源:views.py


示例12: login

def login(request):
    """Returns a tuple of (authenticated) uid, and a message string.
    If the user could not be authenticated (or they didn't try), the uid
    will be None. If the user successfully logged in, sets a session
    cookie for this session."""
    
    session = DBSession()

    uid = authenticated_userid(request)
    if uid:
        return session.query(User).get(uid), None

    if 'user' in request.params and 'passwd' in request.params:
        uid = request.params['user']
        passwd = request.params['passwd']
        user = session.query(User).get(uid)
        if not user:
            return None, "Invalid user or password."

        if user.check_pw(passwd):
            headers = remember(request, uid)
            request.response.headerlist.extend(headers)
            return user, "Logged in Successfully"
        else:
            return None, "Invalid user or password."
    else:
        return None, None
开发者ID:pflarr,项目名称:basic_site,代码行数:27,代码来源:security.py


示例13: make_admin

def make_admin(config_path):
    from intranet3.models import User
    user_login = sys.argv[-1]
    if len(sys.argv) < 4:
        print u"Provide user login"
        return

    session = DBSession()

    user = session.query(User).filter(User.email==user_login).first()

    if not user:
        print u"No such user: %s" % user_login
        return

    if 'admin' in user.groups:
        print u'Removing %s from group admin' % user.name
        groups = list(user.groups)
        groups.remove('admin')
        user.groups = groups
    else:
        print u'Adding %s to group admin' % user.name
        groups = list(user.groups)
        groups.append('admin')
        user.groups = groups

    session.add(user)
    transaction.commit()
开发者ID:pytlakp,项目名称:intranet-1,代码行数:28,代码来源:script.py


示例14: init_db

def init_db(config_path):
    setup_logging(config_path)
    settings = get_appsettings(config_path)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.create_all(engine)
    print 'Done'
开发者ID:pytlakp,项目名称:intranet-1,代码行数:7,代码来源:script.py


示例15: order_delete

def order_delete(request):
    dbsession = DBSession()
    name = clean_matchdict_value(request, 'order')
    order = dbsession.query(Order).filter(Order.id == id).one()
    dbsession.delete(order)
    transaction.commit()
    return {'status': 'success'}
开发者ID:vishakh,项目名称:metamkt,代码行数:7,代码来源:views.py


示例16: eventAdd

def eventAdd(request):
    
    eventName = request.POST['name']
    eventType = request.POST['type']
    eventDescription = request.POST['description']
  
    image = request.POST.getall('file')
    for i in image:
	imageId = uuid.uuid1()
	imageUrl = str(imageId)
	open('/home/mohit/intern/hallwala/HallWala/hallwala/images/%d.jpg' % (imageId), 'wb').write(i.file.read())

    for infile in glob.glob("/home/mohit/intern/hallwala/HallWala/hallwala/images/*.jpg"):
        im = Image.open(infile)
	# don't save if thumbnail already exists
	if infile[0:2] != "T_":
	# convert to thumbnail image
		im.thumbnail((128, 128), Image.ANTIALIAS)
	        # prefix thumbnail file with T_
	        im.save("T_" + infile, "JPEG")



    newEvent = Event(eventName,eventType,eventDescription)
    DBSession.add(newEvent)
    DBSession.flush()
   
    event = newEvent.getJSON()
    return {'event' : event}
开发者ID:m6394g,项目名称:pyramid,代码行数:29,代码来源:views.py


示例17: team_delete

def team_delete(request):
    dbsession = DBSession()
    name = clean_matchdict_value(request, 'team')
    entity = dbsession.query(Entity).filter(Entity.name == name).filter(Entity.parent_id == None).one()
    dbsession.delete(entity)
    transaction.commit()
    return {'status': 'success'}
开发者ID:vishakh,项目名称:metamkt,代码行数:7,代码来源:views.py


示例18: main

def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    config = Configurator(settings=settings)
    config.include('pyramid_mako')
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_route('index', '/')
    config.add_route('accueil', '/accueil')
    config.add_route('map', '/map')
    config.add_route('map_stop', '/map/{stop_id}')
    config.add_route('form_stop', '/form/{stop_id}')
    config.add_route('trip', '/trip/{trip_id}')
    config.add_route('test', '/test')
    config.add_route('test_map', '/test_map')
    config.add_route('stop_stop', '/stop/{stop_id}')
    config.add_route('savoir', '/savoir')
    config.add_route('json_stop', '/json_stop')
    config.add_route('json_stops', '/json_stops')
    config.add_route('json_hor', '/json_hor')
    config.add_route('json_map', '/json_map')
    config.add_route('json_form', '/json_form')
    config.add_route('json_trip', '/json_trip')
    config.scan()
    return config.make_wsgi_app()
开发者ID:philippechataignon,项目名称:easytan,代码行数:26,代码来源:__init__.py


示例19: main

def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    session_factory = UnencryptedCookieSessionFactoryConfig("lolololseekret")
    config = Configurator(settings=settings, session_factory=session_factory)
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_static_view('graphs', 'graphs')
    config.add_route('login', '/login')
    config.add_route('logout', '/logout')
    config.add_route('meal', '/meals/{date}')
    config.add_route('meal_edit', '/meals/edit/{date}')
    config.add_route('weight', '/weight')
    config.add_route('weight_add', '/weight/add/')
    config.add_route('home', '/')
    config.add_route('chat_add', '/chat/add')
    config.add_route('note_add', '/notes/add')
    config.add_route('workout', '/workouts/{date}')
    config.add_route('workout_edit', 'workouts/edit/{date}')
    config.add_route('recipe', '/recipes')
    config.add_route('recipe_view', '/recipes/{id}')
    config.add_route('recipe_add', '/recipes/add')
    config.scan()
    return config.make_wsgi_app()
开发者ID:kyphelps,项目名称:Health-Tracker,代码行数:25,代码来源:__init__.py


示例20: __init__

 def __init__(self, stmtrs):
     """ Initialize with *STMTRS Element """
     self.currency = stmtrs.find('CURDEF').text
     acctfrom = stmtrs.find(self._acctTag)
     self.account = acctfrom.instantiate()
     DBSession.add(self.account)
     self._init(stmtrs)
开发者ID:P-Laf,项目名称:ofxtools,代码行数:7,代码来源:Parser.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.Document类代码示例发布时间:2022-05-27
下一篇:
Python models.Customer类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap