DjangoDb: now with new Metadata table
This commit is contained in:
parent
e45dc665c9
commit
f7afd1fa75
@ -19,6 +19,18 @@
|
|||||||
|
|
||||||
""" Implements a Db interface """
|
""" Implements a Db interface """
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Gramps Modules
|
||||||
|
#
|
||||||
|
#------------------------------------------------------------------------
|
||||||
|
import pickle
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
## add this directory to sys path, so we can find django_support later:
|
||||||
|
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# Gramps Modules
|
# Gramps Modules
|
||||||
@ -28,10 +40,6 @@ from gramps.gen.db.generic import *
|
|||||||
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
||||||
_ = glocale.translation.gettext
|
_ = glocale.translation.gettext
|
||||||
|
|
||||||
## add this directory to sys path, so we can find django_support later:
|
|
||||||
import sys
|
|
||||||
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
|
||||||
|
|
||||||
class DbDjango(DbGeneric):
|
class DbDjango(DbGeneric):
|
||||||
|
|
||||||
def restore(self):
|
def restore(self):
|
||||||
@ -54,7 +62,7 @@ class DbDjango(DbGeneric):
|
|||||||
self.load(directory)
|
self.load(directory)
|
||||||
|
|
||||||
def initialize_backend(self, directory):
|
def initialize_backend(self, directory):
|
||||||
self._metadata = {}
|
pass
|
||||||
|
|
||||||
def close_backend(self):
|
def close_backend(self):
|
||||||
pass
|
pass
|
||||||
@ -118,16 +126,24 @@ class DbDjango(DbGeneric):
|
|||||||
def transaction_abort(self, txn):
|
def transaction_abort(self, txn):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_metadata(self, key, default=[]):
|
def get_metadata(self, setting, default=[]):
|
||||||
if key in self._metadata:
|
metadata = self.dji.Metadata.filter(setting=setting)
|
||||||
return self._metadata[key]
|
if metadata.count() > 0:
|
||||||
|
return pickle.loads(metadata[0].value)
|
||||||
elif default == []:
|
elif default == []:
|
||||||
return []
|
return []
|
||||||
else:
|
else:
|
||||||
return default
|
return default
|
||||||
|
|
||||||
def set_metadata(self, key, value):
|
def set_metadata(self, setting, value):
|
||||||
self._metadata[key] = value
|
from gramps.webapp.grampsdb.models import Metadata
|
||||||
|
metadata = self.dji.Metadata.filter(setting=setting)
|
||||||
|
if metadata.count() > 0:
|
||||||
|
metadata = metadata[0]
|
||||||
|
metadata.value = pickle.dumps(value)
|
||||||
|
else:
|
||||||
|
metadata = Metadata(setting=setting, value=pickle.dumps(value))
|
||||||
|
metadata.save()
|
||||||
|
|
||||||
def get_name_group_keys(self):
|
def get_name_group_keys(self):
|
||||||
return []
|
return []
|
||||||
@ -634,20 +650,14 @@ class DbDjango(DbGeneric):
|
|||||||
force_bsddb_upgrade=False,
|
force_bsddb_upgrade=False,
|
||||||
force_bsddb_downgrade=False,
|
force_bsddb_downgrade=False,
|
||||||
force_python_upgrade=False):
|
force_python_upgrade=False):
|
||||||
super().load(directory,
|
|
||||||
callback,
|
|
||||||
mode,
|
|
||||||
force_schema_upgrade,
|
|
||||||
force_bsddb_upgrade,
|
|
||||||
force_bsddb_downgrade,
|
|
||||||
force_python_upgrade)
|
|
||||||
# Django-specific loads:
|
# Django-specific loads:
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
LOG.info("Django loading...")
|
LOG.info("Django loading...")
|
||||||
default_settings = {"__file__":
|
default_settings = {"__file__":
|
||||||
os.path.join(self._directory, "default_settings.py")}
|
os.path.join(directory, "default_settings.py")}
|
||||||
settings_file = os.path.join(self._directory, "default_settings.py")
|
settings_file = os.path.join(directory, "default_settings.py")
|
||||||
with open(settings_file) as f:
|
with open(settings_file) as f:
|
||||||
code = compile(f.read(), settings_file, 'exec')
|
code = compile(f.read(), settings_file, 'exec')
|
||||||
exec(code, globals(), default_settings)
|
exec(code, globals(), default_settings)
|
||||||
@ -658,7 +668,7 @@ class DbDjango(DbGeneric):
|
|||||||
def __getattr__(self, item):
|
def __getattr__(self, item):
|
||||||
return self.dictionary[item]
|
return self.dictionary[item]
|
||||||
|
|
||||||
LOG.info("Django loading defaults from: " + self._directory)
|
LOG.info("Django loading defaults from: " + directory)
|
||||||
try:
|
try:
|
||||||
settings.configure(Module(default_settings))
|
settings.configure(Module(default_settings))
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
@ -671,6 +681,13 @@ class DbDjango(DbGeneric):
|
|||||||
from gramps.webapp.libdjango import DjangoInterface
|
from gramps.webapp.libdjango import DjangoInterface
|
||||||
|
|
||||||
self.dji = DjangoInterface()
|
self.dji = DjangoInterface()
|
||||||
|
super().load(directory,
|
||||||
|
callback,
|
||||||
|
mode,
|
||||||
|
force_schema_upgrade,
|
||||||
|
force_bsddb_upgrade,
|
||||||
|
force_bsddb_downgrade,
|
||||||
|
force_python_upgrade)
|
||||||
|
|
||||||
def _make_repository(self, repository):
|
def _make_repository(self, repository):
|
||||||
if self.use_db_cache and repository.cache:
|
if self.use_db_cache and repository.cache:
|
||||||
|
@ -1104,6 +1104,10 @@ class Result(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.name)
|
return str(self.name)
|
||||||
|
|
||||||
|
class Metadata(models.Model):
|
||||||
|
setting = models.TextField(blank=False, null=False)
|
||||||
|
value = models.BinaryField()
|
||||||
|
|
||||||
TABLES = [
|
TABLES = [
|
||||||
("abstract", mGrampsType),
|
("abstract", mGrampsType),
|
||||||
("type", NameType),
|
("type", NameType),
|
||||||
|
Loading…
Reference in New Issue
Block a user