Commits

Luke Plant committed d0daa58

Better handling of skipped fields (make them visible)

Comments (0)

Files changed (1)

anonymizer/introspect.py

 
 from django.db.models import EmailField
 
-attribute_template = "        '%(attname)s': %(replacer)s,"
-
-class_template = """
-class %(modelname)sAnonymizer(Anonymizer):
-
-    model = %(modelname)s
-
-    attributes = {
-%(attributes)s
-    }
-"""
-
 field_replacers = {
     'AutoField': None,
     'ForeignKey': None,
 
     return r
 
+attribute_template = "        '%(attname)s': %(replacer)s,"
+skipped_template   = "         # Skipping field %s"
+class_template = """
+class %(modelname)sAnonymizer(Anonymizer):
+
+    model = %(modelname)s
+
+    attributes = {
+%(attributes)s
+    }
+"""
+
 def create_anonymizer(model):
-    replacers = []
+    attributes = []
     for f in model._meta.fields:
         replacer = get_replacer_for_field(f)
-        if replacer is not None:
-            replacers.append((f.attname, replacer))
+        if replacer is None:
+            attributes.append(skipped_template % f.attname)
+        else:
+            attributes.append(attribute_template % {'attname': f.attname,
+                                                    'replacer': replacer })
+    return class_template % {'modelname':model.__name__,
+                             'attributes': "\n".join(attributes) }
 
-    attributes = "\n".join(attribute_template % {'attname': att,
-                                                 'replacer': replacer }
-                           for att, replacer in replacers)
-    return class_template % {'modelname':model.__name__,
-                             'attributes': attributes }
-