Beispiel #1
0
 def update(self, type_id, type_name, type_alias, _id=None, unique=None,
            icon_url="", enabled=None):
     citype = CITypeCache.get(type_id)
     if citype is None:
         return False, "CIType {0} is not existed".format(type_name)
     uniq_key = CIAttributeCache.get(_id) or CIAttributeCache.get(unique)
     if uniq_key is not None:
         citype.uniq_id = uniq_key.attr_id
         citype_attr = db.session.query(CITypeAttribute).filter(
             CITypeAttribute.type_id == type_id).filter(
                 CITypeAttribute.attr_id == uniq_key.attr_id).first()
         if citype_attr is None:
             citype_attr = CITypeAttribute()
             citype_attr.attr_id = uniq_key.attr_id
             citype_attr.type_id = type_id
         citype_attr.is_required = True
         db.session.add(citype_attr)
     if type_name:
         citype.type_name = type_name
     if type_alias:
         citype.type_alias = type_alias
     if icon_url:
         citype.icon_url = icon_url
     if enabled is not None:
         citype.enabled = enabled
     db.session.add(citype)
     try:
         db.session.commit()
     except Exception as e:
         db.session.rollback()
         current_app.logger.error("add CIType is error, {0}".format(str(e)))
         return False, str(e)
     CITypeCache.clean(type_id)
     return True, type_id
Beispiel #2
0
 def add(self, type_name, type_alias, _id=None, unique=None,
         icon_url="", enabled=True):
     uniq_key = CIAttributeCache.get(_id) or CIAttributeCache.get(unique)
     if uniq_key is None:
         return False, "uniq_key is not existed"
     citype = CITypeCache.get(type_name)
     if citype:
         return False, "this CIType {0} is existed".format(type_name)
     _citype = CIType()
     _citype.type_name = type_name
     _citype.type_alias = type_alias
     _citype.uniq_id = uniq_key.attr_id
     _citype.enabled = enabled
     _citype.icon_url = icon_url
     db.session.add(_citype)
     db.session.flush()
     _citype_attr = CITypeAttribute()
     _citype_attr.attr_id = uniq_key.attr_id
     _citype_attr.type_id = _citype.type_id
     _citype_attr.is_required = True
     db.session.add(_citype_attr)
     try:
         db.session.commit()
     except Exception as e:
         db.session.rollback()
         current_app.logger.error("add CIType is error, {0}".format(str(e)))
         return False, str(e)
     CITypeCache.clean(type_name)
     return True, _citype.type_id
Beispiel #3
0
 def delete(self, type_id):
     citype = db.session.query(CIType).filter_by(type_id=type_id).first()
     type_name = citype.type_name
     if citype:
         db.session.delete(citype)
         try:
             db.session.commit()
         except Exception as e:
             db.session.rollback()
             current_app.logger.error(
                 "delete CIType is error, {0}".format(str(e)))
             return abort(500, str(e))
         CITypeCache.clean(type_id)
         return "CIType {0} deleted".format(type_name)
     return abort(404, "CIType is not existed")