Beispiel #1
0
    def get(self):
        the_get = Get()
        cellphone = the_get.get_cellphone_number(self)
        if cellphone is None:
            cellphone = ""
        state = the_get.get_state(self)
        if state is None:
            state = ""
        page = the_get.get_page(self)
        data_count_per_page = the_get.get_data_count_per_page(self)
        page_count_per_page = the_get.get_page_count_per_page(self)
        offset = (page - 1) * data_count_per_page
        limit = data_count_per_page

        instance = User()

        if cellphone:
            query = instance.find_by_cellphone(cellphone)
            # instance.get_by_cellphone(cellphone)
            # query = instance.find_by_username()
        else:
            query = instance.get_all()
        try:
            if state == "":
                pass
            elif int(state):
                query = instance.get_valid(query)
            else:
                query = instance.get_invalid(query)
        except Exception as ex:
            pass
        users, count = instance.get_some_users(query, offset, limit)
        total_page = int(ceil(count / data_count_per_page))
        pagination = Pagination(total_page, page, data_count_per_page,
                                page_count_per_page)
        page_list, previous, next = pagination.get_page_list_of_this_page()

        # return self.render("backstage/management/user_list.html",
        return self.render(
            MANAGEMENT_USER_LIST_HTML,
            users=users,
            pages=page_list,
            previous=previous,
            next=next,
            page=page,
            cellphone_number=cellphone,
            state=state,
            detail_url=MANAGEMENT_USER_DETAIL_URL,
            delete_url=MANAGEMENT_USER_DELETE_URL,
        )
class LogicGetMapPositions(object):
    def __init__(self):
        self.user = User()

    def get(self, user_id, base_url):
        result = Result.result_success()
        users = self.user.get_all()
        data = list()
        if self.user.user.is_empty(users):
            pass
        else:
            for user in users:
                if user_id == user.id:
                    continue
                temp = self.user.get_user_basic_information(user.id, base_url)
                if temp:
                    data.append(temp)
        if data:
            result["data"] = data

        return result
    def get(self):
        the_get = Get()
        cellphone_instance = Cellphone()
        relation_instance = UserAndCellphoneRelation()
        user_instance = User()

        users_query = user_instance.get_all()
        users_query = user_instance.get_valid(users_query)
        cellphones_query = cellphone_instance.get_all_cellphone()

        cellphone_key = the_get.get_cellphone_key(self)
        if cellphone_key is None:
            cellphone_key = ""
        username = the_get.get_username(self)
        if username is None:
            username = ""
        page = the_get.get_page(self)
        data_count_per_page = the_get.get_data_count_per_page(self)
        page_count_per_page = the_get.get_page_count_per_page(self)
        offset = (page - 1) * data_count_per_page
        limit = data_count_per_page

        query = relation_instance.get_all()
        if cellphone_key:
            cellphone_query = cellphone_instance.get_all_cellphone()
            cellphone_query = cellphone_instance.find_by_key(
                cellphone_query, cellphone_key)
            cellphone_id_list = list()
            if not cellphone_instance.cellphone.is_empty(cellphone_query):
                cellphone_id_list = [
                    cellphone.id for cellphone in cellphone_query
                ]
            query = relation_instance.find_by_cellphone(
                query, cellphone_id_list)

        if username:
            user_query = user_instance.find_by_username(username)
            user_id_list = list()
            if not user_instance.user.is_empty(user_query):
                user_id_list = [user.id for user in user_query]
            query = relation_instance.find_by_user(query, user_id_list)

        query, count = relation_instance.get_some(query, offset, limit)
        total_page = int(ceil(count / data_count_per_page))
        pagination = Pagination(total_page, page, data_count_per_page,
                                page_count_per_page)
        page_list, previous, next = pagination.get_page_list_of_this_page()
        relations = list()
        for q in query:
            temp = dict()
            temp["id"] = q.id
            temp["state"] = q.state
            user = user_instance.get_by_id(q.user_id)
            temp["username"] = user.username if user else ""
            temp["user_id"] = user.id if user else ""
            cellphone = cellphone_instance.get_by_id(q.cellphone_id)
            temp["key"] = cellphone.key if cellphone else ""
            temp["cellphone_id"] = cellphone.id if cellphone else ""
            relations.append(temp)

        return self.render(USER_AND_CELLPHONE_LIST_HTML,
                           relations=relations,
                           pages=page_list,
                           previous=previous,
                           next=next,
                           page=page,
                           list_url=USER_AND_CELLPHONE_LIST_URL,
                           detail_url=USER_AND_CELLPHONE_DETAIL_URL,
                           add_url=USER_AND_CELLPHONE_ADD_URL,
                           delete_url=USER_AND_CELLPHONE_DELETE_URL,
                           username=username,
                           cellphone_key=cellphone_key,
                           users_query=users_query,
                           cellphones_query=cellphones_query)