summaryrefslogtreecommitdiff
path: root/main/fields.py
diff options
context:
space:
mode:
authorNicolás Reynolds <fauno@kiwwwi.com.ar>2011-12-04 23:07:59 -0300
committerNicolás Reynolds <fauno@kiwwwi.com.ar>2011-12-04 23:07:59 -0300
commit988c2c6d400b3721464c2891891807d504b076b0 (patch)
tree013dc3d676edad701d0d3bbd239bc2df0cdf76b4 /main/fields.py
parent60a1fc6cc4cef0b9eed58ea4f0ca003b76ec382a (diff)
parent183c4d9cefa95f46c3fa3a6936f837542426eac2 (diff)
Merge branch 'master' of ssh://gparabola/parabolaweb
Conflicts: local_settings.py.example media/archweb.css packages/templatetags/package_extras.py public/views.py templates/packages/details.html templates/packages/flag.html templates/packages/flag_confirmed.html templates/packages/flagged.html templates/packages/search.html templates/public/download.html templates/todolists/view.html
Diffstat (limited to 'main/fields.py')
-rw-r--r--main/fields.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/main/fields.py b/main/fields.py
new file mode 100644
index 00000000..948cb5d9
--- /dev/null
+++ b/main/fields.py
@@ -0,0 +1,42 @@
+from django.db import models
+from django.core.validators import RegexValidator
+
+
+class PositiveBigIntegerField(models.BigIntegerField):
+ _south_introspects = True
+
+ def get_internal_type(self):
+ return "BigIntegerField"
+
+ def formfield(self, **kwargs):
+ defaults = { 'min_value': 0 }
+ defaults.update(kwargs)
+ return super(PositiveBigIntegerField, self).formfield(**defaults)
+
+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: