Refactor activity feed template logic

Yay for removing arbitrary if/else chains!
This commit is contained in:
2020-05-30 14:00:26 +01:00
parent 156e639bac
commit e45324f5b4
5 changed files with 48 additions and 59 deletions

View File

@@ -176,18 +176,14 @@ class Asset(models.Model, RevisionMixin):
errdict["csa"] = ["The CSA of a cable must be more than 0"]
if not self.cable_type:
errdict["cable_type"] = ["A cable must have a type"]
# if not self.circuits or self.circuits <= 0:
# errdict["circuits"] = ["There must be at least one circuit in a cable"]
# if not self.cores or self.cores <= 0:
# errdict["cores"] = ["There must be at least one core in a cable"]
# if self.socket is None:
# errdict["socket"] = ["A cable must have a socket"]
# if self.plug is None:
# errdict["plug"] = ["A cable must have a plug"]
if errdict != {}: # If there was an error when validation
raise ValidationError(errdict)
@property
def activity_feed_string(self):
return str(self)
@receiver(pre_save, sender=Asset)
def pre_save_asset(sender, instance, **kwargs):