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


Python DataAccess.getHistoryOrdered方法代码示例

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


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

示例1: Data

# 需要导入模块: from Data.dataAccess import DataAccess [as 别名]
# 或者: from Data.dataAccess.DataAccess import getHistoryOrdered [as 别名]
class Data(object):
    exposed = True
    
    def __init__(self):
        self._dao = DataAccess()
        
    def GET(self, *args, **kwargs):
        if len(args) < 1:
            raise cherrypy.HTTPError(400)
        dataType = args[0]
        if len(args) > 1:
            dataKey = args[1]
        elif kwargs.has_key('key'):
            dataKey = kwargs['key']
        else:
            dataKey = None

        obj = None    
        if dataType == 'user':
            obj = {}
        elif dataType == 'robot':
            obj = {}
        elif dataType == 'events':
            if kwargs.has_key('tags'):
                tags = kwargs['tags'].split(',')
            else:
                tags = ()
            obj = self.getEventsOrdered(dataKey, tags)
        else :
            raise cherrypy.HTTPError(400)
        
        cherrypy.response.headers['Content-Type'] = 'application/json'
        return json.dumps(obj)
    
    def POST(self, *args, **kwargs):
        request = json.loads(cherrypy.request.body.read())
        if not request.has_key('historyId'):
            raise cherrypy.HTTPError(400)
        else:
            historyId = request['historyId']
            tags = request['tags']
            if type(tags) != tuple and type(tags) != list:
                tags = (tags, )
            if type(tags) == list:
                tags = tuple(tags)
            if self._dao.actionHistory.updateTags(historyId, tags) >= 0:
                return 'OK'
            else:
                raise cherrypy.HTTPError(500)


    def getEventsOrdered(self, key, tags):
        hists = self._dao.getHistoryOrdered(key, tags)
        #if len(events) == 0:
        #    raise cherrypy.HTTPError(404)
        
        for hist in hists:
            if hist['scenario'] != None:
                #hist['gifThUrl'] = 'images/th_%s.gif' % hist['scenario']
                hist['imageArt'] = 'images/%s.jpg' % hist['imageArt']
            for event in hist['events']:
                if event['imageId'] != None:
                    event['imageUrl'] = 'images/%s' % event['imageId']
                    event['imageThUrl'] = 'images/th_r%s.jpg' % event['imageId']
                event.pop('imageId')
                if event['imageOverheadId'] != None:
                    event['imageOverheadUrl'] = 'imagesOverhead/%s' % event['imageOverheadId']
                event.pop('imageOverheadId')

        return {'episodes': hists}

    def getEvents(self, key, tags):
        events = self._dao.getHistory(key, tags)
        #if len(events) == 0:
        #    raise cherrypy.HTTPError(404)
        
        for event in events:
            if event['imageId'] != None:
                event['imageUrl'] = 'images/%s' % event['imageId']
                event['imageThUrl'] = 'images/th_r%s.jpg' % event['imageId']
            event.pop('imageId')
            if event['imageOverheadId'] != None:
                event['imageOverheadUrl'] = 'imagesOverhead/%s' % event['imageOverheadId']
            event.pop('imageOverheadId')
            #if event['sensors'] != None and len(event['sensors']) > 0:
            #    event['sensorMapUrl'] = 'mapHistory/%s' % event['id']
            
        return {'Episodes': [{'Events': events}]}
开发者ID:uh-joan,项目名称:UHCore,代码行数:90,代码来源:actionHistory.py


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