def reset(self): proxy = self.proxy self.field_type = proxy.field_type # ALL field types... self.property_title = pretty_string(proxy.name) self.order = proxy.order self.is_required = proxy.is_required() self.is_hidden = False self.is_editable = True self.is_nillable = not proxy.is_required() self.documentation = proxy.documentation self.inline_help = False assert self.category is not None # even "uncategorized" properties should use the "UncategorizedCategory" # ATOMIC fields... if self.field_type == QPropertyTypes.ATOMIC: self.atomic_default = proxy.atomic_default self.atomic_type = proxy.atomic_type self.atomic_suggestions = "" # ENUMERATION fields... elif self.field_type == QPropertyTypes.ENUMERATION: self.enumeration_open = proxy.enumeration_open # TODO: DO I NEED TO DEAL W/ "enumeration_choices" OR "enumeration_default" ? # RELATIONSHIP fields... else: # self.field_type == QPropertyTypes.RELATIONSHIP: self.relationship_show_subform = not self.use_references()
def reset(self): proxy = self.proxy self.order = proxy.order self.model_title = pretty_string(proxy.name) self.model_description = proxy.documentation self.model_show_all_categories = False
def reset(self, proxy): self.proxy = proxy self.model_title = pretty_string(proxy.name) self.model_description = proxy.documentation self.model_show_all_categories = self.get_field("model_show_all_categories").default self.model_show_hierarchy = self.get_field("model_show_hierarchy").default self.model_hierarchy_name = self.get_field("model_hierarchy_name").default self.model_root_component = self.get_field("model_root_component").default
def reset(self, proxy, reset_keys=True): self.proxy = proxy self.name = proxy.name self.order = proxy.order self.cardinality = proxy.cardinality self.field_type = proxy.field_type # any field... self.displayed = True self.required = proxy.is_required() self.editable = True self.unique = False self.verbose_name = pretty_string(proxy.name) self.documentation = proxy.documentation self.inline_help = False self.choice = proxy.choice self.display_extra_standard_name = False self.display_extra_description = False self.display_extra_units = False self.edit_extra_standard_name = False self.edit_extra_description = False self.edit_extra_units = False # atomic fields... if self.field_type == QPropertyTypes.ATOMIC: self.atomic_default = proxy.atomic_default self.atomic_type = proxy.atomic_type self.atomic_suggestions = "" # enumeration fields... elif self.field_type == QPropertyTypes.ENUMERATION: self.enumeration_choices = proxy.enumeration_choices # self.enumeration_default = self.enumeration_open = proxy.enumeration_open self.enumeration_multi = proxy.enumeration_multi self.enumeration_nullable = proxy.enumeration_nullable # relationship fields... else: # self.field_type == QPropertyTypes.RELATIONSHIP: msg = "ScientificProperties cannot be RELATIONSHIPS" raise QError(msg) if reset_keys: # there is no need to _always_ do this, # b/c in get_new_customization_set I have already passed these values in as strings # (which is faster than these fk lookups) component = proxy.component_proxy vocabulary = component.vocabulary self.component_key = component.guid self.vocabulary_key = vocabulary.guid
def __call__(self, attrs): """ this is basically like the parent class __call__ fn, except that I allow certain missing fields for new instances, and any error messages are spread out among all the "unique_together" fields """ # if this is a CREATE then check for missing fields; # so long as the missing field is exempt, assume it will be added in later # and the model will validate eventually missing_fields = None if self.instance is None: missing_fields = dict([ (field_name, self.missing_message) for field_name in self.fields if field_name not in attrs ]) if set(missing_fields.keys()) - set(self.exempt_fields): raise ValidationError(missing_fields) # If this is an UPDATE, then any unprovided field should # have it's value set based on the existing instance attribute. if self.instance is not None: for field_name in self.fields: if field_name not in attrs: attrs[field_name] = getattr(self.instance, field_name) # narrow down the queryset... queryset = self.queryset filter_kwargs = dict([ (field_name, attrs[field_name]) for field_name in self.fields if field_name in attrs ]) queryset = queryset.filter(**filter_kwargs) if self.instance is not None: # "self.instance" will have been set by "QSerializer.to_internal_value" below queryset = queryset.exclude(pk=self.instance.pk) if not missing_fields and queryset.exists(): # the validation error is a dictionary of strings keyed by field_name # rather than a single string w/ the 'non_field_errors' key as w/ the base UniqueTogetherValidator class field_names = self.fields pretty_field_names = " / ".join([pretty_string(f) for f in field_names]) msg = self.message.format(pretty_field_names=pretty_field_names) raise ValidationError({ f: msg for f in field_names })
def validate_unique(self): model_realization = self.instance try: model_realization.validate_unique() except ValidationError as e: # if there is a validation error then apply that error to the individual fields # so it shows up in the form and is rendered nicely unique_together_fields_list = model_realization.get_unique_together() for unique_together_fields in unique_together_fields_list: if any(field.lower() in " ".join(e.messages).lower() for field in unique_together_fields): msg = [u'An instance with this {0} already exists.'.format( " / ".join([pretty_string(utf) for utf in unique_together_fields]) ) ] for unique_together_field in unique_together_fields: self.errors[unique_together_field] = msg
def reset(self, proxy): self.proxy = proxy self.name = proxy.name self.order = proxy.order self.cardinality = proxy.cardinality self.field_type = proxy.field_type # any field... self.displayed = True self.required = proxy.is_required() self.editable = True self.unique = False self.verbose_name = pretty_string(proxy.name) self.documentation = proxy.documentation self.inline_help = False self.inherited = False # atomic fields... if self.field_type == QPropertyTypes.ATOMIC: self.atomic_default = proxy.atomic_default self.atomic_type = proxy.atomic_type self.atomic_suggestions = "" # enumeration fields... elif self.field_type == QPropertyTypes.ENUMERATION: self.enumeration_choices = proxy.enumeration_choices # self.enumeration_default = self.enumeration_open = proxy.enumeration_open self.enumeration_multi = proxy.enumeration_multi self.enumeration_nullable = proxy.enumeration_nullable # relationship fields... else: # self.field_type == QPropertyTypes.RELATIONSHIP: self.relationship_show_subform = not self.use_reference()
def __str__(self): return pretty_string(self.name)
def title(self): proxy_id = self.proxy.cim_id proxy_title = proxy_id.rsplit('.')[-1] return pretty_string(proxy_title)
def __str__(self): return pretty_string(self.category_title)
def __unicode__(self): return pretty_string(self.name)
def __str__(self): # return self.cim_id return pretty_string(self.name)