user model needed its GetValidators method
[plstackapi.git] / planetstack / core / models / user.py
index b30e897..7fdde19 100644 (file)
@@ -1,6 +1,7 @@
 import os
 import datetime
 import sys
+import hashlib
 from collections import defaultdict
 from django.forms.models import model_to_dict
 from django.db import models
@@ -111,8 +112,28 @@ class User(AbstractBaseUser): #, 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 ----
 
+    @property
+    def remote_password(self):
+        return hashlib.md5(self.password).hexdigest()[:12]
+
     class Meta:
         app_label = "core"