示例#1
0
def change_flag(**args):
    '''смена флагов атрибута'''
    #aot
    schema      = args['schema']
    object_type = args['object_type']
    attr        = args['attr']

    #flags
    displayed   = args['displayed']    
    multiple    = args['multiple']    
    read_only   = args['read_only']    
    hidden      = args['hidden']    
    required    = args['required']    
    calculable  = args['calculable'] 
    
    #search AOT      
    try:
        aot = AOT.objects.get(schema=schema, object_type=object_type, attr=attr)
    except ObjectDoesNotExist:
        AOT().create(schema=schema, object_type=object_type, attr=attr, options=0)
        aot = AOT.objects.get(schema=schema, object_type=object_type, attr=attr)

    #set Attr_property
    attr_prop = Attr_property(aot=aot, attr=attr)
   
    attr_prop.setDisplayed(displayed)
    attr_prop.setRequired(required)
    attr_prop.setMultiple(multiple)
    attr_prop.setReadOnly(read_only)
    attr_prop.setHidden(hidden)
    attr_prop.setCalculable(calculable)
示例#2
0
def worker(req):
    """ 
    получение потомков
    """
    error = False
    tree = []
    
    schema      = req.params()['attr_schema']

    #получаем атрибуты
    attrs       = req.params()['attrs']

    #получаем параметры
    name        = req.params()['name']
    description = req.params()['description']
    def_value   = req.params()['def_value']
    mask        = req.params()['mask']
    type        = req.params()['type']
    
    displayed   = req.params()['displayed']
    multiple    = req.params()['multiple']
    read_only   = req.params()['read_only']
    hidden      = req.params()['hidden']
    required    = req.params()['required']
    calculable  = req.params()['calculable']

    if  name      == None and description == None and def_value == None and \
        mask      == None and type        == None and displayed == None and \
        multiple  == None and read_only   == None and hidden    == None and \
        required  == None and calculable  == None:

        error = True
        reason = "Не отмечено ни одно свойство для изменения"
    else:
        
        #обновляем настоящие атрибуты
        for attr in attrs:
            if name != None:        attr.name        = name
            if description != None: attr.description = description
            if def_value != None:   attr.def_value   = def_value
            if mask != None:        attr.mask        = mask
            if type != None:        attr.type        = type

            #set Attr_property
            aots = AOT.objects.filter(schema=schema, attr=attr)
            for aot in aots:
                attr_prop = Attr_property(aot=aot, attr=attr)
                        
                attr_prop.setDisplayed(displayed)
                attr_prop.setRequired(required)
                attr_prop.setMultiple(multiple)
                attr_prop.setReadOnly(read_only)
                attr_prop.setHidden(hidden)
                attr_prop.setCalculable(calculable)
            
            #обновляем Bulk Edit атрибуты
            if name:
                attr = Tree_bulk_edit.objects.get(orig_id=attr.id.__int__(), type='attr')
                attr.name = name
                
                #сохраняем атрибут
                attr.save()            
    if error:
        return { "success": False, "errors": reason }        
    else:
        return { "success": True, "message": "Атрибуты успешно отредактированы" }
示例#3
0
def worker(req):
    """
    функция модификации атрибута
    """

    schema = req.params()["attr_schema"]
    object_type = req.params()["object_type"]
    group = req.params()["attr_group"]

    name = req.params()["name"]
    description = req.params()["description"]
    type = req.params()["type"]
    def_value = req.params()["def_value"]
    mask = req.params()["mask"]
    tags = req.params()["tags"]

    displayed = req.params()["displayed"]
    multiple = req.params()["multiple"]
    read_only = req.params()["read_only"]
    hidden = req.params()["hidden"]
    required = req.params()["required"]
    calculable = req.params()["calculable"]

    # создаём атрибут
    attr = ATTR.objects.create(
        id=nc_id.get(),
        group=group,
        schema=schema,
        type=type,
        name=name,
        description=description,
        def_value=def_value,
        mask=mask,
    )

    # создаём AOT
    AOT().create(schema=schema, object_type=object_type, attr=attr, options=0)
    aot = AOT.objects.get(schema=schema, object_type=object_type, attr=attr)

    # set Attr_property
    attr_prop = Attr_property(aot=aot, attr=attr)

    attr_prop.setDisplayed(displayed)
    attr_prop.setRequired(required)
    attr_prop.setMultiple(multiple)
    attr_prop.setReadOnly(read_only)
    attr_prop.setHidden(hidden)
    attr_prop.setCalculable(calculable)

    # обновляем Tag если Tags пришли
    if not tags == -1:
        attr.set(tags=tags)

    # TYPE
    if attr.type.id == 7:
        # это List
        req = ListRequired(request=req.request, req_params=["ref_list"])

        if req.success():
            # создаём ссылку на List
            attr.type_def = req.params()["ref_list"]
        else:
            return {"success": False, "errors": req.errors()}

    if attr.type.id == 9:
        # это Reference
        req = OTRequired(request=req.request, req_params=["ref_object_type"])

        if req.success():
            # создаём Reference
            attr.type_def = Type_def.objects.create(
                id=nc_id.get(), type=attr.type, schema=schema, object_type=req.params()["ref_object_type"]
            )
        else:
            return {"success": False, "errors": req.errors()}

    # сохраняем атрибут
    attr.save()

    return {"success": True, "message": "Атрибут %s успешно создан" % str(attr.id)}