-
Notifications
You must be signed in to change notification settings - Fork 1
Sourcery refactored master branch #2
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -237,11 +237,13 @@ def validate_value(self, value): | |
''' | ||
for validator in self.get_validators(): | ||
validator(value) | ||
if self.datatype == self.TYPE_ENUM: | ||
if value not in self.enum_group.enums.all(): | ||
raise ValidationError(_(u"%(enum)s is not a valid choice " | ||
u"for %(attr)s") % \ | ||
{'enum': value, 'attr': self}) | ||
if ( | ||
self.datatype == self.TYPE_ENUM | ||
and value not in self.enum_group.enums.all() | ||
): | ||
raise ValidationError(_(u"%(enum)s is not a valid choice " | ||
u"for %(attr)s") % \ | ||
{'enum': value, 'attr': self}) | ||
Comment on lines
-240
to
+246
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
def save(self, *args, **kwargs): | ||
''' | ||
|
@@ -274,7 +276,7 @@ def get_choices(self): | |
Returns a query set of :class:`EnumValue` objects for this attribute. | ||
Returns None if the datatype of this attribute is not *TYPE_ENUM*. | ||
''' | ||
if not self.datatype == Attribute.TYPE_ENUM: | ||
if self.datatype != Attribute.TYPE_ENUM: | ||
Comment on lines
-277
to
+279
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
return None | ||
return self.enum_group.enums.all() | ||
|
||
|
@@ -297,12 +299,12 @@ def save_value(self, entity, value): | |
entity_id=entity.pk, | ||
attribute=self) | ||
except Value.DoesNotExist: | ||
if value == None or value == '': | ||
if value in [None, '']: | ||
return | ||
value_obj = Value.objects.create(entity_ct=ct, | ||
entity_id=entity.pk, | ||
attribute=self) | ||
if value == None or value == '': | ||
if value is None or value == '': | ||
Comment on lines
-300
to
+307
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
value_obj.delete() | ||
return | ||
|
||
|
@@ -371,13 +373,15 @@ def clean(self): | |
Raises ``ValidationError`` if this value's attribute is *TYPE_ENUM* | ||
and value_enum is not a valid choice for this value's attribute. | ||
''' | ||
if self.attribute.datatype == Attribute.TYPE_ENUM and \ | ||
self.value_enum: | ||
if self.value_enum not in self.attribute.enum_group.enums.all(): | ||
raise ValidationError(_(u"%(choice)s is not a valid " \ | ||
u"choice for %s(attribute)") % \ | ||
{'choice': self.value_enum, | ||
'attribute': self.attribute}) | ||
if ( | ||
self.attribute.datatype == Attribute.TYPE_ENUM | ||
and self.value_enum | ||
and self.value_enum not in self.attribute.enum_group.enums.all() | ||
): | ||
raise ValidationError(_(u"%(choice)s is not a valid " \ | ||
u"choice for %s(attribute)") % \ | ||
{'choice': self.value_enum, | ||
'attribute': self.attribute}) | ||
Comment on lines
-374
to
+384
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
def _get_value(self): | ||
''' | ||
|
@@ -496,7 +500,7 @@ def validate_attributes(self): | |
'err': e}) | ||
|
||
def get_values_dict(self): | ||
values_dict = dict() | ||
values_dict = {} | ||
Comment on lines
-499
to
+503
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
for value in self.get_values(): | ||
values_dict[value.attribute.slug] = value.value | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,7 @@ def validate_text(value): | |
''' | ||
Raises ``ValidationError`` unless *value* type is ``str`` or ``unicode`` | ||
''' | ||
if not (type(value) == unicode or type(value) == str): | ||
if not type(value) in [unicode, str]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
raise ValidationError(_(u"Must be str or unicode")) | ||
|
||
|
||
|
@@ -82,7 +82,7 @@ def validate_bool(value): | |
''' | ||
Raises ``ValidationError`` unless *value* type is ``bool`` | ||
''' | ||
if not type(value) == bool: | ||
if type(value) != bool: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
raise ValidationError(_(u"Must be a boolean")) | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
BaseDynamicEntityForm._build_dynamic_fields
refactored with the following changes:de-morgan
)