Move magicdb handler to it's own file
authorMagnus Hagander <magnus@hagander.net>
Sat, 16 Jun 2018 18:13:44 +0000 (20:13 +0200)
committerMagnus Hagander <magnus@hagander.net>
Wed, 20 Jun 2018 11:47:59 +0000 (13:47 +0200)
If we want to use it from more than one place, it makes sense to have a
single central instance of it since each one of them otherwise has to
load and parse the magic database file.

postgresqleu/confreg/forms.py
postgresqleu/util/magic.py [new file with mode: 0644]

index 8f7c593feab618ae9aaeb1cfe6d3ffcd0e1e67a1..52768cc8c8df9c4b20c3e544e72483c2151d7da3 100644 (file)
@@ -15,17 +15,12 @@ from models import PrepaidVoucher, DiscountCode, AttendeeMail
 
 from regtypes import validate_special_reg_type
 from postgresqleu.util.validators import TwitterValidator
+from postgresqleu.util.magic import magicdb
 
 from postgresqleu.countries.models import Country
 
 from datetime import datetime, date
 import requests
-import magic
-
-
-# Globally load and cache the magicdb
-magicdb = magic.open(magic.MIME)
-magicdb.load()
 
 
 class ConferenceRegistrationForm(forms.ModelForm):
diff --git a/postgresqleu/util/magic.py b/postgresqleu/util/magic.py
new file mode 100644 (file)
index 0000000..d971720
--- /dev/null
@@ -0,0 +1,6 @@
+from __future__ import absolute_import
+import magic
+
+# Globally load and cache the magicdb
+magicdb = magic.open(magic.MIME)
+magicdb.load()