Export from webapp is complete; working on import into webapp
svn: r18326
This commit is contained in:
parent
382336e9b5
commit
f492515494
@ -18,7 +18,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<td class="ColumnAttribute">Options:</td>
|
<td class="ColumnAttribute">Options:</td>
|
||||||
<td class="ColumnValue" id="data">
|
<td class="ColumnValue" id="data">
|
||||||
<input autocomplete="off" name="options" id="get_focus" type="text" size="50" value="{{report.options}}"></input><br>
|
<input autocomplete="off" name="options" id="get_focus" type="text" size="50" value="{% if report.options %}{{report.options}}{% else %}{% endif %}"></input><br>
|
||||||
<i>Hint</i>: use Gramps CLI options such as output file format <b>off=pdf</b>, <b>off=ged</b>, or <b>off=gramps</b>
|
<i>Hint</i>: use Gramps CLI options such as output file format <b>off=pdf</b>, <b>off=ged</b>, or <b>off=gramps</b>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
import cPickle
|
import cPickle
|
||||||
import base64
|
import base64
|
||||||
import web
|
|
||||||
import gen
|
import gen
|
||||||
import re
|
import re
|
||||||
from gen.db import DbReadBase, DbWriteBase, DbTxn
|
from gen.db import DbReadBase, DbWriteBase, DbTxn
|
||||||
@ -43,79 +42,6 @@ from gen.db import (PERSON_KEY,
|
|||||||
import Utils
|
import Utils
|
||||||
from web.libdjango import DjangoInterface
|
from web.libdjango import DjangoInterface
|
||||||
|
|
||||||
# Example for running a report:
|
|
||||||
# ------------------------------
|
|
||||||
# from cli.plug import run_report
|
|
||||||
# from django.conf import settings
|
|
||||||
# import web.settings as default_settings
|
|
||||||
# try:
|
|
||||||
# settings.configure(default_settings)
|
|
||||||
# except:
|
|
||||||
# pass
|
|
||||||
# import dbdjango
|
|
||||||
# db = dbdjango.DbDjango()
|
|
||||||
# run_report(db, "ancestor_report", off="txt", of="ar.txt", pid="I0363")
|
|
||||||
|
|
||||||
# Imports for importing a file:
|
|
||||||
import DbState
|
|
||||||
from cli.grampscli import CLIManager
|
|
||||||
from gen.plug import BasePluginManager
|
|
||||||
import os
|
|
||||||
|
|
||||||
def import_file(db, filename, callback):
|
|
||||||
"""
|
|
||||||
Import a file (such as a GEDCOM file) into the given db.
|
|
||||||
|
|
||||||
>>> import_file(DbDjango(), "/home/user/Untitled_1.ged", lambda a: a)
|
|
||||||
"""
|
|
||||||
dbstate = DbState.DbState()
|
|
||||||
climanager = CLIManager(dbstate, False) # do not load db_loader
|
|
||||||
climanager.do_reg_plugins(dbstate, None)
|
|
||||||
pmgr = BasePluginManager.get_instance()
|
|
||||||
(name, ext) = os.path.splitext(os.path.basename(filename))
|
|
||||||
format = ext[1:].lower()
|
|
||||||
import_list = pmgr.get_reg_importers()
|
|
||||||
for pdata in import_list:
|
|
||||||
if format == pdata.extension:
|
|
||||||
mod = pmgr.load_plugin(pdata)
|
|
||||||
if not mod:
|
|
||||||
for name, error_tuple in pmgr.get_fail_list():
|
|
||||||
etype, exception, traceback = error_tuple
|
|
||||||
print "ERROR:", name, exception
|
|
||||||
return False
|
|
||||||
import_function = getattr(mod, pdata.import_function)
|
|
||||||
db.prepare_import()
|
|
||||||
import_function(db, filename, callback)
|
|
||||||
db.commit_import()
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
def export_file(db, filename, callback):
|
|
||||||
"""
|
|
||||||
Export the db to a file (such as a GEDCOM file).
|
|
||||||
|
|
||||||
>>> export_file(DbDjango(), "/home/user/Untitled_1.ged", lambda a: a)
|
|
||||||
"""
|
|
||||||
dbstate = DbState.DbState()
|
|
||||||
climanager = CLIManager(dbstate, False) # do not load db_loader
|
|
||||||
climanager.do_reg_plugins(dbstate, None)
|
|
||||||
pmgr = BasePluginManager.get_instance()
|
|
||||||
(name, ext) = os.path.splitext(os.path.basename(filename))
|
|
||||||
format = ext[1:].lower()
|
|
||||||
export_list = pmgr.get_reg_exporters()
|
|
||||||
for pdata in export_list:
|
|
||||||
if format == pdata.extension:
|
|
||||||
mod = pmgr.load_plugin(pdata)
|
|
||||||
if not mod:
|
|
||||||
for name, error_tuple in pmgr.get_fail_list():
|
|
||||||
etype, exception, traceback = error_tuple
|
|
||||||
print "ERROR:", name, exception
|
|
||||||
return False
|
|
||||||
export_function = getattr(mod, pdata.export_function)
|
|
||||||
export_function(db, filename, callback)
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
class Cursor(object):
|
class Cursor(object):
|
||||||
def __init__(self, model, func):
|
def __init__(self, model, func):
|
||||||
self.model = model
|
self.model = model
|
||||||
@ -586,7 +512,6 @@ class DbDjango(DbWriteBase, DbReadBase):
|
|||||||
if handle in self.import_cache:
|
if handle in self.import_cache:
|
||||||
return self.import_cache[handle]
|
return self.import_cache[handle]
|
||||||
try:
|
try:
|
||||||
#person = self.dji.Person.select_related().get(handle=handle)
|
|
||||||
person = self.dji.Person.get(handle=handle)
|
person = self.dji.Person.get(handle=handle)
|
||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
@ -596,7 +521,7 @@ class DbDjango(DbWriteBase, DbReadBase):
|
|||||||
if self.use_db_cache and repository.cache:
|
if self.use_db_cache and repository.cache:
|
||||||
data = cPickle.loads(base64.decodestring(repository.cache))
|
data = cPickle.loads(base64.decodestring(repository.cache))
|
||||||
else:
|
else:
|
||||||
data = self.dji.get_family(family)
|
data = self.dji.get_repository(repository)
|
||||||
return gen.lib.Repository.create(data)
|
return gen.lib.Repository.create(data)
|
||||||
|
|
||||||
def make_source(self, source):
|
def make_source(self, source):
|
||||||
|
@ -884,6 +884,7 @@ def clear_tables(*categories):
|
|||||||
Clear the entries of categories of tables. Category is:
|
Clear the entries of categories of tables. Category is:
|
||||||
"abstract", "type", "ref", "system", "primary" and "secondary".
|
"abstract", "type", "ref", "system", "primary" and "secondary".
|
||||||
"""
|
"""
|
||||||
|
# FIXME: I don't think this works anymore...
|
||||||
from django.db import connection, transaction
|
from django.db import connection, transaction
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
flush_tables = []
|
flush_tables = []
|
||||||
|
@ -248,8 +248,9 @@ def send_file(request, filename, mimetype):
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
def process_action(request, view, handle, action):
|
def process_action(request, view, handle, action):
|
||||||
|
from web.reports import import_file
|
||||||
|
from web.reports import export_file
|
||||||
from cli.plug import run_report
|
from cli.plug import run_report
|
||||||
from web.dbdjango import export_file
|
|
||||||
db = DbDjango()
|
db = DbDjango()
|
||||||
if view == "report":
|
if view == "report":
|
||||||
if request.user.is_authenticated():
|
if request.user.is_authenticated():
|
||||||
|
74
src/web/reports.py
Normal file
74
src/web/reports.py
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
# imports for import/export:
|
||||||
|
|
||||||
|
import DbState
|
||||||
|
from cli.grampscli import CLIManager
|
||||||
|
from gen.plug import BasePluginManager
|
||||||
|
import os
|
||||||
|
|
||||||
|
# Example for running a report:
|
||||||
|
# ------------------------------
|
||||||
|
# from cli.plug import run_report
|
||||||
|
# from django.conf import settings
|
||||||
|
# import web.settings as default_settings
|
||||||
|
# try:
|
||||||
|
# settings.configure(default_settings)
|
||||||
|
# except:
|
||||||
|
# pass
|
||||||
|
# import dbdjango
|
||||||
|
# db = dbdjango.DbDjango()
|
||||||
|
# run_report(db, "ancestor_report", off="txt", of="ar.txt", pid="I0363")
|
||||||
|
|
||||||
|
def import_file(db, filename, callback):
|
||||||
|
"""
|
||||||
|
Import a file (such as a GEDCOM file) into the given db.
|
||||||
|
|
||||||
|
>>> import_file(DbDjango(), "/home/user/Untitled_1.ged", lambda a: a)
|
||||||
|
"""
|
||||||
|
dbstate = DbState.DbState()
|
||||||
|
climanager = CLIManager(dbstate, False) # do not load db_loader
|
||||||
|
climanager.do_reg_plugins(dbstate, None)
|
||||||
|
pmgr = BasePluginManager.get_instance()
|
||||||
|
(name, ext) = os.path.splitext(os.path.basename(filename))
|
||||||
|
format = ext[1:].lower()
|
||||||
|
import_list = pmgr.get_reg_importers()
|
||||||
|
for pdata in import_list:
|
||||||
|
if format == pdata.extension:
|
||||||
|
mod = pmgr.load_plugin(pdata)
|
||||||
|
if not mod:
|
||||||
|
for name, error_tuple in pmgr.get_fail_list():
|
||||||
|
etype, exception, traceback = error_tuple
|
||||||
|
print "ERROR:", name, exception
|
||||||
|
return False
|
||||||
|
import_function = getattr(mod, pdata.import_function)
|
||||||
|
db.prepare_import()
|
||||||
|
import_function(db, filename, callback)
|
||||||
|
db.commit_import()
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def export_file(db, filename, callback):
|
||||||
|
"""
|
||||||
|
Export the db to a file (such as a GEDCOM file).
|
||||||
|
|
||||||
|
>>> export_file(DbDjango(), "/home/user/Untitled_1.ged", lambda a: a)
|
||||||
|
"""
|
||||||
|
dbstate = DbState.DbState()
|
||||||
|
climanager = CLIManager(dbstate, False) # do not load db_loader
|
||||||
|
climanager.do_reg_plugins(dbstate, None)
|
||||||
|
pmgr = BasePluginManager.get_instance()
|
||||||
|
(name, ext) = os.path.splitext(os.path.basename(filename))
|
||||||
|
format = ext[1:].lower()
|
||||||
|
export_list = pmgr.get_reg_exporters()
|
||||||
|
for pdata in export_list:
|
||||||
|
if format == pdata.extension:
|
||||||
|
mod = pmgr.load_plugin(pdata)
|
||||||
|
if not mod:
|
||||||
|
for name, error_tuple in pmgr.get_fail_list():
|
||||||
|
etype, exception, traceback = error_tuple
|
||||||
|
print "ERROR:", name, exception
|
||||||
|
return False
|
||||||
|
export_function = getattr(mod, pdata.export_function)
|
||||||
|
export_function(db, filename, callback)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
@ -609,3 +609,4 @@ register_plugins()
|
|||||||
import HtmlDoc
|
import HtmlDoc
|
||||||
from libhtmlbackend import HtmlBackend
|
from libhtmlbackend import HtmlBackend
|
||||||
from libhtml import Html
|
from libhtml import Html
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user