X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetstack%2Fcore%2Fmodels%2Fplcorebase.py;h=4b63062d3c98a4c269745e3687f89c9cbc206a5d;hb=451c4fc73c5fbb698af6e67e9488c1e7d167d209;hp=95959f4e064118d0dda496a67e2a371847979178;hpb=3f130078930766267756b68e971e0a295d351740;p=plstackapi.git diff --git a/planetstack/core/models/plcorebase.py b/planetstack/core/models/plcorebase.py index 95959f4..4b63062 100644 --- a/planetstack/core/models/plcorebase.py +++ b/planetstack/core/models/plcorebase.py @@ -83,6 +83,22 @@ class DiffModelMixIn: def get_field_diff(self, field_name): return self.diff.get(field_name, None) + #classmethod + def getValidators(cls): + """ primarily for REST API, return a dictionary of field names mapped + to lists of the type of validations that need to be applied to + those fields. + """ + validators = {} + for field in cls._meta.fields: + l = [] + if field.blank==False: + l.append("notBlank") + if field.__class__.__name__=="URLField": + l.append("url") + validators[field.name] = l + return validators + class PlCoreBase(models.Model): # , DiffModelMixIn): objects = PlCoreBaseManager() deleted_objects = PlCoreBaseDeletionManager() @@ -118,15 +134,33 @@ class PlCoreBase(models.Model): # , DiffModelMixIn): def get_field_diff(self, field_name): return self.diff.get(field_name, None) + + #classmethod + def getValidators(cls): + """ primarily for REST API, return a dictionary of field names mapped + to lists of the type of validations that need to be applied to + those fields. + """ + validators = {} + for field in cls._meta.fields: + l = [] + if field.blank==False: + l.append("notBlank") + if field.__class__.__name__=="URLField": + l.append("url") + validators[field.name] = l + return validators + # ---- end copy stuff from DiffModelMixin ---- # default values for created and updated are only there to keep evolution # from failing. created = models.DateTimeField(auto_now_add=True, default=timezone.now) updated = models.DateTimeField(auto_now=True, default=timezone.now) - enacted = models.DateTimeField(null=True, default=None) + enacted = models.DateTimeField(null=True, blank=True, default=None) + policed = models.DateTimeField(null=True, blank=True, default=None) backend_status = models.CharField(max_length=140, - default="Provisioning in progress") + default="0 - Provisioning in progress") deleted = models.BooleanField(default=False) class Meta: @@ -206,19 +240,6 @@ class PlCoreBase(models.Model): # , DiffModelMixIn): def is_ephemeral(cls): return cls in ephemeral_models - def getValidators(self): - """ primarily for REST API, return a dictionary of field names mapped - to lists of the type of validations that need to be applied to - those fields. - """ - validators = {} - for field in self._meta.fields: - l = [] - if field.blank==False: - l.append("notBlank") - validators[field.name] = l - return validators -