aboutsummaryrefslogtreecommitdiff
path: root/rpkid/portal-gui/settings.py.in
diff options
context:
space:
mode:
Diffstat (limited to 'rpkid/portal-gui/settings.py.in')
-rw-r--r--rpkid/portal-gui/settings.py.in52
1 files changed, 37 insertions, 15 deletions
diff --git a/rpkid/portal-gui/settings.py.in b/rpkid/portal-gui/settings.py.in
index 19bad89b..8246304c 100644
--- a/rpkid/portal-gui/settings.py.in
+++ b/rpkid/portal-gui/settings.py.in
@@ -21,22 +21,44 @@ rpki.config.default_dirname = '%(AC_SYSCONFDIR)s'
# load the sql authentication bits from the system rpki.conf
rpki_config = rpki.config.parser(section='web_portal')
+
+def get_conv():
+ """Add a custom data converter to encode long() as a hex string
+ in generated SQL statements.
+
+ This is necessary since Django doesn't support binary field types, and
+ assumes all strings are UTF-8. Without this conversion, the generated SQL
+ uses a raw byte string.
+
+ See https://trac.rpki.net/ticket/434
+
+ """
+ from MySQLdb.converters import conversions
+ import types
+ conv = conversions.copy()
+ # WARNING: the extra percents in the following line are due to the fact
+ # that this entire script is used as a format string to generate
+ # settings.py
+ conv[types.LongType] = lambda x, conv: "0x%%x" %% x
+ return conv
+
DATABASES = {
- 'default': {
- 'ENGINE': 'django.db.backends.mysql',
- 'NAME': rpki_config.get('sql-database'),
- 'USER': rpki_config.get('sql-username'),
- 'PASSWORD': rpki_config.get('sql-password'),
-
- # Ensure the default storage engine is InnoDB since we need
- # foreign key support. The Django documentation suggests
- # removing this after the syncdb is performed as an optimization,
- # but there isn't an easy way to do this automatically.
-
- 'OPTIONS': {
- 'init_command': 'SET storage_engine=INNODB'
- }
- }
+ 'default': {
+ 'ENGINE': 'django.db.backends.mysql',
+ 'NAME': rpki_config.get('sql-database'),
+ 'USER': rpki_config.get('sql-username'),
+ 'PASSWORD': rpki_config.get('sql-password'),
+
+ # Ensure the default storage engine is InnoDB since we need
+ # foreign key support. The Django documentation suggests
+ # removing this after the syncdb is performed as an optimization,
+ # but there isn't an easy way to do this automatically.
+
+ 'OPTIONS': {
+ 'init_command': 'SET storage_engine=INNODB',
+ 'conv': get_conv(),
+ }
+ }
}