aboutsummaryrefslogtreecommitdiff
path: root/rpki/fields.py
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2015-10-25 22:25:40 +0000
committerRob Austein <sra@hactrn.net>2015-10-25 22:25:40 +0000
commit2c749a18db7886b7c9931f2b98eac6f099d304d2 (patch)
treeb4fb16f74a8e5ada8e84add05ef94d865c427383 /rpki/fields.py
parent95ef1c6d040c015615be01bee36547faf8432791 (diff)
Tweak binary field types to get SQLite3 working as a Django ORM
backend. Switch yamltest's default database configuration to sqlite3. MySQL still has character set issues, which are almost certainly to do with the communication channel rather than the database tables. It's possible that one of the newer DB API drivers for MySQL fixes this, might be worth trying one of them at some point (see the "MySQL notes" discussion of MySQL DB API drivers in the Django documentation). svn path=/branches/tk705/; revision=6149
Diffstat (limited to 'rpki/fields.py')
-rw-r--r--rpki/fields.py48
1 files changed, 22 insertions, 26 deletions
diff --git a/rpki/fields.py b/rpki/fields.py
index b0252840..a470e272 100644
--- a/rpki/fields.py
+++ b/rpki/fields.py
@@ -123,43 +123,39 @@ class BlobField(models.Field):
# a subclass of BinaryField instead, leave BlobField (for now) for
# backwards compatability during migrations,
-
class DERField(models.BinaryField):
"""
- Field class for DER objects. These are derived from BinaryField,
- but with automatic translation between ASN.1 and Python types.
-
- DERField itself is an abstract class, concrete field classes are
- derived from it.
+ Field class for DER objects, with automatic translation between
+ ASN.1 and Python types. This is an abstract class, concrete field
+ classes are derived from it.
"""
def __init__(self, *args, **kwargs):
- kwargs["serialize"] = False
kwargs["blank"] = True
kwargs["default"] = None
super(DERField, self).__init__(*args, **kwargs)
- if False:
- def to_python(self, value):
- assert value is None or isinstance(value, (self.rpki_type, str))
- if isinstance(value, str):
- return self.rpki_type(DER = value)
- else:
- return value
-
- def get_prep_value(self, value):
- assert value is None or isinstance(value, (self.rpki_type, str))
- if isinstance(value, self.rpki_type):
- return value.get_DER()
- else:
- return value
+ def deconstruct(self):
+ name, path, args, kwargs = super(DERField, self).deconstruct()
+ del kwargs["blank"]
+ del kwargs["default"]
+ return name, path, args, kwargs
def from_db_value(self, value, expression, connection, context):
- assert value is None or isinstance(value, (self.rpki_type, str))
- if isinstance(value, str):
- return self.rpki_type(DER = value)
- else:
- return value
+ if value is not None:
+ value = self.rpki_type(DER = str(value))
+ return value
+
+ def to_python(self, value):
+ value = super(DERField, self).to_python(value)
+ if value is not None and not isinstance(value, self.rpki_type):
+ value = self.rpki_type(DER = str(value))
+ return value
+
+ def get_prep_value(self, value):
+ if value is not None:
+ value = value.get_DER()
+ return super(DERField, self).get_prep_value(value)
class CertificateField(DERField):