Esempio n. 1
0
    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)
Esempio n. 2
0
    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()
Esempio n. 3
0
    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
Esempio n. 4
0
 def add(name):
     CITypeGroup.get_by(name=name, first=True) and abort(
         400, "Group {0} does exist".format(name))
     return CITypeGroup.create(name=name)