def get(self):
        the_get = Get()
        instance = OHHOPermission()
        group_id = the_get.get_id(self)
        message = the_get.get_data(self)
        group_name = ""
        if group_id:
            group_id = int(group_id)
            group = instance.group.get_by_id(group_id)
            if group:
                group_name = group.name

        all_page = instance.page.get_query()
        page_ids = [p.id for p in all_page] if all_page else []

        query_group_and_page = instance.group_and_page.get_query()
        query_group_and_page = instance.group_and_page.get_by_group_id(
            query_group_and_page, group_id)
        permission_ids = [p.page_permission_id for p in query_group_and_page
                          ] if query_group_and_page else []

        query_page_permission = instance.page_permission.get_query()
        query_page_permission = instance.page_permission.get_by_page_permission_ids(
            query_page_permission, permission_ids)
        permission_page_ids = [q.page_id for q in query_page_permission
                               ] if query_page_permission else []

        the_page_ids = OHHOOperation.list_minus_list(page_ids,
                                                     permission_page_ids)
        rest_page_list = list()
        for page_id in the_page_ids:
            page = instance.page.get_by_id(page_id)
            temp = dict()
            if page:
                temp["page_id"] = page.id
                temp["page_description"] = page.description
                temp["page_name"] = page.name
            if temp:
                rest_page_list.append(temp)

        return self.render(
            PERMISSION_GROUP_PAGE_RELATION_BACKSTAGE_ADD_HTML,
            group_id=group_id,
            rest_page_list=rest_page_list,
            group_name=group_name,
            home_list_url=MANAGEMENT_PERMISSION_HOME_URL,
            list_url=PERMISSION_GROUP_PAGE_RELATION_BACKSTAGE_LIST_URL +
            "?id=" + str(group_id),
            detail_url=PERMISSION_GROUP_PAGE_RELATION_BACKSTAGE_DETAIL_URL,
            add_url=PERMISSION_GROUP_PAGE_RELATION_BACKSTAGE_ADD_URL + "?id=" +
            str(group_id),
            delete_url=PERMISSION_GROUP_PAGE_RELATION_BACKSTAGE_DELETE_URL,
            message=message)
Example #2
0
    def get_exclude_user_list_up224hour(self, user_id):
        query = self.exclude.get_query()
        query1 = self.exclude.get_by_user(query, user_id)
        query2 = self.exclude.get_by_exclude_user(query, user_id)
        if self.exclude.is_empty(query1):
            user1_list = list()
        else:
            user1_list = [exclude.exclude_user_id for exclude in query1]

        if self.exclude.is_empty(query1):
            user2_list = list()
        else:
            user2_list = [exclude.user_id for exclude in query2]
        user_id_list = list(set(user1_list + user2_list))
        user_id_list_before24hour = self.get_exclude_user_list(user_id)
        return OHHOOperation.list_minus_list(user_id_list,
                                             user_id_list_before24hour)
Example #3
0
 def clear_by_friend(self, user_id, user_id_list):
     friends = self.friend.get_valid_by_account(user_id)
     friend_user_id_list = [f.friend_account_id for f in friends]
     return OHHOOperation.list_minus_list(user_id_list, friend_user_id_list)
Example #4
0
    def match_version22(self,
                        user_id,
                        device_list_string,
                        base_url,
                        identity_id=None):
        # 查看本人是否打开了配对开关
        # 查看本人状态是否在见面中
        # 查看本人状态是否是有有效的配对
        # 清除不是交友设备的设备(type=1是交友设备)
        # 根据device_list得到用户id_list
        # 过滤掉今天匹配并不中意的人
        # 过滤掉未打开匹配开关的人
        # 过滤掉正在见面的人
        # 过滤掉已经见面但还没有结束的人
        # 过滤掉24小时内见过面的人
        # 过滤掉是好友的人
        # 根据性别和年龄区间筛选用户列表,根据条件找出符合条件的用户列表
        # 从符合条件的用户列表中依次根据用户ID获取配对条件, 根据配对条件看当前用户是否符合条件
        # 将第一个符合条件的用户添加到申请表中,并向两个人发送推送(推送对方的个人信息和推送的类型,这里是申请见面)
        user_id = int(user_id)
        self.clear_outdated_user()
        self.update_match_online(user_id)

        if not self.has_nickname(user_id):
            return Result.result_failed("please add nickname firstly!")

        if user_id and identity_id:
            OHHOLog.print_log(user_id)
            OHHOLog.print_log(identity_id)
            self.device.set_identity(identity_id)
            device = self.device.get_by_identity()
            if device:
                relations = self.device_relation.get_valid_by_device(device.id)
                the_relation = self.device_relation.first(relations)
                if the_relation and the_relation.user_id == user_id:
                    pass
                else:
                    information = "no device and user relation, you have no right to match!"
                    OHHOLog.print_log(information)
                    # return Result.result_failed(information)
            else:
                information = "no such device, you have no right to match!"
                OHHOLog.print_log(information)
                # return Result.result_failed(information)
        else:
            if user_id:
                information = "user %d is invalid, you have no right to match!" % user_id
                OHHOLog.print_log(information)
                # return Result.result_failed(information)
            else:
                information = "user or device is invalid, you have no right to match!"
                OHHOLog.print_log(information)
                # return Result.result_failed(information)

        is_match = self.is_match_open(user_id)
        if not is_match:
            OHHOLog.print_log("%d match switch closed!" % user_id)
            return Result.result_failed("please open match switch!")

        if self.is_in_meeting(user_id):
            OHHOLog.print_log("%d is in meeting" % user_id)
            return Result.result_failed("you are still in meeting!")
        OHHOLog.print_log("%d is not in meeting" % user_id)

        has_valid_apply, the_apply_id = self.has_valid_apply(user_id)
        if has_valid_apply:
            return Result.result_failed("you have matched with somebody: %d" %
                                        the_apply_id)
        OHHOLog.print_log("%d has no valid apply" % user_id)

        exclude_user_id_list = self.get_exclude_user_list(user_id)

        device_list = device_list_string.split(",")
        if "" in device_list:
            device_list.remove("")
        OHHOLog.print_log("source:")
        OHHOLog.print_log(device_list)
        device_list = self.clear_secondary_device(device_list)
        OHHOLog.print_log("clear secondary device:")
        OHHOLog.print_log(device_list)
        user_id_list = list()
        for identity in device_list:
            self.device.set_identity(identity)
            relation = self.device.get_relation_by_device()
            if relation:
                user_id_list.append(relation.user_id)
        OHHOLog.print_log("get user list")
        OHHOLog.print_log(user_id_list)
        OHHOLog.print_log("exclude user id list")
        OHHOLog.print_log(exclude_user_id_list)
        if user_id_list:
            user_id_list = OHHOOperation.list_minus_list(
                user_id_list, exclude_user_id_list)
            OHHOLog.print_log("clear exclude user")
            OHHOLog.print_log(user_id_list)

            user_id_list = self.clear_by_is_match(user_id_list)
            OHHOLog.print_log("clear match switch close user")
            OHHOLog.print_log(user_id_list)

            OHHOLog.print_log("clear self user")
            if user_id in user_id_list:
                user_id_list.remove(user_id)
            OHHOLog.print_log(user_id_list)
        else:
            return Result.result_success()

        if user_id_list:
            meeting_user_id_list = self.meet.get_meeting_user_ids()
            OHHOLog.print_log("meeting user id list")
            OHHOLog.print_log(meeting_user_id_list)
            user_id_list = OHHOOperation.list_minus_list(
                user_id_list, meeting_user_id_list)
            OHHOLog.print_log("clear meeting user")
            OHHOLog.print_log(user_id_list)
        else:
            return Result.result_success()

        if user_id_list:
            user_id_list = self.clear_by_met_not_end(user_id_list)
            OHHOLog.print_log("clear met but not end")
            OHHOLog.print_log(user_id_list)
        else:
            return Result.result_success()

        if user_id_list:
            user_id_list = self.clear_by_meet_in24hour(user_id, user_id_list)
            OHHOLog.print_log("clear meet in 24 hours")
            OHHOLog.print_log(user_id_list)
        else:
            return Result.result_success()

        if user_id_list:
            user_id_list = self.clear_by_friend(user_id, user_id_list)
            OHHOLog.print_log("clear friend")
            OHHOLog.print_log(user_id_list)
        else:
            return Result.result_success()

        if user_id_list:
            has_duplex_agree = self.has_duplex_agree(user_id, user_id_list,
                                                     base_url)
            if has_duplex_agree:
                return Result.result_success()
            else:
                user_id_list = self.duplex_match(user_id, user_id_list)
                OHHOLog.print_log(user_id_list)

                if user_id_list:
                    match_user_id = self.compute_main(user_id, user_id_list)
                    # OHHOLog.print_log("matched user list:")
                    # OHHOLog.print_log(matched_user_list)
                    #
                    # matched_user_list = self.sorted_by_rules(user_id, matched_user_list)
                    # user_tuple = matched_user_list[0]
                    # match_user_id = user_tuple[2]
                    # primary = user_tuple[3]
                    # secondary = user_tuple[4]
                    if match_user_id:
                        the_apply = self.add_apply(user_id, match_user_id)
                        if the_apply:
                            OHHOLog.print_log(
                                self.push_information(user_id, match_user_id,
                                                      the_apply.id, base_url))
                            OHHOLog.print_log(
                                self.push_information(match_user_id, user_id,
                                                      the_apply.id, base_url))
                        else:
                            OHHOLog.print_log("has valid apply!")
            return Result.result_success()
Example #5
0
 def clear_by_meet_in24hour(self, user_id, user_id_list):
     meet_in24hour_user_ids = self.meet.get_meet_in24hour_user_ids(user_id)
     OHHOLog.print_log("meet in 24 hour")
     OHHOLog.print_log(meet_in24hour_user_ids)
     return OHHOOperation.list_minus_list(user_id_list,
                                          meet_in24hour_user_ids)