Better support for report options; added missing tag db functions;

svn: r20075
This commit is contained in:
Doug Blank 2012-07-25 05:02:02 +00:00
parent 4168033f83
commit 6ebcc8624e
4 changed files with 75 additions and 7 deletions

View File

@ -21,7 +21,10 @@
</tr>
<td class="ColumnAttribute">Options:</td>
<td class="ColumnValue" id="data">
<input autocomplete="off" name="options" id="get_focus" type="text" size="50" value="{% if report.options %}{{report.options}}{% else %}{% endif %}"></input><br>
<textarea autocomplete="off" name="options" id="get_focus" cols="70" rows="20">
{% if report.options %}{{report.options}}{% else %}{% endif %}
</textarea>
<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>
</td>
</tr>
@ -32,6 +35,12 @@
</td>
</form>
</tr>
<tr>
<td class="ColumnAttribute">Help:</td>
<td class="ColumnValue" id="data">
{{help|safe}}
</td>
</tr>
</table>

View File

@ -492,6 +492,12 @@ class DbDjango(DbWriteBase, DbReadBase):
obj = gen.lib.Researcher()
return obj
def get_tag_handles(self, sort_handles=False):
if sort_handles:
return [item.handle for item in self.dji.Tag.all().order_by("handle")]
else:
return [item.handle for item in self.dji.Tag.all()]
def get_person_handles(self, sort_handles=False):
if sort_handles:
return [item.handle for item in self.dji.Person.all().order_by("handle")]
@ -593,6 +599,15 @@ class DbDjango(DbWriteBase, DbReadBase):
return None
return self.make_person(person)
def get_tag_from_handle(self, handle):
if handle in self.import_cache:
return self.import_cache[handle]
try:
tag = self.dji.Tag.get(handle=handle)
except:
return None
return self.make_tag(tag)
def make_repository(self, repository):
if self.use_db_cache and repository.cache:
data = cPickle.loads(base64.decodestring(repository.cache))

View File

@ -195,16 +195,18 @@ def process_report_run(request, handle):
if report.options:
for pair in str(report.options).split(" "):
if "=" in pair:
key, value = pair.split("=", 1)
args[key] = value
key, value = [x.strip() for x in pair.split("=", 1)]
if key and value:
args[key] = value
# override from options on webpage:
if request.GET.has_key("options"):
options = str(request.GET.get("options"))
if options:
for pair in options.split(" "): # from webpage
for pair in options.split("\n"): # from webpage
if "=" in pair:
key, value = pair.split("=", 1)
args[key] = value
key, value = [x.strip() for x in pair.split("=", 1)]
if key and value:
args[key] = value
#############################################################################
if report.report_type == "report":
filename = "/tmp/%s-%s.%s" % (str(profile.user.username), str(handle), args["off"])
@ -437,6 +439,7 @@ def action(request, view, handle, act, add_to=None):
View a particular object given /object/handle (implied view),
/object/handle/action, or /object/add.
"""
from webapp.reports import get_plugin_options
# redirect:
rd = None
obj = None
@ -529,11 +532,34 @@ def action(request, view, handle, act, add_to=None):
view_template = 'view_tag_detail.html'
rd = process_tag(request, context, handle, act, add_to)
elif view == "report":
if act not in ["add", "create", "share", "save-share"]:
if act not in ["add", "create"]:
try:
obj = Report.objects.get(handle=handle)
except:
raise Http404(_("Requested %s does not exist.") % view)
override = {}
if obj.options:
for pair in obj.options.split(" "):
key, value = pair.split("=")
override[key] = value
db = DbDjango()
opt_default, opt_help = get_plugin_options(db, obj.handle)
retval = ""
for key in sorted(opt_default.keys()):
if key in override:
retval += "%s=%s\n" % (key, override[key])
del override[key]
else:
retval += "%s=%s\n" % (key, repr(opt_default[key]))
# Any leftover overrides:
for key in sorted(override.keys()):
retval += "%s=%s\n" % (key, override[key])
obj.options = retval
retval = "<ol>"
for key in sorted(opt_help.keys()):
retval += "<li><b>%s</b>: %s</li>\n" % (key, opt_help[key][1])
retval += "</ol>"
context["help"] = retval
view_template = 'view_report_detail.html'
rd = process_report(request, context, handle, act)
else:

View File

@ -41,6 +41,24 @@ import os
# db = dbdjango.DbDjango()
# run_report(db, "ancestor_report", off="txt", of="ar.txt", pid="I0363")
def get_plugin_options(db, pid):
"""
Get the default options and help for this plugin.
"""
dbstate = DbState()
climanager = CLIManager(dbstate, False) # do not load db_loader
climanager.do_reg_plugins(dbstate, None)
pmgr = BasePluginManager.get_instance()
pdata = pmgr.get_plugin(pid)
if hasattr(pdata, "optionclass") and pdata.optionclass:
mod = pmgr.load_plugin(pdata)
optionclass = eval("mod." + pdata.optionclass)
optioninstance = optionclass("Name", db)
optioninstance.load_previous_values()
return optioninstance.options_dict, optioninstance.options_help
else:
return {}, {}
def import_file(db, filename, user):
"""
Import a file (such as a GEDCOM file) into the given db.