Added a type to backend_status
[plstackapi.git] / planetstack / core / models / plcorebase.py
index e483a79..4b63062 100644 (file)
@@ -7,6 +7,7 @@ from django.forms.models import model_to_dict
 from django.utils import timezone
 from django.core.exceptions import PermissionDenied
 import model_policy
+from model_autodeletion import ephemeral_models
 
 try:
     # This is a no-op if observer_disabled is set to 1 in the config file
@@ -82,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()
@@ -117,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:
@@ -201,6 +236,12 @@ class PlCoreBase(models.Model): # , DiffModelMixIn):
         # filtering of visible objects by user.
         return cls.objects.all()
 
+    @classmethod
+    def is_ephemeral(cls):
+       return cls in ephemeral_models
+
+
+