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


Python User.get_user_by_phones方法代码示例

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


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

示例1: ShowHandler

# 需要导入模块: from model.User import User [as 别名]
# 或者: from model.User.User import get_user_by_phones [as 别名]
class ShowHandler(tornado.web.RequestHandler):
    def initialize(self, mysql_handler, LOG):
        self.mysql_handler = mysql_handler
        self.LOG = LOG
        self.user = User(mysql_handler, LOG)
        self.device = Device(mysql_handler, LOG)
        self.favorite = Favorite(mysql_handler, LOG)
        self.picture = Picture(mysql_handler, LOG)
        self.device_attribute = DeviceAttribute(mysql_handler, LOG)
        self.rsp_handler = CommResponse()
        return

    def post(self):
        self.LOG.debug('this is %s' % self.__class__.__name__)
        try:
            request_json = json.loads(self.request.body)
            user_phone = request_json['user_phone']
            user_login_mobile_uuid = request_json['user_login_mobile_uuid']
            collection_type = request_json['collection_type']
        except Exception as e:
            self.LOG.error('parameters error.')
            self.rsp_msg = self.rsp_handler.generate_rsp_msg('21001', None)
            self.write(self.rsp_msg)
            return

        if not self.user.check_login_status(user_phone, user_login_mobile_uuid):
            self.LOG.error('user [%s] not login.' % user_phone)
            self.rsp_msg = self.rsp_handler.generate_rsp_msg('21006', None)
            self.mysql_handler.rollback_db()
            self.write(self.rsp_msg)
            return

        collections = self.favorite.get_collection(user_phone, collection_type) 
        if not collections:
            self.LOG.error('user [%s] has no collections.' % user_phone)
            self.rsp_msg = self.rsp_handler.generate_rsp_msg('200', {'rsp_data': {'collections':[]}})
            self.mysql_handler.rollback_db()
            self.write(self.rsp_msg)
            return

        result = []
        targets = [collection['collection_mark'] for collection in collections]
        if collection_type == 'user':
            users = self.user.get_user_by_phones(targets)
            for user in users:
                image_info = self.picture.get_image_by_phone(user['user_phone'], 'user')
                try:
                    image_big_mame = image_info['pic_big_name']
                    image_sml_mame = image_info['pic_sml_name']
                except:
                    image_big_mame = None
                    image_sml_mame = None
                user['pic_big_name'] = image_big_mame
                user['pic_sml_name'] = image_sml_mame
                del user['user_login_mobile_uuid']
                del user['user_phone_mno']
            result = users
        elif collection_type == 'device':
            devices = self.device.get_device_by_numbers(targets)
            for device in devices:
                attributes = self.device_attribute.get_attribute_by_number(device['device_number'])
                device['device_attributes'] = attributes if attributes else []
                pictures = self.picture.get_image_by_number(device['device_number'], 'device')
                if pictures:
                    for picture in pictures:
                        del picture['pic_owner_mark']
                        del picture['create_time']
                        del picture['pic_path']
                        del picture['pic_owner_type']
                device['device_pictures'] = pictures if pictures else []
                device['user_phone']
            result = devices
        else:
            self.LOG.error('collection_type [%s] is error.' % collection_type)
            self.rsp_msg = self.rsp_handler.generate_rsp_msg('21999', None)
            self.mysql_handler.rollback_db()
            self.write(self.rsp_msg)
            return

        self.rsp_msg = self.rsp_handler.generate_rsp_msg('200', {'rsp_data': {'collections':result}})
        self.mysql_handler.commit_db()
        self.write(self.rsp_msg)
        return
开发者ID:yufajieluo,项目名称:cloud_factory,代码行数:85,代码来源:favoriteHandler.py


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