コード例 #1
0
ファイル: views.py プロジェクト: yzcho1236/demo
    def get(self, request, *args, **kwargs):
        content = {
            "error": "",
            "data": [],
            "all_role_dict": [],
            "perm": request.perm,
        }
        user_role_list = []
        page = request.GET.get("page", 1)
        pagesize = request.pagesizes
        user_query = User.objects.all().order_by("id")
        pagination = Pagination(user_query, pagesize, page)

        all_roles = Role.objects.all().values("id", "name").order_by('id')
        all_role_dict = {}
        for i in list(all_roles):
            all_role_dict[i["id"]] = i["name"]

        for user in pagination.get_objs():
            roles = UserRole.objects.filter(
                user=user).values("role__name").order_by('id')
            roles_list = [i["role__name"] for i in list(roles)]
            user_role = {
                "id": user.id,
                "user": user.username,
                "role": roles_list,
            }
            user_role_list.append(user_role)
        content["data"] = user_role_list
        content["all_role_dict"] = all_role_dict
        content["page"] = pagination.page
        content["records"] = pagination.count
        content["total_pages"] = pagination.total_pages

        return TemplateResponse(request, "user_role.html", content)
コード例 #2
0
ファイル: views.py プロジェクト: yzcho1236/demo
    def get(self, request, *args, **kwargs):
        """获取用户列表"""

        content = []
        page = request.GET.get("page", 1)
        pagesize = request.pagesizes
        user_query = User.objects.all().order_by("id")
        pagination = Pagination(user_query, pagesize, page)

        for i in pagination.get_objs():
            data = {
                "id": i.id,
                "username": i.username,
                "is_superuser": i.is_superuser,
            }
            content.append(data)
        all_data = {
            "page": page,
            "records": pagination.count,
            "total_pages": pagination.total_pages,
            "data": content,
            "perm": request.perm
        }

        return TemplateResponse(request, "user.html", all_data)
コード例 #3
0
ファイル: views.py プロジェクト: yzcho1236/demo
    def _get_data(self, request, in_page=True, *args, **kwargs):
        # 查询的字段
        filter_fields = ("id", "nr", "name", "barcode")
        # 获取到的页面数
        page = request.GET.get("page", 1)
        query_data = dict(request.GET.lists())
        item_query, fs, query_url = GetQueryData.get_data(
            Item, query_data, filter_fields)
        count = float(item_query.count())
        pagesize = request.pagesizes if in_page else count
        pagination = Pagination(item_query, pagesize, page)
        content = []
        for i in pagination.get_objs():
            data = {
                "id": i.id,
                "nr": i.nr,
                "name": i.name,
                "barcode": i.barcode
            }
            content.append(data)
        all_data = {
            "data": content,
            "pg": pagination,
            "perm": request.perm,
            "query": fs,
            'query_url': query_url,
            "select_field": self.select_field,
            "select_op": select_op,
            "error": ""
        }

        return all_data
コード例 #4
0
ファイル: views.py プロジェクト: yzcho1236/demo
    def get(self, request, *args, **kwargs):
        content = {
            "error": "",
            "data": [],
            "all_perm_dict": {},
            "perm": request.perm
        }
        page = request.GET.get("page", 1)
        pagesize = request.pagesizes
        roles_query = Role.objects.all().order_by('id')
        pagination = Pagination(roles_query, pagesize, page)

        role_perm_list = []
        all_perms = list(Perm.objects.all().values("id",
                                                   "codename").order_by('id'))
        all_perm_dict = {}
        for i in all_perms:
            all_perm_dict[i["id"]] = i["codename"]

        perms = list(
            RolePermission.objects.filter(
                role_id__in=[i.id for i in list(roles_query)]))
        for role in pagination.get_objs():
            perms_ids = list(
                map(lambda x: x.permission_id,
                    filter(lambda i: i.role_id == role.id, perms)))
            perms_list = list(
                map(
                    lambda x: x['codename'],
                    filter(lambda i: perms_ids.__contains__(i["id"]),
                           all_perms)))
            user_role = {
                "id": role.id,
                "role": role.name,
                "perm": perms_list,
            }
            role_perm_list.append(user_role)

        content["data"] = role_perm_list
        content["all_perm_dict"] = all_perm_dict
        content["page"] = pagination.page
        content["records"] = pagination.count
        content["total_pages"] = pagination.total_pages
        return TemplateResponse(request, "role_permission.html", content)
コード例 #5
0
ファイル: views.py プロジェクト: yzcho1236/demo
    def get(self, request, *args, **kwargs):
        content = []
        page = request.GET.get("page", 1)
        pagesize = request.pagesizes
        perm_query = Perm.objects.all().order_by("id")
        pagination = Pagination(perm_query, pagesize, page)
        for i in pagination.get_objs():
            data = {
                "id": i.id,
                "name": i.name,
                "codename": i.codename,
                "perm": request.perm
            }
            content.append(data)

        all_data = {
            "page": pagination.page,
            "records": pagination.count,
            "total_pages": pagination.total_pages,
            "data": content,
            "perm": request.perm
        }

        return TemplateResponse(request, "permission.html", all_data)
コード例 #6
0
    def _get_data(self, request, in_page=True, *args, **kwargs):
        page = request.GET.get("page", 1)
        query_data = dict(request.GET.lists())
        bom_query, node_data, download, fs, query_url, search = BomData.get_tree(
            BomModel, query_data, self.select_field)
        if search:
            request.session["bom_query_url"] = query_url
        count = float(bom_query.count())
        pagesize = request.pagesizes if in_page else count
        pagination = Pagination(bom_query, pagesize, page)

        item_id = request.GET.get("id", None)
        child_bom_list = []
        if bom_query:
            if item_id:
                pid = item_id
            else:
                pid = bom_query.first().id
            parent = BomModel.objects.get(id=pid)

            # 是否查询所有数据
            if query_data.get("all", None):
                child_bom = BomModel.objects.filter(
                    parent_id=parent.item.id).order_by("id")
            else:
                child_bom = BomModel.objects.filter(
                    parent_id=parent.item.id,
                    effective_end__gte=timezone.now()).order_by("id")
            for i in child_bom:
                adict = {}
                adict["id"] = i.id
                adict["item"] = i.item.nr
                adict["nr"] = i.nr
                adict["effective_start"] = i.effective_start
                adict["effective_end"] = i.effective_end
                adict["qty"] = i.qty
                child_bom_list.append(adict)
            content = {
                "parent_id":
                pid,
                "parent":
                parent,
                "pg":
                pagination,
                "data":
                node_data,
                "bom_query":
                bom_query,
                "child_bom_list":
                child_bom_list,
                "download":
                download,
                "query":
                fs,
                "query_url":
                request.session.get("bom_query_url", None)
                if request.session.get("bom_query_url", None) else "",
                "select_op":
                select_op,
                "select_field":
                self.select_field,
                "perm":
                request.perm,
                "error":
                ""
            }
        else:
            content = {
                "parent_id":
                "",
                "parent":
                "",
                "pg":
                pagination,
                "nodes":
                pagination.get_objs(),
                "data":
                node_data,
                "bom_query":
                bom_query,
                "child_bom_list":
                child_bom_list,
                "download":
                download,
                "query":
                fs,
                "query_url":
                request.session.get("bom_query_url", None)
                if request.session.get("bom_query_url", None) else "",
                "select_op":
                select_op,
                "select_field":
                self.select_field,
                "perm":
                request.perm,
                "error":
                ""
            }
        return content
コード例 #7
0
    def _get_data(self, request, in_page=True, *args, **kwargs):
        # 获取到的页面数
        page = request.GET.get("page", 1)
        query_data = dict(request.GET.lists())
        item_query, fs, query_url, search = GetQueryData.get_tree(
            Tree_Model, query_data, self.select_field)
        if search:
            request.session["bom_query_url"] = query_url
        count = float(item_query.count())
        pagesize = request.pagesizes if in_page else count
        pagination = Pagination(item_query, pagesize, page)

        item_id = request.GET.get("id", None)
        page = request.GET.get("page", 1)
        data = []
        if item_query:
            if item_id:
                id = item_id
            else:
                id = item_query.first().id
            parent = Tree_Model.objects.get(id=id)
            pagination = Pagination(item_query, request.pagesizes, page)
            items = Tree_Model.objects.filter(
                parent__id=id, effective_end__gte=timezone.now())
            for i in items:
                adict = {}
                adict["id"] = i.id
                adict["item"] = i.name
                adict["item_nr"] = i.nr
                adict["parent"] = parent.name
                adict["parent_nr"] = parent.nr
                adict["effective_start"] = i.effective_start
                adict["effective_end"] = i.effective_end
                adict["qty"] = i.qty
                data.append(adict)
            content = {
                "id":
                id,
                "parent":
                parent.name,
                "parent_nr":
                parent.nr,
                "pg":
                pagination,
                "nodes":
                pagination.get_objs(),
                "data":
                data,
                "query":
                fs,
                "query_url":
                request.session.get("bom_query_url", None)
                if request.session.get("bom_query_url", None) else "",
                "select_op":
                select_op,
                "select_field":
                self.select_field,
                "perm":
                request.perm,
                "error":
                ""
            }
        else:
            content = {
                "id":
                "",
                "parent":
                "",
                "pg":
                pagination,
                "nodes":
                pagination.get_objs(),
                "data":
                data,
                "query":
                fs,
                "query_url":
                request.session.get("bom_query_url", None)
                if request.session.get("bom_query_url", None) else "",
                "select_op":
                select_op,
                "select_field":
                self.select_field,
                "perm":
                request.perm,
                "error":
                ""
            }
        return content