コード例 #1
0
ファイル: ci_type.py プロジェクト: russellPanda/cmdb-2
    def update(gid, name, type_ids):
        """
        update all
        :param gid: 
        :param name: 
        :param type_ids: 
        :return: 
        """
        existed = CITypeGroup.get_by_id(gid) or abort(
            404, "Group <{0}> does not exist".format(gid))
        if name is not None:
            existed.update(name=name)

        for idx, type_id in enumerate(type_ids):

            item = CITypeGroupItem.get_by(group_id=gid,
                                          type_id=type_id,
                                          first=True,
                                          to_dict=False)
            if item is not None:
                item.update(order=idx)
            else:
                CITypeGroupItem.create(group_id=gid,
                                       type_id=type_id,
                                       order=idx)
コード例 #2
0
ファイル: ci_type.py プロジェクト: 13052020/cmdb
    def delete(gid):
        existed = CITypeGroup.get_by_id(gid) or abort(404, "Group <{0}> does not exist".format(gid))

        items = CITypeGroupItem.get_by(group_id=gid, to_dict=False)
        for item in items:
            item.soft_delete()

        existed.soft_delete()
コード例 #3
0
ファイル: ci_type.py プロジェクト: 13052020/cmdb
    def get(need_other=None):
        groups = CITypeGroup.get_by()
        group_types = set()
        for group in groups:
            for t in sorted(CITypeGroupItem.get_by(group_id=group['id']), key=lambda x: x['order']):
                group.setdefault("ci_types", []).append(CITypeCache.get(t['type_id']).to_dict())
                group_types.add(t["type_id"])

        if need_other:
            ci_types = CITypeManager.get_ci_types()
            other_types = dict(ci_types=[ci_type for ci_type in ci_types if ci_type["id"] not in group_types])
            groups.append(other_types)

        return groups