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


Python queryhelper.QueryHelper类代码示例

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


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

示例1: put

    def put(self):
        """Update the parameters of terminal.
        """
        status = ErrorCode.SUCCESS
        try:
            data = DotDict(json_decode(self.request.body))
            tid = data.get('tid', None)
            # check tid whether exist in request and update current_user
            self.check_tid(tid)
            logging.info("[UWEB] Terminal request: %s, uid: %s, tid: %s",
                         data, self.current_user.uid, self.current_user.tid)
        except Exception as e:
            status = ErrorCode.ILLEGAL_DATA_FORMAT
            self.write_ret(status)
            return

        try:
            terminal = QueryHelper.get_available_terminal(
                self.current_user.tid, self.db)
            if not terminal:
                status = ErrorCode.LOGIN_AGAIN
                logging.error("[UWEB] The terminal with tid: %s does not exist,"
                              "  redirect to login.html",
                              self.current_user.tid)
                self.write_ret(status)
                return

            user = QueryHelper.get_user_by_uid(self.current_user.uid, self.db)
            if not user:
                status = ErrorCode.LOGIN_AGAIN
                logging.error("[UWEB] The user with uid: %s does not exist,"
                              "  redirect to login.html",
                              self.current_user.uid)
                self.write_ret(status)
                return

            # sql injection
            if data.has_key('corp_cnum') and not check_cnum(data.corp_cnum):
                status = ErrorCode.ILLEGAL_CNUM
                self.write_ret(status)
                return

            # NOTE: deprecated
            if data.has_key('white_list'):
                white_list = ":".join(data.white_list)
                if not check_sql_injection(white_list):
                    status = ErrorCode.ILLEGAL_WHITELIST
                    self.write_ret(status)
                    return

            self.update_terminal_db(data)
            # NOTE: wspush to client
            if status == ErrorCode.SUCCESS:
                WSPushHelper.pushS7(tid, self.db, self.redis)
            self.write_ret(status)
        except Exception as e:
            logging.exception("[UWEB] uid:%s, tid:%s update terminal info failed. Exception: %s",
                              self.current_user.uid, self.current_user.tid, e.args)
            status = ErrorCode.SERVER_BUSY
            self.write_ret(status)
开发者ID:jcsy521,项目名称:ydws,代码行数:60,代码来源:terminal.py

示例2: get

 def get(self):
     """Get activities.
     """
     status = ErrorCode.SUCCESS
     try:
         res = []
         timestamp = self.get_argument('timestamp', None)
         if timestamp is None:
             res = QueryHelper.get_activity_list(self.db)
         elif int(timestamp) == -1:
             res = QueryHelper.get_activity_avaliable(self.db)
         else:
             res = QueryHelper.get_activity_by_begintime(timestamp, self.db)
         for r in res:
             if r['filename']:
                 r['filepath'] = self.application.settings[
                     'activity_path'] + r['filename']
             else:
                 r['filepath'] = ''
             r['url'] = r['html_name']
             del r['filename']
             del r['html_name']
         self.write_ret(status,
                        dict_=DotDict(res=res))
     except Exception as e:
         logging.exception("[UWEB] Get activities failed. Exception: %s",
                           e.args)
         status = ErrorCode.SERVER_BUSY
         self.write_ret(status)
开发者ID:jcsy521,项目名称:ydws,代码行数:29,代码来源:activity.py

示例3: get

    def get(self):
        status = ErrorCode.SUCCESS
        try:
            category = int(self.get_argument('category', UWEB.APK_TYPE.YDWS))
            if category == UWEB.APK_TYPE.YDWS:  # 1
                #version_info = get_version_info("android")
                version_info = QueryHelper.get_version_info_by_category(
                    category, self.db)
            elif category == UWEB.APK_TYPE.YDWQ_MONITOR:  # 2
                version_info = QueryHelper.get_version_info_by_category(
                    category, self.db)
            elif category == UWEB.APK_TYPE.YDWQ_MONITORED:  # 3
                version_info = QueryHelper.get_version_info_by_category(
                    category, self.db)
            elif category == UWEB.APK_TYPE.YDWS_ANJIETONG:  # 4
                version_info = QueryHelper.get_version_info_by_category(
                    category, self.db)
            else:
                logging.info("[UWEB] Invalid category: %s",
                             category)

            self.write_ret(status,
                           dict_=DotDict(version_info=version_info))
        except Exception as e:
            logging.exception(
                "[UWEB] Android check update failed. Exception: %s", e.args)
            status = ErrorCode.SERVER_BUSY
            self.write_ret(status)
开发者ID:jcsy521,项目名称:ydws,代码行数:28,代码来源:checkupdate.py

示例4: get

 def get(self):
     category = int(self.get_argument('category', 2))
     if category == 2:  # ydws
         #version_info = get_version_info('android')
         download_info = get_download_count(category, self.db)
         version_info = QueryHelper.get_version_info_by_category(
             UWEB.APK_TYPE.YDWS, self.db)
         update_download_count(category, self.db)
         self.render('android_weixin.html',
                     versioncode=version_info.versioncode,
                     versionname=version_info.versionname,
                     versioninfo=version_info.versioninfo,
                     updatetime=version_info.updatetime,
                     filesize=version_info.filesize,
                     count=download_info.count)
     elif category == 3:  # ydwq_monitor
         version_info = QueryHelper.get_version_info_by_category(
             UWEB.APK_TYPE.YDWQ_MONITOR, self.db)
         url = "/static/apk/" + version_info['filename']
         self.redirect(url)
     elif category == 4:  # ydwq_monitored
         version_info = QueryHelper.get_version_info_by_category(
             UWEB.APK_TYPE.YDWQ_MONITORED, self.db)
         url = "/static/apk/" + version_info['filename']
         self.redirect(url)
     elif category == 5:  # ydws_anjietong
         version_info = QueryHelper.get_version_info_by_category(
             UWEB.APK_TYPE.YDWS_ANJIETONG, self.db)
         url = "/static/apk/" + version_info['filename']
         self.redirect(url)
开发者ID:jcsy521,项目名称:ydws,代码行数:30,代码来源:download.py

示例5: get

    def get(self):
        """Display profile of current user.
        """
        status = ErrorCode.SUCCESS
        try: 
            tid = self.get_argument('tid',None) 
            # check tid whether exist in request and update current_user
            self.check_tid(tid)

            profile = DotDict()
            # 1: user
            user = QueryHelper.get_user_by_uid(self.current_user.uid, self.db)
            if not user:
                status = ErrorCode.LOGIN_AGAIN
                logging.error("[UWEB] User does not exist, redirect to login.html. uid: %s.", 
                              self.current_user.uid)
                self.write_ret(status)
                return

            # 2: car 
            car = QueryHelper.get_car_by_tid(self.current_user.tid, self.db)            
            profile.update(user)
            profile.update(car)
            self.write_ret(status,
                           dict_=dict(profile=profile))
        except Exception as e:
            logging.exception("[UWEB] Get user profile failed. uid:%s, tid:%s, Exception: %s", 
                              self.current_user.uid, self.current_user.tid, e.args) 
            status = ErrorCode.SERVER_BUSY
            self.write_ret(status)
开发者ID:jcsy521,项目名称:ydws,代码行数:30,代码来源:profile.py

示例6: get

    def get(self):
        """Get terminal info.
        """
        status = ErrorCode.SUCCESS
        try:
            tid = self.get_argument('tid', None)
            # check tid whether exist in request and update current_user
            self.check_tid(tid)

            car_sets = DotDict()

            terminal = QueryHelper.get_available_terminal(self.current_user.tid, self.db)
            if not terminal:
                status = ErrorCode.LOGIN_AGAIN
                logging.error("[UWEB] The terminal with tid: %s does not exist,"
                              "  redirect to login.html",
                              self.current_user.tid)
                self.write_ret(status)
                return

            user = QueryHelper.get_user_by_mobile(terminal.owner_mobile, self.db)
            if not user:
                logging.error("[UWEB] The user with uid: %s does not exist,"
                              "  redirect to login.html", 
                              self.current_user.uid)
                self.clear_cookie(self.app_name)
                self.write_ret(ErrorCode.LOGIN_AGAIN)
                return

            # NOTE: deprecated.
            if terminal['mannual_status'] == 1:
                terminal['parking_defend'] = 0
            else:
                terminal['parking_defend'] = 1

            # NOTE: deprecated.
            whitelist = QueryHelper.get_white_list_by_tid(
                self.current_user.tid, self.db)

            car_info = QueryHelper.get_car_by_tid(
                self.current_user.tid, self.db)
            car = dict(corp_cnum=car_info.get('cnum', ''))

            # add tow dict: terminal, car. add two value: whitelist_1,
            # whitelist_2
            white_list = [terminal.owner_mobile]
            for item in whitelist:
                white_list.append(item['mobile'])

            car_sets.update(terminal)
            car_sets.update(car)
            car_sets.update(DotDict(white_list=white_list))
            self.write_ret(status,
                           dict_=dict(car_sets=car_sets))
        except Exception as e:
            status = ErrorCode.SERVER_BUSY
            logging.exception("[UWEB] uid: %s tid: %s get terminal failed. Exception: %s",
                              self.current_user.uid, self.current_user.tid, e.args)
            self.write_ret(status)
开发者ID:jcsy521,项目名称:ydws,代码行数:59,代码来源:terminal.py

示例7: post

    def post(self):
        """Get latest location of a terminal.
        """
        status = ErrorCode.SUCCESS
        res = {}
        try:
            data = DotDict(json_decode(self.request.body))
            mobile = str(data.mobile)
            token = data.token
            logging.info("[REALTIME] Request, data:%s", data)
        except Exception as e:
            status = ErrorCode.DATA_FORMAT_ILLEGAL
            logging.exception("[REALTIME] Invalid data format, body: %s, mobile: %s.",
                              self.request.body, mobile)
            self.write_ret(status)
            return

        try:
            status = self.basic_check(token, mobile)                             
            if status != ErrorCode.SUCCESS:
                self.write_ret(status)
                return
    
            terminal = QueryHelper.get_terminal_by_tmobile(mobile, self.db)
            tid = terminal.tid      
            location = QueryHelper.get_location_info(tid, self.db, self.redis)

            # check and make name valid
            if location and location['name'] is None:
                location['name'] = ''                            
            # check and make clatclon valid
            locations = [location,] 
            locations = get_locations_with_clatlon(locations, self.db) 
            location = locations[0]
            
            if (location and location.clatitude and location.clongitude):
                res = dict(lon=location.get('longitude', 0),
                           lat=location.get('latitude', 0),
                           clon=location.get('clongitude', 0),
                           clat=location.get('clatitude', 0),
                           timestamp=location.get('timestamp',0),
                           name=location.get('name',''),
                           type=location.get('type',0))
                 
            self.write_ret(status,
                           dict_=dict(res=res))

        except Exception as e:
            logging.exception("[REALTIME] sid: %s. Exception: %s",
                              mobile, e.args)
            status = ErrorCode.FAILED
            self.write_ret(status)     
开发者ID:jcsy521,项目名称:ydws,代码行数:52,代码来源:realtime.py

示例8: handle_charge_info

 def handle_charge_info(self, info):
     info = DotDict(info)
     self.db.execute("INSERT INTO T_CHARGE"
                     "  VALUES (NULL, %s, %s, %s)",
                     info.dev_id, info.content, info.timestamp)
     user = QueryHelper.get_user_by_tid(info.dev_id, self.db) 
     if not user:
         logging.error("[EVENTER] Cannot find USER of terminal: %s", info.dev_id)
         return
         
     sms_option = QueryHelper.get_sms_option_by_uid(user.owner_mobile, EVENTER.SMS_CATEGORY.CHARGE.lower(), self.db)
     if sms_option == UWEB.SMS_OPTION.SEND:
         logging.error("[EVENTER] do not send charge sms temporarily")
开发者ID:jcsy521,项目名称:ydws,代码行数:13,代码来源:packettask.py

示例9: get

 def get(self):
     """Just just to a new page. 
     """
     # NOTE: The se_id should can be found in platform.
     se_id = self.get_argument("se_id", "")
     single_event = QueryHelper.get_single_event_by_se_id(se_id, self.db)
     terminal = QueryHelper.get_terminal_info(single_event["tid"], self.db, self.redis)
     self.render(
         "single_point.html",
         single_id=single_event["sid"],
         alias=terminal["alias"],
         tid=single_event.get("tid", ""),
         start_time=single_event.get("start_time"),
         end_time=single_event.get("end_time"),
     )
开发者ID:jcsy521,项目名称:ydws,代码行数:15,代码来源:corpsingle.py

示例10: pushS4

    def pushS4(tid, db, redis):
        """
        S4
        Information about online, offline.

        e.g.

        res = []
        res.append(dict(tid='tid1',
                        login_status=1))
        res.append(dict(tid='tid2',
                        login_status=2))

        """

        res = []

        t = QueryHelper.get_terminal_info(tid, db, redis)
        if t:
            res.append(dict(tid=tid,
                            biz_type=t.get('biz_type', 0),
                            login_status=t['login'] if t['login'] == 0 else 1))

        packet = dict(packet_type="S4",
                      res=res)
        res = WSPushHelper.push_packet(tid, packet, db, redis)
开发者ID:jcsy521,项目名称:ydws,代码行数:26,代码来源:wspushhelper.py

示例11: get

    def get(self):
        status = ErrorCode.SUCCESS
        try:
            tid = self.get_argument('tid', None)
            # check tid whether exist in request and update current_user
            self.check_tid(tid)
            terminal = QueryHelper.get_available_terminal(tid, self.db)
            if not terminal:
                status = ErrorCode.LOGIN_AGAIN
                logging.error("[UWEB] The terminal with tid: %s does not exist, redirect to login.html", 
                               self.current_user.tid)
                self.write_ret(status)
                return
            else:
                terminal_info_key = get_terminal_info_key(self.current_user.tid)
                terminal_info = self.redis.getvalue(terminal_info_key)
                mannual_status = terminal_info['mannual_status']

            self.write_ret(status,
                           dict_=DotDict(defend_status=mannual_status,
                                         mannual_status=mannual_status,
                                         fob_status=terminal.fob_status))
        except Exception as e:
            logging.exception("[UWEB] uid:%s tid:%s get defend status failed. Exception: %s",
                              self.current_user.uid, self.current_user.tid, e.args)
            status = ErrorCode.SERVER_BUSY
            self.write_ret(status)
            return
开发者ID:jcsy521,项目名称:ydws,代码行数:28,代码来源:defend.py

示例12: pushS4

    def pushS4(self, op):
        """
        res = []
        res.append(dict(tid='tid1',
                        login_status=1))
        res.append(dict(tid='tid2',
                        login_status=2))
        """

        res = [] 
        corp = self.db.get("SELECT * FROM V_TERMINAL where tid = %s",
                            self.tid) 
        if corp:
            terminals = self.db.query("SELECT tid FROM V_TERMINAL WHERE cid= %s",
                                      corp['cid'])
            for terminal in terminals:
                t = QueryHelper.get_terminal_info(terminal['tid'], self.db, self.redis) 
                res.append(dict(tid=terminal['tid'],
                                biz_type=0,
                                login_status=t['login']))
        else:
            res = []

        packet = dict(packet_type="S4",
                      res=res)
        res = self.push(packet)

        return res
开发者ID:jcsy521,项目名称:ydws,代码行数:28,代码来源:wspush_checker.py

示例13: get_sms_status

    def get_sms_status(self, tmobile):
        """
        sms_status: 0,  // failded
                    1,  // sent
                    2,  // reached to terminal
                    3,  // terminal has connected to gataway
        """ 
        sms_status = 0
        terminal = QueryHelper.get_terminal_by_tmobile(tmobile, self.db)
        if terminal.login == GATEWAY.TERMINAL_LOGIN.ONLINE:
            sms_status = 3
        elif terminal.msgid:
            sms_status = 1
        else:
            sms = self.db.get("SELECT send_status, recv_status"
                              "  FROM T_SMS"
                              "  WHERE msgid = %s"
                              "  AND category = %s"
                              "  LIMIT 1",
                              terminal.msgid, SMS.CATEGORY.MT)
            if not sms:
                pass
            elif sms.recv_status == 0:
                sms_status = 2
            elif sms.send_status == 0:
                sms_status = 1

        return sms_status
开发者ID:jcsy521,项目名称:ydws,代码行数:28,代码来源:business.py

示例14: get

    def get(self):
        """Display smsoption of current user.

        workflow:
        if alarmoption is exist:
            return alarmoption 
        else:
            initialize the alarmoption
            return alarmoption 
        """
        status = ErrorCode.SUCCESS
        try:
            umobile = self.get_argument('umobile')
            logging.info(
                "[UWEB] Alarmoption request: %s", self.request.arguments)
        except Exception as e:
            status = ErrorCode.ILLEGAL_DATA_FORMAT
            logging.exception(
                "[UWEB] Invalid data format. Exception: %s", e.args)
            self.write_ret(status)
            return

        try:
            alarm_options = QueryHelper.get_alarm_options(umobile, self.db)
            self.write_ret(status,
                           dict_=dict(res=alarm_options))
        except Exception as e:
            logging.exception("[UWEB] Get alarmoption failed. umobile: %s, Exception: %s",
                              umobile, e.args)
            status = ErrorCode.SERVER_BUSY
            self.write_ret(status)
开发者ID:jcsy521,项目名称:ydws,代码行数:31,代码来源:alarmoption.py

示例15: update_terminal_dynamic_info

def update_terminal_dynamic_info(db, redis, location):
    """Update terminal's dynamic info in db and redis.
    Then inclues gps, gsm, pbat.
    """
    # db
    tid = location.dev_id
    fields = []

    # NOTE: only gps, gsm, pbat should be updated
    keys = ['gps', 'gsm', 'pbat']
    for key in keys:
        if location.get(key, None) is not None:
            fields.append(key + " = " + str(location[key]))
    set_clause = ','.join(fields)
    if set_clause:
        db.execute("UPDATE T_TERMINAL_INFO"
                   "  SET " + set_clause +
                   "  WHERE tid = %s",
                   tid)
    # redis
    terminal_info = QueryHelper.get_terminal_info(tid, db, redis)
    if terminal_info:
        terminal_info_key = get_terminal_info_key(tid)
        for key in terminal_info:
            value = location.get(key, None)
            if value is not None:
                terminal_info[key] = value
        redis.setvalue(terminal_info_key, terminal_info)
开发者ID:jcsy521,项目名称:ydws,代码行数:28,代码来源:public.py


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