summaryrefslogtreecommitdiff
path: root/devel/fields.py
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2012-04-20 10:21:28 -0500
committerDan McGee <dan@archlinux.org>2012-04-20 11:15:03 -0500
commitd21d8be0186413fe1fa5fd6c859786465472ee10 (patch)
tree2309796163078af30b05f340dbe0e816a92f6a84 /devel/fields.py
parentc1ccc88d0769afc16363ceb06e5bdcd8605455bf (diff)
UserProfile model and fields shuffle
Move this model into the devel/ application, and move the PGPKeyField which is used only by these models into the application as well. This involves updating some old migrations along the way to ensure we don't reference a field class that no longer exists. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'devel/fields.py')
-rw-r--r--devel/fields.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/devel/fields.py b/devel/fields.py
new file mode 100644
index 00000000..606ca63c
--- /dev/null
+++ b/devel/fields.py
@@ -0,0 +1,30 @@
+from django.db import models
+from django.core.validators import RegexValidator
+
+
+class PGPKeyField(models.CharField):
+ _south_introspects = True
+
+ def __init__(self, *args, **kwargs):
+ super(PGPKeyField, self).__init__(*args, **kwargs)
+ self.validators.append(RegexValidator(r'^[0-9A-F]{40}$',
+ "Ensure this value consists of 40 hex characters.", 'hex_char'))
+
+ def to_python(self, value):
+ if value == '' or value is None:
+ return None
+ value = super(PGPKeyField, self).to_python(value)
+ # remove all spaces
+ value = value.replace(' ', '')
+ # prune prefixes, either 0x or 2048R/ type
+ if value.startswith('0x'):
+ value = value[2:]
+ value = value.split('/')[-1]
+ # make all (hex letters) uppercase
+ return value.upper()
+
+ def formfield(self, **kwargs):
+ # override so we don't set max_length form field attribute
+ return models.Field.formfield(self, **kwargs)
+
+# vim: set ts=4 sw=4 et: