Changes for Tag and Report views; Reports can be run from the website
svn: r18297
This commit is contained in:
parent
a2e000a04d
commit
1740803a58
@ -386,6 +386,8 @@ class Tag(models.Model):
|
||||
last_saved = models.DateTimeField('last changed', auto_now=True)
|
||||
last_changed = models.DateTimeField('last changed', null=True,
|
||||
blank=True) # user edits
|
||||
last_changed_by = models.TextField(blank=True, null=True)
|
||||
|
||||
name = models.TextField('name')
|
||||
color = models.CharField(max_length=13) # "#000000000000" # Black
|
||||
priority = models.IntegerField('priority', blank=False)
|
||||
@ -410,6 +412,8 @@ class PrimaryObject(models.Model):
|
||||
last_saved = models.DateTimeField('last changed', auto_now=True)
|
||||
last_changed = models.DateTimeField('last changed', null=True,
|
||||
blank=True) # user edits
|
||||
last_changed_by = models.TextField(blank=True, null=True)
|
||||
|
||||
private = models.BooleanField('private')
|
||||
#attributes = models.ManyToManyField("Attribute", blank=True, null=True)
|
||||
cache = models.TextField(blank=True, null=True)
|
||||
@ -561,6 +565,7 @@ class SecondaryObject(models.Model):
|
||||
last_saved = models.DateTimeField('last changed', auto_now=True)
|
||||
last_changed = models.DateTimeField('last changed', null=True,
|
||||
blank=True) # user edits
|
||||
last_changed_by = models.TextField(blank=True, null=True)
|
||||
order = models.PositiveIntegerField(default=1)
|
||||
|
||||
class Surname(models.Model):
|
||||
@ -742,6 +747,8 @@ class BaseRef(models.Model):
|
||||
order = models.PositiveIntegerField()
|
||||
last_saved = models.DateTimeField('last changed', auto_now=True)
|
||||
last_changed = models.DateTimeField('last changed', null=True) # user edits
|
||||
last_changed_by = models.TextField(blank=True, null=True)
|
||||
|
||||
#attributes = models.ManyToManyField("Attribute", null=True)
|
||||
private = models.BooleanField()
|
||||
|
||||
@ -801,6 +808,19 @@ class MediaRef(BaseRef):
|
||||
def __unicode__(self):
|
||||
return "MediaRef to " + str(self.ref_object)
|
||||
|
||||
class Report(models.Model):
|
||||
name = models.TextField(blank=True, null=True)
|
||||
handle = models.TextField(blank=True, null=True) # report_id
|
||||
report_type = models.TextField(blank=True, null=True)
|
||||
options = models.TextField(blank=True, null=True)
|
||||
|
||||
class Result(models.Model):
|
||||
name = models.TextField(blank=True, null=True)
|
||||
filename = models.TextField(blank=True, null=True)
|
||||
run_on = models.DateTimeField('run on', auto_now=True)
|
||||
run_by = models.TextField('run by', blank=True, null=True)
|
||||
status = models.TextField(blank=True, null=True)
|
||||
|
||||
TABLES = [
|
||||
("abstract", mGrampsType),
|
||||
("type", NameType),
|
||||
@ -820,7 +840,6 @@ TABLES = [
|
||||
("type", LdsStatus),
|
||||
("type", ThemeType),
|
||||
("abstract", DateObject),
|
||||
("meta", Config),
|
||||
("abstract", PrimaryObject),
|
||||
("primary", Person),
|
||||
("primary", Family),
|
||||
@ -847,7 +866,10 @@ TABLES = [
|
||||
("ref", RepositoryRef),
|
||||
("ref", PersonRef),
|
||||
("ref", ChildRef),
|
||||
("ref", MediaRef)
|
||||
("ref", MediaRef),
|
||||
("system", Config),
|
||||
("system", Report),
|
||||
("system", Result),
|
||||
]
|
||||
|
||||
def no_style():
|
||||
@ -860,7 +882,7 @@ def no_style():
|
||||
def clear_tables(*categories):
|
||||
"""
|
||||
Clear the entries of categories of tables. Category is:
|
||||
"abstract", "type", "ref", "meta", "primary" and "secondary".
|
||||
"abstract", "type", "ref", "system", "primary" and "secondary".
|
||||
"""
|
||||
from django.db import connection, transaction
|
||||
cursor = connection.cursor()
|
||||
|
@ -21,6 +21,8 @@
|
||||
|
||||
""" Main view handlers """
|
||||
|
||||
import os
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Django Modules
|
||||
@ -29,7 +31,7 @@
|
||||
from django.contrib.auth import logout
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.paginator import Paginator, InvalidPage, EmptyPage
|
||||
from django.http import Http404, HttpResponseRedirect
|
||||
from django.http import Http404, HttpResponseRedirect, HttpResponse
|
||||
from django.shortcuts import get_object_or_404, render_to_response, redirect
|
||||
from django.template import Context, RequestContext, escape
|
||||
from django.db.models import Q
|
||||
@ -58,6 +60,7 @@ VIEWS = [(_('People'), 'person', Name),
|
||||
(_('Sources'), 'source', Source),
|
||||
(_('Places'), 'place', Place),
|
||||
(_('Repositories'), 'repository', Repository),
|
||||
(_('Tags'), 'tag', Tag),
|
||||
]
|
||||
|
||||
def context_processor(request):
|
||||
@ -228,6 +231,39 @@ def view_name_detail(request, handle, order, action="view"):
|
||||
else:
|
||||
return render_to_response(view_template, context)
|
||||
|
||||
def send_file(request, filename):
|
||||
"""
|
||||
Send a file through Django without loading the whole file into
|
||||
memory at once. The FileWrapper will turn the file object into an
|
||||
iterator for chunks of 8KB.
|
||||
"""
|
||||
from django.core.servers.basehttp import FileWrapper
|
||||
wrapper = FileWrapper(file(filename))
|
||||
response = HttpResponse(wrapper, mimetype='application/pdf')
|
||||
response['Content-Length'] = os.path.getsize(filename)
|
||||
return response
|
||||
|
||||
def process_action(request, view, handle, action):
|
||||
from cli.plug import run_report
|
||||
db = DbDjango()
|
||||
#context = RequestContext(request)
|
||||
#context["tview"] = "Results"
|
||||
#context["view"] = view
|
||||
#context["handle"] = handle
|
||||
#context["action"] = action
|
||||
#context["message"] = "Your report ran. How to download?"
|
||||
if view == "report":
|
||||
if action == "run":
|
||||
args = {}
|
||||
if request.GET.has_key("options"):
|
||||
options = request.GET.get("options")
|
||||
for pair in options.split(" "):
|
||||
key, value = pair.split("=", 1)
|
||||
args[key] = value
|
||||
run_report(db, handle, off="pdf", of=("%s.pdf" % handle), **args)
|
||||
# pid="I0363")
|
||||
#return render_to_response("process_action.html", context)
|
||||
return send_file(request, "%s.pdf" % handle)
|
||||
|
||||
def view_detail(request, view, handle, action="view"):
|
||||
context = RequestContext(request)
|
||||
@ -284,6 +320,20 @@ def view_detail(request, view, handle, action="view"):
|
||||
raise Http404(_("Requested %s does not exist.") % view)
|
||||
view_template = 'view_source_detail.html'
|
||||
context["tview"] = _("Source")
|
||||
elif view == "tag":
|
||||
try:
|
||||
obj = Tag.objects.get(handle=handle)
|
||||
except:
|
||||
raise Http404(_("Requested %s does not exist.") % view)
|
||||
view_template = 'view_tag_detail.html'
|
||||
context["tview"] = _("Tag")
|
||||
elif view == "report":
|
||||
try:
|
||||
obj = Report.objects.get(handle=handle)
|
||||
except:
|
||||
raise Http404(_("Requested %s does not exist.") % view)
|
||||
view_template = 'view_report_detail.html'
|
||||
context["tview"] = _("Report")
|
||||
else:
|
||||
raise Http404(_("Requested page type not known"))
|
||||
context[view] = obj
|
||||
@ -595,8 +645,28 @@ def view(request, view):
|
||||
object_list = Source.objects.filter(private).order_by("gramps_id")
|
||||
view_template = 'view_sources.html'
|
||||
total = Source.objects.all().count()
|
||||
elif view == "tag":
|
||||
if request.GET.has_key("search"):
|
||||
search = request.GET.get("search")
|
||||
object_list = Tag.objects \
|
||||
.filter(Q(name__icontains=search)) \
|
||||
.order_by("name")
|
||||
else:
|
||||
object_list = Tag.objects.order_by("name")
|
||||
view_template = 'view_tags.html'
|
||||
total = Tag.objects.all().count()
|
||||
elif view == "report":
|
||||
if request.GET.has_key("search"):
|
||||
search = request.GET.get("search")
|
||||
object_list = Report.objects \
|
||||
.filter(Q(name__icontains=search)) \
|
||||
.order_by("name")
|
||||
else:
|
||||
object_list = Report.objects.all()
|
||||
view_template = 'view_report.html'
|
||||
total = Report.objects.all().count()
|
||||
else:
|
||||
raise Http404("Requested page type not known")
|
||||
raise Http404("Requested page type '%s' not known" % view)
|
||||
|
||||
if request.user.is_authenticated():
|
||||
paginator = Paginator(object_list, 20)
|
||||
|
@ -62,6 +62,53 @@ for table, entries in [("grampsdb.config",
|
||||
("description", "\"database creation date/time\""),
|
||||
("value_type", "\"str\""),
|
||||
("value", ('"%s"' % time.strftime("%Y-%m-%d %H:%M")))),
|
||||
]),
|
||||
("grampsdb.report",
|
||||
[(("name", '"Ahnentafel Report"'),
|
||||
("handle", '"ancestor_report"'),
|
||||
("report_type", '"textreport"')),
|
||||
(("name", '"birthday_report"'),
|
||||
("handle", '"birthday_report"'),
|
||||
("report_type", '"textreport"')),
|
||||
(("name", '"custom_text"'),
|
||||
("handle", '"custom_text"'),
|
||||
("report_type", '"textreport"')),
|
||||
(("name", '"descend_report"'),
|
||||
("handle", '"descend_report"'),
|
||||
("report_type", '"textreport"')),
|
||||
(("name", '"det_ancestor_report"'),
|
||||
("handle", '"det_ancestor_report"'),
|
||||
("report_type", '"textreport"')),
|
||||
(("name", '"det_descendant_report"'),
|
||||
("handle", '"det_descendant_report"'),
|
||||
("report_type", '"textreport"')),
|
||||
(("name", '"endofline_report"'),
|
||||
("handle", '"endofline_report"'),
|
||||
("report_type", '"textreport"')),
|
||||
(("name", '"family_group"'),
|
||||
("handle", '"family_group"'),
|
||||
("report_type", '"textreport"')),
|
||||
(("name", '"indiv_complete"'),
|
||||
("handle", '"indiv_complete"'),
|
||||
("report_type", '"textreport"')),
|
||||
(("name", '"kinship_report"'),
|
||||
("handle", '"kinship_report"'),
|
||||
("report_type", '"textreport"')),
|
||||
(("name", '"tag_report"'),
|
||||
("handle", '"tag_report"'),
|
||||
("report_type", '"textreport"')),
|
||||
(("name", '"number_of_ancestors_report"'),
|
||||
("handle", '"number_of_ancestors_report"'),
|
||||
("report_type", '"textreport"')),
|
||||
(("name", '"place_report"'),
|
||||
("handle", '"place_report"'),
|
||||
("report_type", '"textreport"')),
|
||||
(("name", '"simple_book_title"'),
|
||||
("handle", '"simple_book_title"'),
|
||||
("report_type", '"textreport"')),
|
||||
(("name", '"summary"'),
|
||||
("handle", '"summary"'),
|
||||
("report_type", '"textreport"')),
|
||||
])]:
|
||||
entry_count = 0
|
||||
for entry in entries:
|
||||
|
@ -29,4 +29,4 @@ import settings
|
||||
|
||||
import grampsdb.models as dj
|
||||
|
||||
dj.clear_tables("primary", "secondary", "ref")
|
||||
dj.clear_tables("primary", "secondary", "ref", "system")
|
||||
|
@ -39,7 +39,8 @@ from django.contrib import admin
|
||||
admin.autodiscover()
|
||||
|
||||
from web.grampsdb.views import (main_page, user_page, logout_page,
|
||||
view, view_detail, view_name_detail)
|
||||
process_action, view, view_detail,
|
||||
view_name_detail)
|
||||
|
||||
urlpatterns = patterns('',
|
||||
# Specific matches first:
|
||||
@ -73,6 +74,7 @@ urlpatterns += patterns('',
|
||||
(r'^(?P<view>(\w+))/(?P<handle>(\w+))/$', view_detail),
|
||||
(r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))$', view_name_detail),
|
||||
(r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))/(?P<action>(\w+))$', view_name_detail),
|
||||
(r'^(?P<view>(\w+))/(?P<handle>(\w+))/(?P<action>(\w+))$', process_action),
|
||||
)
|
||||
|
||||
# In urls:
|
||||
|
Loading…
Reference in New Issue
Block a user