def _update_ca_attrs_values(cls, obj, **arguments): """Update CA's (obj) attributes values according to dictionary of arguments (key = value). Restrictions: 'multi_choice_options' is a mandatory attribute for Dropdown CA and 'placeholder' is a attribute that exists only for Text and Rich Text CA. Generated data - 'obj', entered data - '**arguments'. """ # fix generated data if arguments.get("attribute_type"): obj.title = cls.generate_string(arguments["attribute_type"]) if (obj.multi_choice_options and obj.attribute_type == AdminWidgetCustomAttributes.DROPDOWN and arguments.get("attribute_type") != AdminWidgetCustomAttributes.DROPDOWN): obj.multi_choice_options = None # fix entered data if (arguments.get("multi_choice_options") and arguments.get("attribute_type") != AdminWidgetCustomAttributes.DROPDOWN): arguments["multi_choice_options"] = None if (arguments.get("placeholder") and arguments.get("attribute_type") not in (AdminWidgetCustomAttributes.TEXT, AdminWidgetCustomAttributes.RICH_TEXT)): arguments["placeholder"] = None # extend entered data if (arguments.get("attribute_type") == AdminWidgetCustomAttributes.DROPDOWN and not obj.multi_choice_options): obj.multi_choice_options = random_list_strings() return Entity.update_objs_attrs_values_by_entered_data(obj_or_objs=obj, **arguments)
def _update_ca_attrs_values(cls, obj, **arguments): """Update CA's (obj) attributes values according to dictionary of arguments (key = value). Restrictions: 'multi_choice_options' is a mandatory attribute for Dropdown CA and 'placeholder' is a attribute that exists only for Text and Rich Text CA. Generated data - 'obj', entered data - '**arguments'. """ # fix generated data if arguments.get("attribute_type"): obj.title = cls.generate_string(arguments["attribute_type"]) if (obj.multi_choice_options and obj.attribute_type == AdminWidgetCustomAttributes.DROPDOWN and arguments.get("attribute_type") != AdminWidgetCustomAttributes.DROPDOWN): obj.multi_choice_options = None # fix entered data if (arguments.get("multi_choice_options") and arguments.get("attribute_type") != AdminWidgetCustomAttributes.DROPDOWN): arguments["multi_choice_options"] = None if (arguments.get("placeholder") and arguments.get("attribute_type") not in (AdminWidgetCustomAttributes.TEXT, AdminWidgetCustomAttributes.RICH_TEXT)): arguments["placeholder"] = None # extend entered data if (arguments.get("attribute_type") == AdminWidgetCustomAttributes.DROPDOWN and not obj.multi_choice_options): obj.multi_choice_options = random_list_strings() return Entity.update_objs_attrs_values_by_entered_data( obj_or_objs=obj, **arguments)
def _fill_ca_entity_fields(cls, ca_object, **ca_object_fields): """Set the CustomAttributes object's attributes.""" if ca_object_fields.get("ca_type"): ca_object.ca_type = ca_object_fields["ca_type"] ca_object.title = cls._generate_title(ca_object.ca_type) if ca_object_fields.get("definition_type"): ca_object.definition_type = ca_object_fields["definition_type"] if ca_object_fields.get("title"): ca_object.title = ca_object_fields["definition_type"] # "Placeholder" field exists only for Text and Rich Text. if (ca_object_fields.get("placeholder") and ca_object.ca_type in (AdminWidgetCustomAttrs.TEXT, AdminWidgetCustomAttrs.RICH_TEXT)): ca_object.placeholder = ca_object_fields["placeholder"] if ca_object_fields.get("helptext"): ca_object.helptext = ca_object_fields["helptext"] if ca_object_fields.get("is_mandatory"): ca_object.is_mandatory = ca_object_fields["is_mandatory"] if ca_object_fields.get("ca_global"): ca_object.ca_global = ca_object_fields["ca_global"] # "Possible Values" - is a mandatory field for dropdown CustomAttribute. if ca_object.ca_type == AdminWidgetCustomAttrs.DROPDOWN: if (ca_object_fields.get("multi_choice_options") and ca_object_fields["multi_choice_options"] is not None): ca_object.multi_choice_options =\ ca_object_fields["multi_choice_options"] else: ca_object.multi_choice_options = random_list_strings(list_len=3) return ca_object
def _fill_ca_entity_fields(cls, ca_object, **ca_object_fields): """Set the CustomAttributes object's attributes.""" if ca_object_fields.get("ca_type"): ca_object.ca_type = ca_object_fields["ca_type"] ca_object.title = cls._generate_title(ca_object.ca_type) if ca_object_fields.get("definition_type"): ca_object.definition_type = ca_object_fields["definition_type"] if ca_object_fields.get("title"): ca_object.title = ca_object_fields["definition_type"] # "Placeholder" field exists only for Text and Rich Text. if (ca_object_fields.get("placeholder") and ca_object.ca_type in (AdminWidgetCustomAttrs.TEXT, AdminWidgetCustomAttrs.RICH_TEXT)): ca_object.placeholder = ca_object_fields["placeholder"] if ca_object_fields.get("helptext"): ca_object.helptext = ca_object_fields["helptext"] if ca_object_fields.get("is_mandatory"): ca_object.is_mandatory = ca_object_fields["is_mandatory"] if ca_object_fields.get("ca_global"): ca_object.ca_global = ca_object_fields["ca_global"] # "Possible Values" - is a mandatory field for dropdown CustomAttribute. if ca_object.ca_type == AdminWidgetCustomAttrs.DROPDOWN: if (ca_object_fields.get("multi_choice_options") and ca_object_fields["multi_choice_options"] is not None): ca_object.multi_choice_options =\ ca_object_fields["multi_choice_options"] else: ca_object.multi_choice_options = random_list_strings( list_len=3) return ca_object
def _create_random_ca(cls): """Create CustomAttribute entity with randomly filled fields.""" random_ca = CustomAttributeEntity() random_ca.type = cls.obj_ca random_ca.attribute_type = unicode( random.choice(AdminWidgetCustomAttributes.ALL_CA_TYPES)) random_ca.title = cls.generate_string(random_ca.attribute_type) if random_ca.attribute_type == AdminWidgetCustomAttributes.DROPDOWN: random_ca.multi_choice_options = random_list_strings() random_ca.definition_type = unicode( objects.get_singular(random.choice(objects.ALL_CA_OBJS))) random_ca.mandatory = False return random_ca
def _create_random_ca(cls): """Create CustomAttribute entity with randomly filled fields.""" random_ca = CustomAttributeEntity() random_ca.type = cls.obj_ca random_ca.attribute_type = unicode(random.choice( AdminWidgetCustomAttributes.ALL_CA_TYPES)) random_ca.title = cls.generate_string(random_ca.attribute_type) if random_ca.attribute_type == AdminWidgetCustomAttributes.DROPDOWN: random_ca.multi_choice_options = random_list_strings() random_ca.definition_type = unicode(objects.get_singular( random.choice(objects.ALL_CA_OBJS))) random_ca.mandatory = False return random_ca