def get(self):
        the_get = Get()
        relation_id = the_get.get_id(self)
        username = ""
        identity_id = ""
        state = False
        user_instance = DBOHHOUser()
        device_instance = DBOHHODevice()
        relation_instance = DBOHHOUserAndDeviceRelation()
        if relation_id:
            relation = relation_instance.get_by_id(relation_id)
            if relation:
                state = relation.state
                user = user_instance.get_by_id(relation.user_id)
                username = user.username if user else ""
                device = device_instance.get_by_id(relation.device_id)
                identity_id = device.identity_id if device else ""

        return self.render(
            USER_AND_DEVICE_DELETE_HTML,
            username=username,
            identity_id=identity_id,
            state=state,
            detail_url=USER_AND_DEVICE_DETAIL_URL,
            list_url=USER_AND_DEVICE_LIST_URL,
            delete_url=USER_AND_DEVICE_DELETE_URL,
        )
示例#2
0
class LogicAddDevice(object):
    def __init__(self):
        self.device = DBOHHODevice()

    def add_device(self, application_id, identity_id, mac_address, tx_power):

        data_dict = dict()
        data_dict["application_id"] = application_id
        data_dict["identity_id"] = identity_id
        data_dict["mac_address"] = mac_address
        data_dict["tx_power"] = tx_power

        self.device.set_identity(identity_id)
        device = self.device.get_by_identity()
        if not device:
            add = self.device.add(data_dict)
            if add:
                result = Result.result_success()
                device = self.device.get_by_identity()
                result["device_id"] = device.id
            else:
                result = Result.result_failed()
        else:
            result = Result.result_exist(DEVICE_EXIST)
            result["device_id"] = device.id
        return result
示例#3
0
 def __init__(self):
     self.blue_tooth = Bluetooth()
     self.meet = Meet()
     self.user = User()
     self.device = DBOHHODevice()
     self.relation = DBOHHOUserAndDeviceRelation()
     self.display_configuration = DBOHHOUserDisplayConfiguration()
    def __init__(self):
        self.user = DBOHHOUser()
        self.user_and_device_relation = DBOHHOUserAndDeviceRelation()
        self.password = Password()
        self.token = Token()
        self.user_extension = DBOHHOUserAccuracyExtension()
        self.interest = DBOHHOInterest()
        self.map = DBOHHOMapInformation()
        self.device = DBOHHODevice()
        self.record_user_and_match_condition = DBOHHORecordUserAndMatchCondition(
        )
        self.match_condition = DBOHHORecordMatchCondition()
        self.im_user = DBOHHOIMUser()
        self.im_user_relation = DBOHHOIMUserRelation()
        self.user_configuration = DBOHHOUserConfiguration()
        self.imei = IMEI()
        self.user_and_device_imei = DBOHHOUserAndDeviceIMEI()
        self.friend = Friend()
        self.apply = DBOHHORecordMatchApply()
        self.country_code = DBOHHOCountryCode()
        self.user_and_cellphone_relation = DBOHHOUserAndCellphoneRelation()

        self.user_favourite_book = DBOHHOUserFavouriteBook()
        self.user_favourite_movie = DBOHHOUserFavouriteMovie()
        self.user_favourite_sport = DBOHHOUserFavouriteSport()
        self.user_favourite_music = DBOHHOUserFavouriteMusic()
        self.user_icon = DBOHHOUserIcon()
        self.user_description = DBOHHOUserDescription()
        self.user_impression = DBOHHOUserImpression()
示例#5
0
class LogicFindDevicePosition(object):
    def __init__(self):
        self.sensor = DBOHHODeviceSensor()
        self.device = DBOHHODevice()
        self.relation = DBOHHOUserAndDeviceRelation()
        self.map = DBOHHOMapInformation()

    def find_device_position(self, identity_id):
        result = dict()
        data = list()
        circle = dict()
        circle["longitude"] = -1
        circle["latitude"] = -1
        circle["radius"] = -1
        self.device.set_identity(identity_id)
        device = self.device.get_by_identity()
        if device:
            relation = self.relation.get_by_device(device.id)
            if relation:
                query = self.map.get_by_user(relation.user_id)
                query = self.map.order_by_id_desc(query)
                first = self.map.first(query)
                if first:
                    current_timestamp = OHHODatetime.get_current_timestamp()
                    if current_timestamp < first.timestamp + FIND_DEVICE_TIMESTAMP_DELTA:
                        circle["longitude"] = first.longitude
                        circle["latitude"] = first.latitude
                        sensor_query = self.sensor.get_query()
                        sensor_query = self.sensor.get_by_device(
                            sensor_query, device.id)
                        sensor_query = self.sensor.get_by_user(
                            sensor_query, relation.user_id)
                        sensor_query = self.sensor.order_by_id_desc(
                            sensor_query)
                        first = self.sensor.first(sensor_query)
                        if first:
                            if current_timestamp < first.timestamp + FIND_DEVICE_TIMESTAMP_DELTA:
                                result = Result.result_success()
                                circle["radius"] = first.distance
                            else:
                                result = Result.result_failed(
                                    "device sensor is outdated!")
                        else:
                            result = Result.result_failed("no device sensor!")
                    else:
                        result = Result.result_failed(
                            "map position is outdated!")
                else:
                    result = Result.result_failed("no map position!")
            else:
                result = Result.result_failed("no user binds the device!")
        else:
            result = Result.result_failed("no such device!")
        data.append(circle)
        result["data"] = data

        return result
 def get(self):
     user_instance = DBOHHOUser()
     device_instance = DBOHHODevice()
     user_query = user_instance.get_query()
     user_query = user_instance.get_valid(user_query)
     device_query = device_instance.get_query()
     device_query = device_instance.get_all(device_query)
     return self.render(USER_AND_DEVICE_ADD_HTML,
                        add_url=USER_AND_DEVICE_ADD_URL,
                        list_url=USER_AND_DEVICE_LIST_URL,
                        user_query=user_query,
                        device_query=device_query)
示例#7
0
 def get_information(self, instance):
     result = dict()
     device = DBOHHODevice.get_by_id(instance.device_id)
     if device:
         result["identity_id"] = device.identity_id
         result["imei"] = instance.imei
     return result
 def post(self):
     the_post = Post()
     username = the_post.get_username(self)
     identity_id = the_post.get_device_identity_id(self)
     user_instance = DBOHHOUser()
     device_instance = DBOHHODevice()
     relation_instance = DBOHHOUserAndDeviceRelation()
     user = user_instance.get_by_username(username)
     device_instance.set_identity(identity_id)
     device = device_instance.get_by_identity()
     if user and device:
         data = dict()
         data["user_id"] = user.id
         data["device_id"] = device.id
         success = relation_instance.add(data)
         if success:
             return self.redirect(USER_AND_DEVICE_LIST_URL)
     return self.redirect(USER_AND_DEVICE_ADD_URL)
    def post(self):
        the_post = Post()
        username = the_post.get_username(self)
        identity_id = the_post.get_device_identity_id(self)
        user_instance = DBOHHOUser()
        device_instance = DBOHHODevice()
        relation_instance = DBOHHOUserAndDeviceRelation()

        user = user_instance.get_by_username(username)
        device_instance.set_identity(identity_id)
        device = device_instance.get_by_identity()
        delete_or_restore = the_post.get_delete_or_restore(self)
        if delete_or_restore:
            if device:
                relation = relation_instance.get_by_device(device.id)
                if relation:
                    if relation.state:
                        # print("execute delete")
                        relation_instance.delete(relation)
                    else:
                        # print("execute restore")
                        relation_instance.restore(relation)

        return self.redirect(USER_AND_DEVICE_LIST_URL)
    def post(self):
        the_post = Post()
        username = the_post.get_username(self)
        identity_id = the_post.get_device_identity_id(self)
        user_instance = DBOHHOUser()
        device_instance = DBOHHODevice()
        relation_instance = DBOHHOUserAndDeviceRelation()

        user = user_instance.get_by_username(username)
        device_instance.set_identity(identity_id)
        device = device_instance.get_by_identity()

        submit = the_post.get_submit(self)
        # delete_or_restore = the_post.get_delete_or_restore(self)

        if submit:
            if device:
                relation = relation_instance.get_by_device(device.id)
                if relation:
                    if user:
                        data = dict()
                        data["user_id"] = user.id
                        if relation:
                            relation_instance.update(relation, data)
        # if delete_or_restore:
        #     if device:
        #         relation = relation_instance.get_by_device(device.id)
        #         if relation:
        #             if relation.state:
        #                 # print("execute delete")
        #                 relation_instance.delete(relation)
        #             else:
        #                 # print("execute restore")
        #                 relation_instance.restore(relation)

        return self.redirect(USER_AND_DEVICE_LIST_URL)
示例#11
0
 def __init__(self):
     self.user = DBOHHOUser()
     self.user_and_device_relation = DBOHHOUserAndDeviceRelation()
     self.password = Password()
     self.token = Token()
     self.user_extension = DBOHHOUserAccuracyExtension()
     self.interest = DBOHHOInterest()
     self.map = DBOHHOMapInformation()
     self.device = DBOHHODevice()
     self.record_user_and_match_condition = DBOHHORecordUserAndMatchCondition()
     self.match_condition = DBOHHORecordMatchCondition()
     self.im_user = DBOHHOIMUser()
     self.im_user_relation = DBOHHOIMUserRelation()
     self.user_configuration = DBOHHOUserConfiguration()
     self.imei = IMEI()
     self.user_and_device_imei = DBOHHOUserAndDeviceIMEI()
     self.friend = Friend()
     self.apply = DBOHHORecordMatchApply()
     self.country_code = DBOHHOCountryCode()
示例#12
0
    def get(self):
        device = DBOHHODevice()
        query = device.get_query()
        total_count = device.get_count(query)
        today_start = OHHODatetime.get_today_start()
        utc_today_start = OHHODatetime.beijing2utc(today_start)
        today_query = device.get_great_than_equal_changed_at(query, utc_today_start)
        today_count = device.get_count(today_query)

        relation = DBOHHOUserAndDeviceRelation()
        relation_query = relation.get_query()
        relation_query = relation.get_valid(relation_query)
        total_bind_count = relation.get_count(relation_query)
        today_bind_query = relation.get_great_than_equal_changed_at(relation_query, utc_today_start)
        today_bind_count = relation.get_count(today_bind_query)

        return self.render(STATISTICS_DEVICE_HTML,
                           total_count=total_count,
                           today_count=today_count,
                           today_bind_count=today_bind_count,
                           total_bind_count=total_bind_count,
                           )
示例#13
0
class Device(object):
    def __init__(self, identity_id=None, mac_address=None):
        self.device = DBOHHODevice(identity_id, mac_address)
        self.relation = DBOHHOUserAndDeviceRelation()
        self.imei = DBOHHOUserAndDeviceIMEI()
        self.user = DBOHHOUser()
        self.countryCode = DBOHHOCountryCode()

    def set_identity(self, identity_id):
        self.device.set_identity(identity_id)

    def get_identity(self):
        return self.device.identity_id

    def set_mac_address(self, mac_address):
        self.device.set_mac_address(mac_address)

    def get_mac_address(self):
        return self.device.mac_address

    def get_by_identity(self):
        return self.device.get_by_identity()

    def bind_device(self, user_id, type=1):
        try:
            OHHOLog.print_log("bind device start")
            device = self.get_by_identity()
            if device and self.device.check_by_mac():
                relation = self.relation.get_by_device(device.id)
                if relation and self.relation.is_valid(relation, True):
                    if relation.user_id == int(user_id):
                        result = Result.result_exist(RELATION_EXIST)
                    else:
                        user = self.user.get_by_id(relation.user_id)
                        cellphone = user.cellphone
                        country_code_id = user.country_code_id
                        country_code_obj = self.countryCode.get_by_id(
                            country_code_id)
                        if country_code_obj:
                            country_code = country_code_obj.country_code
                        else:
                            country_code = "+86"
                        result = Result.result_device_used_by_other()
                        result["country_code"] = country_code
                        result["cellphone_number"] = cellphone
                else:
                    success = self.relation.add_without_commit({
                        "device_id":
                        device.id,
                        "user_id":
                        user_id,
                        "type":
                        type
                    })
                    if success:
                        self.relation.commit()
                        result = Result.result_success()
                    else:
                        self.relation.rollback()
                        result = Result.result_failed()
            else:
                result = Result.result_not_exist()
            OHHOLog.print_log("bind device end")
            return result
        except Exception as ex:
            OHHOLog.print_log(ex)
            return Result.result_failed(ex)

    def unbind_device(self, user_id):
        device = self.device.get_by_identity()
        if device and self.device.check_by_mac():
            OHHOLog.print_log(device.id)
            relation = self.relation.get_by_device(device.id)
            if not relation:
                return Result.result_success(RELATION_NOT_EXIST)
            elif relation.user_id == int(user_id):
                if not self.relation.is_valid(relation, True):
                    return Result.result_success(RELATION_EXIST)
                else:
                    success = self.relation.delete(relation)
                    if success:
                        return Result.result_success()
                    else:
                        return Result.result_failed()
            else:
                return Result.result_failed(USED_BY_OTHER)
        else:
            return Result.result_failed(INVALID_DEVICE)

    def is_device_valid(self):
        device = self.device.get_by_identity()
        # OHHOLog.print_log(self.device.get_identity())
        # OHHOLog.print_log(device)
        if device and self.device.check_by_mac():
            relation = self.relation.get_by_device(device.id)
            if relation and self.relation.is_valid(relation, True):
                result = Result.result_device_used_by_other()
                user = DBOHHOUser()
                user_instance = user.get_by_id(relation.user_id)
                if user_instance:
                    result["cellphone_number"] = user_instance.cellphone
                    code = DBOHHOCountryCode.get_by_id(
                        user_instance.country_code_id)
                    if code:
                        result["country_code"] = code.country_code
                    else:
                        result["country_code"] = "+86"
                return result
            else:
                return Result.result_success()
        else:
            return Result.result_failed(INVALID_DEVICE)

    def get_relation_by_device(self):
        device = self.device.get_by_identity()
        if device:
            relation = self.relation.get_by_device(device.id)
            if self.relation.is_valid(relation, True):
                return relation
            else:
                return None
        return None

    def get_primary_relation_by_user(self, user_id):
        query = self.relation.get_query()
        query = self.relation.get_valid(query)
        relations = self.relation.get_by_user(query, user_id)
        relations = self.relation.get_primary(relations)
        return relations

    def relation_update(self, instance, data_dict):
        return self.relation.update(instance, data_dict)

    def get_all_device(self):
        return self.device.get_query()

    def find_by_identity(self, query):
        return self.device.find_by_identity(query)

    def find_by_mac_address(self, query):
        return self.device.find_by_mac_address(query)

    def get_some_devices(self, query, offset, limit):
        return self.device.get_some(query, offset, limit)

    def get_by_id(self, device_id):
        return self.device.get_by_id(device_id)

    def update(self, instance, data):
        return self.device.update(instance, data)

    def add(self, data):
        return self.device.add(data)

    def delete(self, instance):
        return self.device.delete(instance)

    def is_empty(self, query):
        count = query.count()
        if count > 0:
            return False
        return True

    def set_lost(self, user_id, identity_id):
        self.device.set_identity(identity_id)
        device = self.device.get_by_identity()
        if device:
            query = self.relation.get_valid_by_device(device.id)
            if query:
                query = self.relation.get_by_user(query, user_id)
                query = self.relation.get_not_lost(query)
                OHHOLog.print_log(query.count())
            if query:
                success = self.relation.set_lost(query)
                if success:
                    return Result.result_success()
                else:
                    return Result.result_failed()
            else:
                return Result.result_failed("this device is not yours!")
        else:
            return Result.result_failed("this device is invalid")

    def cancel_lost(self, user_id, identity_id):
        self.device.set_identity(identity_id)
        device = self.device.get_by_identity()
        if device:
            query = self.relation.get_valid_by_device(device.id)
            if query:
                query = self.relation.get_by_user(query, user_id)
                OHHOLog.print_log(query.count())
                # query = self.relation.get_valid(query)
                # OHHOLog.print_log(query.count())
                query = self.relation.get_lost(query)
                OHHOLog.print_log(query.count())
            if query:
                success = self.relation.cancel_lost(query)
                if success:
                    return Result.result_success()
                else:
                    return Result.result_failed()
            else:
                return Result.result_failed("this device is not yours!")
        else:
            return Result.result_failed("this device is invalid")

    def get_valid_relation_by_user(self, user_id):
        query = self.relation.get_query()
        query = self.relation.get_valid(query)
        query = self.relation.get_by_user(query, user_id)
        return query

    def get_device_information(self, device_id):
        device = self.device.get_by_id(device_id)
        result = self.device.get_information(device)
        imei = self.get_imei_by_deivce(device_id)
        if imei:
            result["imei"] = imei.imei
        else:
            result["imei"] = ""
        return result

    def get_imei_by_deivce(self, device_id):
        query = self.imei.get_query()
        instance = self.imei.get_by_device_id(query, device_id)
        # query = self.imei.order_by_id_desc(query)
        # instance = self.imei.first(query)
        return instance
示例#14
0
class LogicBluetoothPosition(object):
    def __init__(self):
        self.blue_tooth = Bluetooth()
        self.meet = Meet()
        self.user = User()
        self.device = DBOHHODevice()
        self.relation = DBOHHOUserAndDeviceRelation()
        self.display_configuration = DBOHHOUserDisplayConfiguration()

    def get_display_instance(self, distance):
        instance = self.display_configuration.get_nearest_distance(distance)
        return instance

    def get_information(self, user_extension, instance):
        information = dict()
        if instance.has_sex:
            information["sex"] = user_extension.sex

        return information

    def get_push_data_by_distance(self, user_id, apply_id, distance, base_url):
        user_extension = self.user.user_extension.get_by_user(user_id)
        instance = self.get_display_instance(distance)
        information = dict()
        if user_extension and instance:
            information = self.get_information(user_extension, instance)
        return information

    def bluetooth_position(self, user_id, identity_id, rssi, distance,
                           apply_id, base_url):
        the_meeting = self.meet.is_apply_in_meeting(apply_id, user_id)
        if the_meeting:
            friend_user_id = self.meet.get_another_user_id(apply_id, user_id)
            is_friend_end = self.meet.is_meet_end(apply_id, friend_user_id)
            is_friend_met = self.meet.is_met(apply_id)

            if is_friend_met:
                the_type = PUSH_STATE_TYPE_MET
                information = self.get_push_data_by_distance(
                    user_id, apply_id, distance, base_url)
                information["is_blue_tooth"] = 1
                self.user.push_user_information(friend_user_id, the_type,
                                                information)

                information = self.get_push_data_by_distance(
                    friend_user_id, apply_id, distance, base_url)
                information["is_blue_tooth"] = 1
                self.user.push_user_information(user_id, the_type, information)

                return Result.result_success("met!")

            if not is_friend_end and not is_friend_met:
                if self.meet.is_met(apply_id):
                    the_type = PUSH_STATE_TYPE_MET
                elif self.meet.is_meet_end(apply_id, user_id):
                    the_type = PUSH_STATE_TYPE_END_MEET
                else:
                    the_type = PUSH_STATE_TYPE_MEETING
                information = self.get_push_data_by_distance(
                    user_id, apply_id, distance, base_url)
                information["is_blue_tooth"] = 1
                self.user.push_user_information(friend_user_id, the_type,
                                                information)

                self.device.set_identity(identity_id)
                device = self.device.get_by_identity()
                if device:
                    self.blue_tooth.add_sensor(user_id, device.id, rssi,
                                               distance)
        return Result.result_success()
示例#15
0
 def __init__(self):
     self.device = DBOHHODevice()
示例#16
0
 def __init__(self):
     self.device = DBOHHODevice()
     self.setting = DBOHHODeviceSetting()
     self.version = DBOHHODeviceVersion()
     self.sensor = DBOHHODeviceSensor()
示例#17
0
class Bluetooth(object):
    def __init__(self):
        self.device = DBOHHODevice()
        self.setting = DBOHHODeviceSetting()
        self.version = DBOHHODeviceVersion()
        self.sensor = DBOHHODeviceSensor()

    def add_sensor(self, user_id, device_id, rssi, distance):
        data_dict = dict()
        data_dict["user_id"] = user_id
        data_dict["device_id"] = device_id
        data_dict["rssi"] = rssi
        data_dict["distance"] = distance

        return self.sensor.add(data_dict)

    def add_setting(self, identity_id, password, name, power, periods):
        self.device.set_identity(identity_id)
        device = self.device.get_by_identity()
        password_instance = Password(password)
        if device:
            instance = self.setting.get_by_device(device.id)
            if instance:
                result = Result.result_exist(DEVICE_SETTING_EXIST)
            else:
                data_dict = dict()
                data_dict["device_id"] = device.id
                data_dict["password"] = password_instance.aes_encryption()
                data_dict["name"] = name
                data_dict["power"] = power
                data_dict["periods"] = periods
                success = self.setting.add(data_dict)
                if success:
                    result = Result.result_success()
                else:
                    result = Result.result_failed()
        else:
            result = Result.result_not_exist(DEVICE_NOT_EXIST)
        return result

    def update_setting(self, identity_id, password, name, power):
        self.device.set_identity(identity_id)
        device = self.device.get_by_identity()
        if device:
            instance = self.setting.get_by_device(device.id)
            if instance:
                data_dict = dict()
                data_dict["password"] = Password.aes_encryption(password)
                data_dict["name"] = name
                data_dict["power"] = power
                success = self.setting.update(instance, data_dict)
                if success:
                    result = Result.result_success()
                else:
                    result = Result.result_failed()
            else:
                result = Result.result_not_exist(DEVICE_SETTING_NOT_EXIST)
        else:
            result = Result.result_not_exist(DEVICE_NOT_EXIST)

        return result

    def get_setting_information(self, identity_id):
        self.device.set_identity(identity_id)
        device = self.device.get_by_identity()
        data = dict()
        if device:
            instance = self.setting.get_by_device(device.id)
            if instance:
                data = self.setting.get_information(instance)
                data["source_password"] = Password.aes_decryption(data["password"])
                result = Result.result_success()
            else:
                result = Result.result_failed()
        else:
            result = Result.result_not_exist(DEVICE_NOT_EXIST)
        result["data"] = data
        return result

    def get_version_information(self):
        query = self.version.get_query()
        query = self.version.order_by_id_desc(query)
        version_object = self.version.first(query)
        data = dict()
        if version_object:
            data = self.version.get_information(version_object)
            result = Result.result_success()
        else:
            result = Result.result_failed()
        result["data"] = data
        return result

    def add_version(self, version, name, url):
        instance = self.version.get_by_version(version)
        if instance:
            return Result.result_failed("version exist!")
        data = dict()
        data["version"] = version
        data["name"] = name
        data["url"] = url
        success = self.version.add(data)
        if success:
            return Result.result_success()
        else:
            return Result.result_failed()
示例#18
0
class LogicAddUserNew(object):
    def __init__(self):
        self.user = DBOHHOUser()
        self.user_and_device_relation = DBOHHOUserAndDeviceRelation()
        self.password = Password()
        self.token = Token()
        self.user_extension = DBOHHOUserAccuracyExtension()
        self.interest = DBOHHOInterest()
        self.map = DBOHHOMapInformation()
        self.device = DBOHHODevice()
        self.record_user_and_match_condition = DBOHHORecordUserAndMatchCondition(
        )
        self.match_condition = DBOHHORecordMatchCondition()
        self.im_user = DBOHHOIMUser()
        self.im_user_relation = DBOHHOIMUserRelation()
        self.user_configuration = DBOHHOUserConfiguration()
        self.imei = IMEI()
        self.user_and_device_imei = DBOHHOUserAndDeviceIMEI()
        self.friend = Friend()
        self.apply = DBOHHORecordMatchApply()
        self.country_code = DBOHHOCountryCode()
        self.user_and_cellphone_relation = DBOHHOUserAndCellphoneRelation()

        self.user_favourite_book = DBOHHOUserFavouriteBook()
        self.user_favourite_movie = DBOHHOUserFavouriteMovie()
        self.user_favourite_sport = DBOHHOUserFavouriteSport()
        self.user_favourite_music = DBOHHOUserFavouriteMusic()
        self.user_icon = DBOHHOUserIcon()
        self.user_description = DBOHHOUserDescription()
        self.user_impression = DBOHHOUserImpression()

        # self.cellphone = 10000000000
        # self.identity_id = 9000000000

    def add_user(self):
        cellphone = 10000000000
        identity_id = 9000000000
        for i in range(10):
            cellphone = cellphone + 1
            identity_id = identity_id + 1
            while self.user.get_by_cellphone(cellphone):
                cellphone = cellphone + 1
            user_id = self.add_user_table(str(cellphone))
            self.add_user_token_table(user_id)
            self.add_user_extension(user_id)
            self.add_user_configuration(user_id)
            # self.add_user_and_cellphone_relation(user_id)
            self.device.set_identity(identity_id)
            while self.device.get_by_identity():
                identity_id = identity_id + 1
            device_id = self.add_device(identity_id)
            self.add_user_and_device_imei(user_id, device_id)
            self.add_user_and_device_relation(user_id, device_id)
            match_condition_id = self.add_match_condition()
            print("match_condition_id:")
            print(match_condition_id)
            self.add_user_match_condition(user_id, match_condition_id)

    def add_device(self, identity_id):
        data = dict()
        data["identity_id"] = identity_id
        self.device.add(data)
        query = self.device.get_query()
        query = self.device.order_by_id_desc(query)
        obj = Operation.first(query)
        return obj.id

    def add_match_condition(self):
        data = dict()
        data["sex"] = OhhoRandom.get_sex()
        data["small_age"] = 0
        data["big_age"] = 150
        data["interest"] = OhhoRandom.get_user_match_interest()
        self.match_condition.add(data)
        query = self.match_condition.get_query()
        query = self.match_condition.order_by_id_desc(query)
        obj = Operation.first(query)
        return obj.id

    def add_user_and_device_relation(self, user_id, device_id):
        data = dict()
        data["user_id"] = user_id
        data["device_id"] = device_id
        self.user_and_device_relation.add(data)

    def add_user_and_device_imei(self, user_id, device_id):
        data = dict()
        data["user_id"] = user_id
        data["device_id"] = device_id
        data["imei"] = OhhoRandom.get_imei()
        self.user_and_device_imei.add(data)

    def add_user_and_cellphone_relation(self, user_id):
        data = dict()
        data["user_id"] = user_id
        data["cellphone_id"] = OhhoRandom.get_cellphone_id()
        self.user_and_cellphone_relation.add(data)

    def add_user_configuration(self, user_id):
        data = dict()
        data["user_id"] = user_id
        data["is_match"] = 1
        data["is_online"] = 1
        self.user_configuration.add(data)

    def add_user_match_condition(self, user_id, match_condition_id):
        data = dict()
        data["user_id"] = user_id
        data["match_condition_id"] = match_condition_id
        self.record_user_and_match_condition.add(data)

    def add_user_extension(self, user_id):
        data = dict()
        data["user_id"] = user_id
        data["sex"] = OhhoRandom.get_sex()
        data["birthday"] = OhhoRandom.get_birthday()
        data["interest"] = OhhoRandom.get_user_interest()
        self.user_extension.add(data)

    def add_user_token_table(self, user_id):
        token = OHHORandom.get_nonce()
        token_dict = dict()
        token_dict["user_id"] = user_id
        token_dict["token"] = token
        self.token.token.add(token_dict)

    def add_user_table(self, cellphone="00000000000"):
        """添加用户 参数 """
        data = dict()
        password = "******"
        country_code_id = 159
        username = OHHOUUID.get_uuid1_string()
        self.password.set_password(password)
        encryption_password = self.password.encryption()
        data["username"] = username
        data["password"] = encryption_password
        data["cellphone"] = cellphone
        data["country_code_id"] = country_code_id
        self.user.add(data)
        user = self.user.get_by_username(username)
        return user.id
示例#19
0
 def __init__(self):
     self.sensor = DBOHHODeviceSensor()
     self.device = DBOHHODevice()
     self.relation = DBOHHOUserAndDeviceRelation()
     self.map = DBOHHOMapInformation()
示例#20
0
 def __init__(self, identity_id=None, mac_address=None):
     self.device = DBOHHODevice(identity_id, mac_address)
     self.relation = DBOHHOUserAndDeviceRelation()
     self.imei = DBOHHOUserAndDeviceIMEI()
     self.user = DBOHHOUser()
     self.countryCode = DBOHHOCountryCode()