Webapp: changes for web portion to use new Django interface

This commit is contained in:
Doug Blank 2015-08-21 17:24:14 -04:00
parent a93872a0f3
commit 4f4fe6c0de
7 changed files with 214 additions and 219 deletions

View File

@ -20,7 +20,7 @@
""" Views for Person, Name, and Surname """
## Gramps Modules
from gramps.webapp.utils import _, boolean, update_last_changed, build_search
from gramps.webapp.utils import _, boolean, update_last_changed, build_search, db
from gramps.webapp.grampsdb.models import Event, EventType, EventRef, EventRoleType, Person
from gramps.webapp.grampsdb.forms import *
from gramps.webapp.libdjango import DjangoInterface, lookup_role_index
@ -33,7 +33,6 @@ from django.template import Context, RequestContext
## Globals
dji = DjangoInterface()
db = DbDjango()
dd = displayer.display
dp = parser.parse
@ -94,8 +93,8 @@ def recheck_birth_death_refs(person):
obj_type = ContentType.objects.get_for_model(person)
# Update Birth event references:
events = EventRef.objects.filter(
object_id=person.id,
object_type=obj_type,
object_id=person.id,
object_type=obj_type,
role_type=get_type_from_name(EventRoleType, "Primary"),
ref_object__event_type__val=EventType.BIRTH).order_by("order")
if events:
@ -108,8 +107,8 @@ def recheck_birth_death_refs(person):
person.birth_ref_index = -1
# Update Death event references:
events = EventRef.objects.filter(
object_id=person.id,
object_type=obj_type,
object_id=person.id,
object_type=obj_type,
role_type=get_type_from_name(EventRoleType, "Primary"),
ref_object__event_type__val=EventType.DEATH).order_by("order")
if events:
@ -120,7 +119,7 @@ def recheck_birth_death_refs(person):
else:
person.death = None
person.death_ref_index = -1
def process_event(request, context, handle, act, add_to=None): # view, edit, save
"""
Process act on person. Can return a redirect.
@ -138,24 +137,24 @@ def process_event(request, context, handle, act, add_to=None): # view, edit, sav
# Handle: edit, view, add, create, save, delete, share, save-share
if act == "share":
item, handle = add_to
context["pickform"] = PickForm("Pick event",
Event,
context["pickform"] = PickForm("Pick event",
Event,
(),
request.POST)
request.POST)
context["object_handle"] = handle
context["object_type"] = item
return render_to_response("pick.html", context)
elif act == "save-share":
item, handle = add_to
pickform = PickForm("Pick event",
Event,
item, handle = add_to
pickform = PickForm("Pick event",
Event,
(),
request.POST)
if pickform.data["picklist"]:
parent_model = dji.get_model(item) # what model?
parent_obj = parent_model.objects.get(handle=handle) # to add
ref_handle = pickform.data["picklist"]
ref_obj = Event.objects.get(handle=ref_handle)
ref_obj = Event.objects.get(handle=ref_handle)
dji.add_event_ref_default(parent_obj, ref_obj)
if item == "person": # then need to recheck birth/death indexes:
recheck_birth_death_refs(parent_obj)
@ -171,7 +170,7 @@ def process_event(request, context, handle, act, add_to=None): # view, edit, sav
event = Event(gramps_id=dji.get_next_id(Event, "E"))
eventform = EventForm(instance=event)
eventform.model = event
elif act in ["view", "edit"]:
elif act in ["view", "edit"]:
event = Event.objects.get(handle=handle)
genlibevent = db.get_event_from_handle(handle)
if genlibevent:
@ -179,7 +178,7 @@ def process_event(request, context, handle, act, add_to=None): # view, edit, sav
event.text = dd(date)
eventform = EventForm(instance=event)
eventform.model = event
elif act == "save":
elif act == "save":
event = Event.objects.get(handle=handle)
eventform = EventForm(request.POST, instance=event)
eventform.model = event
@ -193,7 +192,7 @@ def process_event(request, context, handle, act, add_to=None): # view, edit, sav
act = "view"
else:
act = "edit"
elif act == "create":
elif act == "create":
event = Event(handle=create_id())
eventform = EventForm(request.POST, instance=event)
eventform.model = event
@ -213,7 +212,7 @@ def process_event(request, context, handle, act, add_to=None): # view, edit, sav
act = "view"
else:
act = "add"
elif act == "delete":
elif act == "delete":
event = Event.objects.get(handle=handle)
delete_event(event)
return redirect("/event/")
@ -224,5 +223,5 @@ def process_event(request, context, handle, act, add_to=None): # view, edit, sav
context["object"] = event
context["event"] = event
context["action"] = act
return render_to_response(view_template, context)

View File

@ -20,7 +20,7 @@
""" Views for Person, Name, and Surname """
## Gramps Modules
from gramps.webapp.utils import _, boolean, update_last_changed, StyledNoteFormatter, parse_styled_text, build_search
from gramps.webapp.utils import _, boolean, update_last_changed, StyledNoteFormatter, parse_styled_text, build_search, db
from gramps.webapp.grampsdb.models import Note
from gramps.webapp.grampsdb.forms import *
from gramps.webapp.libdjango import DjangoInterface
@ -32,7 +32,6 @@ from django.template import Context, RequestContext
## Globals
dji = DjangoInterface()
db = DbDjango()
snf = StyledNoteFormatter(db)
# add a note to a person:
@ -59,24 +58,24 @@ def process_note(request, context, handle, act, add_to=None): # view, edit, save
# Handle: edit, view, add, create, save, delete, share, save-share
if act == "share":
item, handle = add_to
context["pickform"] = PickForm("Pick note",
Note,
context["pickform"] = PickForm("Pick note",
Note,
(),
request.POST)
request.POST)
context["object_handle"] = handle
context["object_type"] = item
return render_to_response("pick.html", context)
elif act == "save-share":
item, handle = add_to
pickform = PickForm("Pick note",
Note,
item, handle = add_to
pickform = PickForm("Pick note",
Note,
(),
request.POST)
if pickform.data["picklist"]:
parent_model = dji.get_model(item) # what model?
parent_obj = parent_model.objects.get(handle=handle) # to add
ref_handle = pickform.data["picklist"]
ref_obj = Note.objects.get(handle=ref_handle)
ref_obj = Note.objects.get(handle=ref_handle)
dji.add_note_ref(parent_obj, ref_obj)
parent_obj.save_cache() # rebuild cache
return redirect("/%s/%s%s#tab-notes" % (item, handle, build_search(request)))
@ -90,13 +89,13 @@ def process_note(request, context, handle, act, add_to=None): # view, edit, save
notetext = ""
noteform = NoteForm(instance=note, initial={"notetext": notetext})
noteform.model = note
elif act in ["view", "edit"]:
elif act in ["view", "edit"]:
note = Note.objects.get(handle=handle)
genlibnote = db.get_note_from_handle(note.handle)
notetext = snf.format(genlibnote)
noteform = NoteForm(instance=note, initial={"notetext": notetext})
noteform.model = note
elif act == "save":
elif act == "save":
note = Note.objects.get(handle=handle)
notetext = ""
noteform = NoteForm(request.POST, instance=note, initial={"notetext": notetext})
@ -108,12 +107,12 @@ def process_note(request, context, handle, act, add_to=None): # view, edit, save
note = noteform.save()
dji.save_note_markup(note, notedata[1])
note.save_cache()
notetext = noteform.data["notetext"]
notetext = noteform.data["notetext"]
act = "view"
else:
notetext = noteform.data["notetext"]
notetext = noteform.data["notetext"]
act = "edit"
elif act == "create":
elif act == "create":
note = Note(handle=create_id())
notetext = ""
noteform = NoteForm(request.POST, instance=note, initial={"notetext": notetext})
@ -132,12 +131,12 @@ def process_note(request, context, handle, act, add_to=None): # view, edit, save
dji.add_note_ref(obj, note)
obj.save_cache()
return redirect("/%s/%s#tab-notes" % (item, handle))
notetext = noteform.data["notetext"]
notetext = noteform.data["notetext"]
act = "view"
else:
notetext = noteform.data["notetext"]
notetext = noteform.data["notetext"]
act = "add"
elif act == "delete":
elif act == "delete":
# FIXME: delete markup too for this note
note = Note.objects.get(handle=handle)
note.delete()
@ -150,5 +149,5 @@ def process_note(request, context, handle, act, add_to=None): # view, edit, save
context["notetext"] = notetext
context["note"] = note
context["action"] = act
return render_to_response(view_template, context)

View File

@ -57,13 +57,13 @@ from gramps.version import VERSION
# Gramps-connect imports:
import gramps.webapp
from gramps.webapp.utils import _, build_args
from gramps.webapp.utils import _, build_args, db
from gramps.webapp.grampsdb.models import *
from gramps.webapp.grampsdb.view import *
from gramps.webapp.djangodb import DbDjango
import gramps.cli.user
# Menu: (<Nice name>, /<path>/, <Model> | None, Need authentication )
# Menu: (<Nice name>, /<path>/, <Model> | None, Need authentication )
MENU = [
(_('Browse'), 'browse', None, False),
(_('Reports'), 'report', Report, True),
@ -71,7 +71,7 @@ MENU = [
]
# Views: [(<Nice name plural>, /<name>/handle, <Model>), ]
VIEWS = [
(_('People'), 'person', Name),
(_('People'), 'person', Name),
(_('Families'), 'family', Family),
(_('Events'), 'event', Event),
(_('Notes'), 'note', Note),
@ -107,8 +107,8 @@ def context_processor(request):
search = request.GET.get("search", "") or request.POST.get("search", "")
page = request.GET.get("page", "") or request.POST.get("page", "")
context["page"] = page
context["search"] = search
context["page"] = page
context["search"] = search
context["args"] = build_args(search=search, page=page)
return context
@ -120,7 +120,7 @@ def main_page(request):
context["view"] = 'home'
context["tview"] = _('Home')
return render_to_response("main_page.html", context)
def logout_page(request):
"""
Logout a user.
@ -174,10 +174,10 @@ def timestamp():
return time.strftime("%Y-%m-%d:%H:%M:%S")
def send_file(request, filename, mimetype):
"""
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.
"""
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(open(filename, mode="rb"))
@ -196,7 +196,6 @@ def process_report_run(request, handle):
from gramps.webapp.reports import import_file, export_file, download
from gramps.cli.plug import run_report
import traceback
db = DbDjango()
if request.user.is_authenticated():
profile = request.user.profile
report = Report.objects.get(handle=handle)
@ -227,7 +226,7 @@ def process_report_run(request, handle):
export_file(db, filename, gramps.cli.user.User()) # callback
mimetype = 'text/plain'
elif report.report_type == "import":
filename = download(args["i"], "/tmp/%s-%s-%s.%s" % (str(profile.user.username),
filename = download(args["i"], "/tmp/%s-%s-%s.%s" % (str(profile.user.username),
str(handle),
timestamp(),
args["iff"]))
@ -311,7 +310,7 @@ def view_list(request, view):
object_list = Note.objects \
.filter(query) \
.order_by(*order) \
.distinct()
.distinct()
view_template = 'view_notes.html'
total = Note.objects.all().count()
elif view == "person":
@ -321,7 +320,7 @@ def view_list(request, view):
object_list = Name.objects \
.filter(query) \
.order_by(*order) \
.distinct()
.distinct()
view_template = 'view_people.html'
total = Name.objects.all().count()
elif view == "family":
@ -331,7 +330,7 @@ def view_list(request, view):
object_list = Family.objects \
.filter(query) \
.order_by(*order) \
.distinct()
.distinct()
view_template = 'view_families.html'
total = Family.objects.all().count()
elif view == "place":
@ -341,7 +340,7 @@ def view_list(request, view):
object_list = Place.objects \
.filter(query) \
.order_by(*order) \
.distinct()
.distinct()
view_template = 'view_places.html'
total = Place.objects.all().count()
elif view == "repository":
@ -351,7 +350,7 @@ def view_list(request, view):
object_list = Repository.objects \
.filter(query) \
.order_by(*order) \
.distinct()
.distinct()
view_template = 'view_repositories.html'
total = Repository.objects.all().count()
elif view == "citation":
@ -361,7 +360,7 @@ def view_list(request, view):
object_list = Citation.objects \
.filter(query) \
.order_by(*order) \
.distinct()
.distinct()
view_template = 'view_citations.html'
total = Citation.objects.all().count()
elif view == "source":
@ -371,7 +370,7 @@ def view_list(request, view):
object_list = Source.objects \
.filter(query) \
.order_by(*order) \
.distinct()
.distinct()
view_template = 'view_sources.html'
total = Source.objects.all().count()
elif view == "tag":
@ -381,7 +380,7 @@ def view_list(request, view):
object_list = Tag.objects \
.filter(query) \
.order_by(*order) \
.distinct()
.distinct()
view_template = 'view_tags.html'
total = Tag.objects.all().count()
elif view == "report":
@ -391,16 +390,16 @@ def view_list(request, view):
object_list = Report.objects \
.filter(query) \
.order_by(*order) \
.distinct()
.distinct()
view_template = 'view_report.html'
total = Report.objects.all().count()
else:
raise Http404("Requested page type '%s' not known" % view)
if request.user.is_authenticated():
paginator = Paginator(object_list, 20)
paginator = Paginator(object_list, 20)
else:
paginator = Paginator(object_list, 20)
paginator = Paginator(object_list, 20)
try:
page = int(request.GET.get('page', '1'))
@ -445,7 +444,7 @@ def add_share(request, view, item, handle):
"""
# /person/share/family/handle
# Use an existing person with this family
# r'^(?P<view>(\w+))/share/(?P<item>(\w+))/(?P<handle>(\w+))$',
# r'^(?P<view>(\w+))/share/(?P<item>(\w+))/(?P<handle>(\w+))$',
act = "share"
if "action" in request.POST:
act = request.POST.get("action") # can be "save-share"
@ -465,7 +464,6 @@ def action(request, view, handle, act, add_to=None):
/object/handle/action, or /object/add.
"""
from gramps.webapp.reports import get_plugin_options
db = DbDjango()
# redirect:
rd = None
obj = None
@ -641,7 +639,7 @@ def action(request, view, handle, act, add_to=None):
obj = Report.objects.get(handle=handle)
except:
raise Http404(_("Requested %s does not exist.") % view)
override = {}
override = {}
if obj.options:
for pair in obj.options.split("\\n"):
key, value = pair.split("=", 1)
@ -689,11 +687,11 @@ def build_string_query(field, value, exact=False, startswith=False, endswith=Fal
if exact:
retval = Q(**{"%s" % field: value})
elif startswith:
retval = Q(**{"%s__istartswith" % field: value})
retval = Q(**{"%s__istartswith" % field: value})
elif endswith:
retval = Q(**{"%s__iendswith" % field: value})
retval = Q(**{"%s__iendswith" % field: value})
else: # default
retval = Q(**{"%s__icontains" % field: value})
retval = Q(**{"%s__icontains" % field: value})
return retval
def build_person_query(request, search):
@ -704,11 +702,11 @@ def build_person_query(request, search):
protect = not request.user.is_authenticated()
### Build the order:
if protect:
# Do this to get the names sorted by private/alive
# Do this to get the names sorted by private/alive
# NOTE: names can be private
terms = ["surname", "given", "id", "tag"]
query = Q(private=False) & Q(person__private=False)
order = ["surname__surname", "private", "person__probably_alive",
order = ["surname__surname", "private", "person__probably_alive",
"first_name"]
else:
terms = ["surname", "given", "id", "tag", "public", "private"]
@ -775,11 +773,11 @@ def build_person_query(request, search):
make_message(request, "Invalid query field '%s'" % field)
else: # no search fields, just raw search
if protect:
query &= (Q(surname__surname__icontains=search) |
query &= (Q(surname__surname__icontains=search) |
Q(surname__prefix__icontains=search) |
Q(person__gramps_id__icontains=search))
else:
query &= (Q(surname__surname__icontains=search) |
query &= (Q(surname__surname__icontains=search) |
Q(first_name__icontains=search) |
Q(suffix__icontains=search) |
Q(surname__prefix__icontains=search) |
@ -798,21 +796,21 @@ def build_family_query(request, search):
protect = not request.user.is_authenticated()
if protect:
terms = ["father", "mother", "id", "type", "surnames", "tag"]
query = (Q(private=False) & Q(father__private=False) &
query = (Q(private=False) & Q(father__private=False) &
Q(mother__private=False))
order = ["father__name__surname__surname",
"father__private", "father__probably_alive",
order = ["father__name__surname__surname",
"father__private", "father__probably_alive",
"father__name__first_name",
"mother__name__surname__surname",
"mother__private", "mother__probably_alive",
"mother__name__surname__surname",
"mother__private", "mother__probably_alive",
"mother__name__first_name"]
else:
terms = ["father", "mother", "id", "type", "surnames", "father.name.first_name",
terms = ["father", "mother", "id", "type", "surnames", "father.name.first_name",
"mother.name.first_name", "tag", "public", "private"]
query = Q()
order = ["father__name__surname__surname",
order = ["father__name__surname__surname",
"father__name__first_name",
"mother__name__surname__surname",
"mother__name__surname__surname",
"mother__name__first_name"]
if search:
if "," in search or "=" in search:
@ -912,13 +910,13 @@ def build_media_query(request, search):
if "." in field and not protect:
query &= build_string_query(field.replace(".", "__"), value, exact, startswith, endswith)
elif field == "id":
query &= build_string_query("gramps_id", value, exact, startswith, endswith)
query &= build_string_query("gramps_id", value, exact, startswith, endswith)
elif field == "path":
query &= build_string_query("path", value, exact, startswith, endswith)
query &= build_string_query("path", value, exact, startswith, endswith)
elif field == "description":
query &= build_string_query("desc", value, exact, startswith, endswith)
query &= build_string_query("desc", value, exact, startswith, endswith)
elif field == "mime":
query &= build_string_query("mime", value, exact, startswith, endswith)
query &= build_string_query("mime", value, exact, startswith, endswith)
elif field == "tag":
query &= build_string_query("tags__name", value, exact, startswith, endswith)
elif field == "private":
@ -926,17 +924,17 @@ def build_media_query(request, search):
elif field == "public":
query &= Q(public=boolean(value))
else:
request.user.message_set.create(message="Invalid query field '%s'" % field)
request.user.message_set.create(message="Invalid query field '%s'" % field)
else: # no search fields, just raw search
if protect:
query &= (Q(gramps_id__icontains=search) |
Q(path__icontains=search) |
Q(desc__icontains=search) |
Q(desc__icontains=search) |
Q(mime__icontains=search))
else:
query &= (Q(gramps_id__icontains=search) |
Q(path__icontains=search) |
Q(desc__icontains=search) |
Q(desc__icontains=search) |
Q(mime__icontains=search))
else: # no search
pass # nothing left to do
@ -978,9 +976,9 @@ def build_note_query(request, search):
elif field == "id":
query &= build_string_query("gramps_id", value, exact, startswith, endswith)
elif field == "type":
query &= build_string_query("note_type__name", value, exact, startswith, endswith)
query &= build_string_query("note_type__name", value, exact, startswith, endswith)
elif field == "text":
query &= build_string_query("text", value, exact, startswith, endswith)
query &= build_string_query("text", value, exact, startswith, endswith)
elif field == "tag":
query &= build_string_query("tags__name", value, exact, startswith, endswith)
elif field == "private":
@ -988,7 +986,7 @@ def build_note_query(request, search):
elif field == "public":
query &= Q(public=boolean(value))
else:
request.user.message_set.create(message="Invalid query field '%s'" % field)
request.user.message_set.create(message="Invalid query field '%s'" % field)
else: # no search fields, just raw search
if protect:
query &= (Q(gramps_id__icontains=search) |
@ -1041,13 +1039,13 @@ def build_place_query(request, search):
elif field == "id":
query &= build_string_query("gramps_id", value, exact, startswith, endswith)
elif field == "title":
query &= build_string_query("title", value, exact, startswith, endswith)
query &= build_string_query("title", value, exact, startswith, endswith)
elif field == "private":
query &= Q(private=boolean(value))
elif field == "public":
query &= Q(public=boolean(value))
else:
request.user.message_set.create(message="Invalid query field '%s'" % field)
request.user.message_set.create(message="Invalid query field '%s'" % field)
else: # no search fields, just raw search
if protect:
query &= (Q(gramps_id__icontains=search) |
@ -1095,7 +1093,7 @@ def build_repository_query(request, search):
elif field == "id":
query &= build_string_query("gramps_id", value, exact, startswith, endswith)
elif field == "name":
query &= build_string_query("name", value, exact, startswith, endswith)
query &= build_string_query("name", value, exact, startswith, endswith)
elif field == "type":
query &= build_string_query("repository_type__name", value, exact, startswith, endswith)
elif field == "private":
@ -1103,7 +1101,7 @@ def build_repository_query(request, search):
elif field == "public":
query &= Q(public=boolean(value))
else:
request.user.message_set.create(message="Invalid query field '%s'" % field)
request.user.message_set.create(message="Invalid query field '%s'" % field)
else: # no search fields, just raw search
if protect:
query &= (Q(gramps_id__icontains=search) |
@ -1159,7 +1157,7 @@ def build_citation_query(request, search):
elif field == "public":
query &= Q(public=boolean(value))
else:
request.user.message_set.create(message="Invalid query field '%s'" % field)
request.user.message_set.create(message="Invalid query field '%s'" % field)
else: # no search fields, just raw search
if protect:
query &= (Q(gramps_id__icontains=search))
@ -1209,7 +1207,7 @@ def build_source_query(request, search):
elif field == "public":
query &= Q(public=boolean(value))
else:
request.user.message_set.create(message="Invalid query field '%s'" % field)
request.user.message_set.create(message="Invalid query field '%s'" % field)
else: # no search fields, just raw search
if protect:
query &= Q(gramps_id__icontains=search)
@ -1255,7 +1253,7 @@ def build_tag_query(request, search):
elif field == "name":
query &= Q(name__icontains=value)
else:
request.user.message_set.create(message="Invalid query field '%s'" % field)
request.user.message_set.create(message="Invalid query field '%s'" % field)
else: # no search fields, just raw search
if protect:
query &= Q(name__icontains=search)
@ -1302,7 +1300,7 @@ def build_report_query(request, search):
elif field == "name":
query &= Q(name__icontains=value)
else:
request.user.message_set.create(message="Invalid query field '%s'" % field)
request.user.message_set.create(message="Invalid query field '%s'" % field)
else: # no search fields, just raw search
if protect:
query &= Q(name__icontains=search)
@ -1358,7 +1356,7 @@ def build_event_query(request, search):
elif field == "public":
query &= Q(public=boolean(value))
else:
request.user.message_set.create(message="Invalid query field '%s'" % field)
request.user.message_set.create(message="Invalid query field '%s'" % field)
else: # no search fields, just raw search
if protect:
query &= (Q(gramps_id__icontains=search) |
@ -1393,12 +1391,12 @@ def process_reference(request, ref_by, handle, ref_to, order):
ref_to_class = dji.get_model("%sRef" % ref_to.title())
exclude = ["last_changed_by", "last_changed", "object_type", "object_id", "ref_object"]
if order == "new":
referenced_to = ref_to_class.objects.filter(object_id=referenced_by.id,
referenced_to = ref_to_class.objects.filter(object_id=referenced_by.id,
object_type=object_type,
order=0)
form = modelformset_factory(ref_to_class, exclude=exclude, extra=1)(queryset=referenced_to)
else:
referenced_to = ref_to_class.objects.filter(object_id=referenced_by.id,
referenced_to = ref_to_class.objects.filter(object_id=referenced_by.id,
object_type=object_type,
order=order)
form = modelformset_factory(ref_to_class, exclude=exclude, extra=0)(queryset=referenced_to)
@ -1410,7 +1408,7 @@ def process_reference(request, ref_by, handle, ref_to, order):
context["object"] = referenced_by
context["handle"] = referenced_by.handle
context["url"] = referenced_to[0].get_reference_to().get_url()
#"/%s/%s" % (referenced_to[0].ref_object.__class__.__name__.lower(),
#"/%s/%s" % (referenced_to[0].ref_object.__class__.__name__.lower(),
# referenced_to[0].ref_object.handle)
context["referenced_by"] = "/%s/%s" % (referenced_by.__class__.__name__.lower(),
referenced_by.handle)
@ -1451,7 +1449,7 @@ def process_child(request, handle, act, child):
elif act == "down":
if int(child) <= len(childrefs) - 1:
childrefs[int(child) - 1].order = int(child) + 1
childrefs[int(child)].order = int(child)
childrefs[int(child)].order = int(child)
childrefs[int(child) - 1].save()
childrefs[int(child)].save()
dji.rebuild_cache(family)
@ -1465,12 +1463,12 @@ def process_list_item(request, view, handle, act, item, index):
# /citation/872323636232635/down/attribute/2
index = int(index)
tab = {
"eventref": "#tab-events",
"citationref": "#tab-citations",
"repositoryref": "#tab-repositories",
"noteref": "#tab-notes",
"attribute": "#tab-attributes",
"media": "#tab-media",
"eventref": "#tab-events",
"citationref": "#tab-citations",
"repositoryref": "#tab-repositories",
"noteref": "#tab-notes",
"attribute": "#tab-attributes",
"media": "#tab-media",
"lds": "#tab-lds",
"parentfamily": "#tab-references",
"family": "#tab-references",
@ -1548,11 +1546,10 @@ def process_json_request(request):
"""
import gramps.gen.lib
from gramps.gen.proxy import PrivateProxyDb, LivingProxyDb
db = DbDjango()
if not request.user.is_authenticated():
db = PrivateProxyDb(db)
db = LivingProxyDb(db,
LivingProxyDb.MODE_INCLUDE_LAST_NAME_ONLY,
db = LivingProxyDb(db,
LivingProxyDb.MODE_INCLUDE_LAST_NAME_ONLY,
None, # current year
1) # years after death
field = request.GET.get("field", None)

View File

@ -41,9 +41,8 @@
import os, sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gramps.webapp.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gramps.webapp.default_settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)

View File

@ -20,7 +20,7 @@
#### This sets up Django so you can interact with it via the Python
#### command line.
#### Start with something like:
#### $ PYTHONPATH=..:../plugins/lib python -i shell.py
#### $ PYTHONPATH=..:../plugins/lib python -i shell.py
#### >>> Person.objects.all()
import os
@ -58,7 +58,7 @@ with open(pystartup) as f:
exec(code, globals(), locals())
from django.conf import settings
import gramps.webapp.settings as default_settings
from gramps.webapp import default_settings
try:
settings.configure(default_settings)
except RuntimeError:
@ -82,12 +82,13 @@ from gramps.cli.user import User as GUser # gramps user
from django.db.models import Q
db = DbDjango()
dji = DjangoInterface()
db.load(os.path.abspath(os.path.dirname(__file__)))
dd = displayer.display
dp = parser.parse
#import_file(db,
# "/home/dblank/gramps/trunk/example/gramps/data.gramps",
#import_file(db,
# "/home/dblank/gramps/trunk/example/gramps/data.gramps",
# GUser())
#snf = StyledNoteFormatter(db)

View File

@ -25,6 +25,7 @@
#
#------------------------------------------------------------------------
import sys
import os
import re
import datetime
from html.parser import HTMLParser
@ -74,7 +75,7 @@ _ = glocale.translation.gettext
TAB_HEIGHT = 200
util_filters = [
'nbsp',
'nbsp',
'date_as_text',
'render_name',
]
@ -83,7 +84,7 @@ util_tags = [
'render',
'media_link',
'render_name',
"get_person_from_handle",
"get_person_from_handle",
"event_table",
"history_table",
"name_table",
@ -117,10 +118,10 @@ util_tags = [
# Module Constants
#
#------------------------------------------------------------------------
dji = libdjango.DjangoInterface()
dd = displayer.display
dp = parser.parse
db = DbDjango()
db.load(os.path.abspath(os.path.dirname(__file__)))
def register_plugins(user):
dbstate = DbState()
@ -199,7 +200,7 @@ class Table(object):
"""
def __init__(self, id, style=None):
self.id = id # css id
self.db = DbDjango()
self.db = db
self.access = SimpleAccess(self.db)
self.table = SimpleTable(self.access)
self.column_widths = None
@ -210,24 +211,24 @@ class Table(object):
# None is paperstyle, which is ignored:
self.doc = Doc(HtmlDoc(
make_basic_stylesheet(
Table={"set_width":95},
Table={"set_width":95},
TableHeaderCell={"set_bottom_border": True,
"set_right_border": True,
"set_padding": .1,
},
TableDataCell={"set_bottom_border": True,
TableDataCell={"set_bottom_border": True,
"set_right_border": True,
"set_padding": .1,
},
),
),
None))
self.doc.doc._backend = HtmlBackend()
self.doc.doc.use_table_headers = True
# You can set elements id, class, etc:
self.doc.doc.htmllist += [
Html('div',
class_="content",
id=self.id,
Html('div',
class_="content",
id=self.id,
style=("overflow: auto; height:%spx; background-color: #f4f0ec;" % TAB_HEIGHT) if not style else style)]
def columns(self, *args):
@ -292,7 +293,7 @@ def make_button(text, url, *args):
if text[0] in "+$-?x" or text in ["x", "^", "v", "<", "<<", ">", ">>"]:
return mark_safe(make_image_button(text, url, kwargs, last))
else:
return mark_safe("""<input type="button" value="%s" onclick="document.location.href='%s%s%s'"/>""" %
return mark_safe("""<input type="button" value="%s" onclick="document.location.href='%s%s%s'"/>""" %
(text, url, kwargs, last))
def make_image_button(text, url, kwargs, last):
@ -335,7 +336,7 @@ def make_image_button(text, url, kwargs, last):
return make_image_button2(button, text, url, kwargs, last)
def make_image_button2(button, text, url, kwargs="", last=""):
if button == "cancel":
if button == "cancel":
filename = "/images/gtk-remove.png"
elif button == "x": # delete
filename = "/images/gtk-remove.png"
@ -374,7 +375,7 @@ def event_table(obj, user, act, url, args):
table = Table("event_table")
table.columns(
"",
_("Description"),
_("Description"),
_("Type"),
_("ID"),
_("Date"),
@ -384,7 +385,7 @@ def event_table(obj, user, act, url, args):
if user.is_authenticated() or obj.public:
obj_type = ContentType.objects.get_for_model(obj)
event_ref_list = models.EventRef.objects.filter(
object_id=obj.id,
object_id=obj.id,
object_type=obj_type).order_by("order")
event_list = [(o.ref_object, o) for o in event_ref_list]
links = []
@ -393,7 +394,7 @@ def event_table(obj, user, act, url, args):
table.row(Link("{{[[x%d]][[^%d]][[v%d]]}}" % (count, count, count)) if user.is_superuser and act == "view" else "",
djevent.description,
table.db.get_event_from_handle(djevent.handle),
djevent.gramps_id,
djevent.gramps_id,
display_date(djevent),
get_title(djevent.place),
str(event_ref.role_type))
@ -429,16 +430,16 @@ def history_table(obj, user, act):
cssid = "tab-history"
table = Table("history_table")
table.columns(
_("Action"),
_("Action"),
_("Comment"),
)
if user.is_authenticated() or obj.public:
obj_type = ContentType.objects.get_for_model(obj)
for entry in models.Log.objects.filter(
object_id=obj.id,
object_id=obj.id,
object_type=obj_type):
table.row(
"%s on %s by %s" % (entry.log_type,
"%s on %s by %s" % (entry.log_type,
entry.last_changed,
entry.last_changed_by),
entry.reason)
@ -458,7 +459,7 @@ def name_table(obj, user, act, url=None, *args):
has_data = False
cssid = "tab-names"
table = Table("name_table")
table.columns(_("Name"),
table.columns(_("Name"),
_("Type"),
_("Group As"),
_("Source"),
@ -467,14 +468,14 @@ def name_table(obj, user, act, url=None, *args):
links = []
for name in obj.name_set.all().order_by("order"):
obj_type = ContentType.objects.get_for_model(name)
citationq = dji.CitationRef.filter(object_type=obj_type,
citationq = db.dji.CitationRef.filter(object_type=obj_type,
object_id=name.id).count() > 0
note_refs = dji.NoteRef.filter(object_type=obj_type,
note_refs = db.dji.NoteRef.filter(object_type=obj_type,
object_id=name.id)
note = ""
if note_refs.count() > 0:
try:
note = dji.Note.get(id=note_refs[0].object_id).text[:50]
note = db.dji.Note.get(id=note_refs[0].object_id).text[:50]
except:
note = None
table.row(make_name(name, user),
@ -482,7 +483,7 @@ def name_table(obj, user, act, url=None, *args):
name.group_as,
["No", "Yes"][citationq],
note)
links.append(('URL',
links.append(('URL',
# url is "/person/%s/name"
(url % name.person.handle) + ("/%s" % name.order)))
has_data = True
@ -535,14 +536,14 @@ def citation_table(obj, user, act, url=None, *args):
has_data = False
cssid = "tab-sources"
table = Table("citation_table")
table.columns("",
_("ID"),
table.columns("",
_("ID"),
_("Confidence"),
_("Page"))
table.column_widths = [11, 10, 49, 30]
if user.is_authenticated() or obj.public:
obj_type = ContentType.objects.get_for_model(obj)
citation_refs = dji.CitationRef.filter(object_type=obj_type,
citation_refs = db.dji.CitationRef.filter(object_type=obj_type,
object_id=obj.id).order_by("order")
links = []
count = 1
@ -603,7 +604,7 @@ def repository_table(obj, user, act, url=None, *args):
retval += """</div>"""
if user.is_authenticated() or obj.public:
obj_type = ContentType.objects.get_for_model(obj)
refs = dji.RepositoryRef.filter(object_type=obj_type,
refs = db.dji.RepositoryRef.filter(object_type=obj_type,
object_id=obj.id)
count = 1
for repo_ref in refs:
@ -612,7 +613,7 @@ def repository_table(obj, user, act, url=None, *args):
Link("{{[[x%d]][[^%d]][[v%d]]}}" % (count, count, count)) if user.is_superuser else "",
repository.gramps_id,
repository.name,
repo_ref.call_number,
repo_ref.call_number,
str(repository.repository_type),
)
has_data = True
@ -645,7 +646,7 @@ def note_table(obj, user, act, url=None, *args):
table.column_widths = [11, 10, 20, 59]
if user.is_authenticated() or obj.public:
obj_type = ContentType.objects.get_for_model(obj)
note_refs = dji.NoteRef.filter(object_type=obj_type,
note_refs = db.dji.NoteRef.filter(object_type=obj_type,
object_id=obj.id).order_by("order")
links = []
count = 1
@ -690,7 +691,7 @@ def data_table(obj, user, act, url=None, *args):
table = Table("data_table")
table.columns(
"",
_("Type"),
_("Type"),
_("Value"),
)
table.column_widths = [11, 39, 50]
@ -739,12 +740,12 @@ def attribute_table(obj, user, act, url=None, *args):
has_data = False
cssid = "tab-attributes"
table = Table("attribute_table")
table.columns(_("Type"),
table.columns(_("Type"),
_("Value"),
)
if user.is_authenticated() or obj.public:
obj_type = ContentType.objects.get_for_model(obj)
attributes = dji.Attribute.filter(object_type=obj_type,
attributes = db.dji.Attribute.filter(object_type=obj_type,
object_id=obj.id)
for attribute in attributes:
table.row(attribute.attribute_type.name,
@ -766,7 +767,7 @@ def address_table(obj, user, act, url=None, *args):
has_data = False
cssid = "tab-addresses"
table = Table("address_table")
table.columns(_("Date"),
table.columns(_("Date"),
_("Address"),
_("City"),
_("State"),
@ -797,13 +798,13 @@ def media_table(obj, user, act, url=None, *args):
has_data = False
cssid = "tab-media"
table = Table("media_table")
table.columns(_("Description"),
table.columns(_("Description"),
_("Type"),
_("Path/Filename"),
)
if user.is_authenticated() or obj.public:
obj_type = ContentType.objects.get_for_model(obj)
media_refs = dji.MediaRef.filter(object_type=obj_type,
media_refs = db.dji.MediaRef.filter(object_type=obj_type,
object_id=obj.id)
for media_ref in media_refs:
media = table.db.get_object_from_handle(
@ -833,7 +834,7 @@ def internet_table(obj, user, act, url=None, *args):
_("Path"),
_("Description"))
if user.is_authenticated() or obj.public:
urls = dji.Url.filter(person=obj)
urls = db.dji.Url.filter(person=obj)
for url_obj in urls:
table.row(str(url_obj.url_type),
url_obj.path,
@ -855,7 +856,7 @@ def association_table(obj, user, act, url=None, *args):
has_data = False
cssid = "tab-associations"
table = Table("association_table")
table.columns(_("Name"),
table.columns(_("Name"),
_("ID"),
_("Association"))
retval += """<div style="background-color: lightgray; padding: 2px 0px 0px 2px">"""
@ -872,11 +873,11 @@ def association_table(obj, user, act, url=None, *args):
associations = person.get_person_ref_list()
for association in associations: # PersonRef
table.row(Link("{{[[x%d]][[^%d]][[v%d]]}}" % (count, count, count)) if user.is_superuser and url and act == "view" else "",
association.ref_object.get_primary_name(),
association.ref_object.gramps_id,
association.description,
association.ref_object.get_primary_name(),
association.ref_object.gramps_id,
association.description,
)
links.append(('URL', "/person/%s/association/%d" % (obj.handle, count)))
links.append(('URL', "/person/%s/association/%d" % (obj.handle, count)))
has_data = True
count += 1
table.links(links)
@ -893,17 +894,17 @@ def association_table(obj, user, act, url=None, *args):
retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
return retval
def location_table(obj, user, act, url=None, *args):
def location_table(obj, user, act, url=None, *args):
# obj is Place or Address
retval = ""
has_data = False
cssid = "tab-alternatelocations"
table = Table("location_table")
table.columns(_("Street"),
_("Locality"),
_("City"),
_("State"),
_("Country"))
has_data = False
cssid = "tab-alternatelocations"
table = Table("location_table")
table.columns(_("Street"),
_("Locality"),
_("City"),
_("State"),
_("Country"))
if user.is_authenticated() or obj.public:
# FIXME: location confusion!
# The single Location on the Location Tab is here too?
@ -918,22 +919,22 @@ def location_table(obj, user, act, url=None, *args):
location.country)
has_data = True
retval += """<div style="background-color: lightgray; padding: 2px 0px 0px 2px">"""
if user.is_superuser and url and act == "view":
retval += make_button(_("+Add Address"), (url % args))
else:
retval += nbsp("") # to keep tabs same height
if user.is_superuser and url and act == "view":
retval += make_button(_("+Add Address"), (url % args))
else:
retval += nbsp("") # to keep tabs same height
retval += """</div>"""
retval += table.get_html()
if has_data:
retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
return retval
retval += table.get_html()
if has_data:
retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
return retval
def lds_table(obj, user, act, url=None, *args):
retval = ""
has_data = False
cssid = "tab-lds"
table = Table("lds_table")
table.columns(_("Type"),
table.columns(_("Type"),
_("Date"),
_("Status"),
_("Temple"),
@ -969,14 +970,14 @@ def person_reference_table(obj, user, act):
table1.columns(
"As Spouse",
_("ID"),
_("Reference"),
_("Reference"),
)
table1.column_widths = [11, 10, 79]
table2 = Table("person_reference_table", style="background-color: #f4f0ec;")
table2.columns(
"As Child",
_("ID"),
_("Reference"),
_("Reference"),
)
table2.column_widths = [11, 10, 79]
if (user.is_authenticated() or obj.public) and act != "add":
@ -1023,25 +1024,25 @@ def person_reference_table(obj, user, act):
count += 1
retval += """<div style="background-color: lightgray; padding: 2px 0px 0px 2px">"""
retval += make_image_button2("add spouse to new family",
_("Add as Spouse to New Family"),
retval += make_image_button2("add spouse to new family",
_("Add as Spouse to New Family"),
"/family/add/spouse/%s" % obj.handle)
retval += make_image_button2("add spouse to existing family",
_("Add as Spouse to Existing Family"),
retval += make_image_button2("add spouse to existing family",
_("Add as Spouse to Existing Family"),
"/family/share/spouse/%s" % obj.handle)
retval += "&nbsp;"
retval += make_image_button2("add child to new family",
_("Add as Child to New Family"),
retval += make_image_button2("add child to new family",
_("Add as Child to New Family"),
"/family/add/child/%s" % obj.handle)
retval += make_image_button2("add child to existing family",
_("Add as Child to Existing Family"),
retval += make_image_button2("add child to existing family",
_("Add as Child to Existing Family"),
"/family/share/child/%s" % obj.handle)
retval += """</div>"""
retval += """<div style="overflow: auto; height:%spx;">""" % TAB_HEIGHT
retval += text1 + text2 + "</div>"
if has_data:
retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
return retval
return retval
def note_reference_table(obj, user, act):
retval = ""
@ -1050,7 +1051,7 @@ def note_reference_table(obj, user, act):
table = Table("note_reference_table")
table.columns(
_("Type"),
_("Reference"),
_("Reference"),
_("ID"))
if (user.is_authenticated() or obj.public) and act != "add":
for reference in models.NoteRef.objects.filter(ref_object=obj):
@ -1065,7 +1066,7 @@ def note_reference_table(obj, user, act):
retval += nbsp("") # to keep tabs same height
if has_data:
retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
return retval
return retval
def event_reference_table(obj, user, act):
retval = ""
@ -1074,7 +1075,7 @@ def event_reference_table(obj, user, act):
table = Table("event_reference_table")
table.columns(
_("Type"),
_("Reference"),
_("Reference"),
_("ID"))
if (user.is_authenticated() or obj.public) and act != "add":
for reference in models.EventRef.objects.filter(ref_object=obj):
@ -1093,7 +1094,7 @@ def event_reference_table(obj, user, act):
retval += nbsp("") # to keep tabs same height
if has_data:
retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
return retval
return retval
def repository_reference_table(obj, user, act):
retval = ""
@ -1102,7 +1103,7 @@ def repository_reference_table(obj, user, act):
table = Table("repository_reference_table")
table.columns(
_("Type"),
_("Reference"),
_("Reference"),
_("ID"))
if (user.is_authenticated() or obj.public) and act != "add":
for reference in models.RepositoryRef.objects.filter(ref_object=obj):
@ -1117,7 +1118,7 @@ def repository_reference_table(obj, user, act):
retval += nbsp("") # to keep tabs same height
if has_data:
retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
return retval
return retval
def citation_reference_table(obj, user, act):
retval = ""
@ -1126,7 +1127,7 @@ def citation_reference_table(obj, user, act):
table = Table("citation_reference_table")
table.columns(
_("Type"),
_("Reference"),
_("Reference"),
# _("ID")
)
if (user.is_authenticated() or obj.public) and act != "add":
@ -1141,7 +1142,7 @@ def citation_reference_table(obj, user, act):
retval += nbsp("") # to keep tabs same height
if has_data:
retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
return retval
return retval
def source_reference_table(obj, user, act):
retval = ""
@ -1150,7 +1151,7 @@ def source_reference_table(obj, user, act):
table = Table("source_reference_table")
table.columns(
_("Type"),
_("Reference"),
_("Reference"),
_("ID"))
if (user.is_authenticated() or obj.public) and act != "add":
for item in obj.citation_set.all():
@ -1163,7 +1164,7 @@ def source_reference_table(obj, user, act):
retval += nbsp("") # to keep tabs same height
if has_data:
retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
return retval
return retval
def media_reference_table(obj, user, act):
retval = ""
@ -1172,7 +1173,7 @@ def media_reference_table(obj, user, act):
table = Table("media_reference_table")
table.columns(
_("Type"),
_("Reference"),
_("Reference"),
_("ID"))
if (user.is_authenticated() or obj.public) and act != "add":
for reference in models.MediaRef.objects.filter(ref_object=obj):
@ -1187,7 +1188,7 @@ def media_reference_table(obj, user, act):
retval += nbsp("") # to keep tabs same height
if has_data:
retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
return retval
return retval
def place_reference_table(obj, user, act):
retval = ""
@ -1210,7 +1211,7 @@ def place_reference_table(obj, user, act):
retval += nbsp("") # to keep tabs same height
if has_data:
retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
return retval
return retval
def tag_reference_table(obj, user, act):
retval = ""
@ -1219,7 +1220,7 @@ def tag_reference_table(obj, user, act):
table = Table("tag_reference_table")
table.columns(
_("Type"),
_("Reference"),
_("Reference"),
_("ID"))
if (user.is_authenticated() or obj.public) and act != "add":
querysets = [obj.person_set, obj.family_set, obj.note_set, obj.media_set]
@ -1234,7 +1235,7 @@ def tag_reference_table(obj, user, act):
retval += nbsp("") # to keep tabs same height
if has_data:
retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
return retval
return retval
class Link(object):
def __init__(self, string, url=None):
@ -1260,11 +1261,11 @@ def children_table(obj, user, act, url=None, *args):
_("Maternal"),
_("Birth Date"),
)
table.column_widths = [11, 5, 10, 29, 8, 8, 10, 19]
table.column_widths = [11, 5, 10, 29, 8, 8, 10, 19]
family = obj
obj_type = ContentType.objects.get_for_model(family)
childrefs = dji.ChildRef.filter(object_id=family.id,
childrefs = db.dji.ChildRef.filter(object_id=family.id,
object_type=obj_type).order_by("order")
links = []
count = 1
@ -1272,7 +1273,7 @@ def children_table(obj, user, act, url=None, *args):
child = childref.ref_object
if user.is_authenticated() or obj.public:
table.row(Link("{{[[x%d]][[^%d]][[v%d]]}}" % (count, count, count)) if user.is_superuser and url and act == "view" else "",
str(count),
str(count),
"[%s]" % child.gramps_id,
render_name(child, user),
child.gender_type,
@ -1285,7 +1286,7 @@ def children_table(obj, user, act, url=None, *args):
count += 1
else:
table.row("",
str(count),
str(count),
"[%s]" % child.gramps_id,
render_name(child, user) if not child.private else "[Private]",
child.gender_type if not child.private else "[Private]",
@ -1331,7 +1332,7 @@ def get_title(place):
return ""
def display_date(obj):
date_tuple = dji.get_date(obj)
date_tuple = db.dji.get_date(obj)
if date_tuple:
gdate = GDate()
gdate.unserialize(date_tuple)
@ -1341,7 +1342,7 @@ def display_date(obj):
def media_link(handle, user, act):
retval = """<a href="%s"><img src="%s" /></a>""" % (
"/media/%s/full" % handle,
"/media/%s/full" % handle,
"/media/%s/thumbnail" % handle)
return retval
@ -1375,7 +1376,7 @@ def render(formfield, user, act, id=None, url=None, *args):
except:
# name, "prefix"
try:
retval = str(formfield.form.data[fieldname])
retval = str(formfield.form.data[fieldname])
except:
retval = "[None]"
else: # show as widget
@ -1409,7 +1410,7 @@ def render_name(name, user, act=None):
surname = name.model.surname_set.get(primary=True)
except:
surname = "[No primary surname]"
return "%s, %s" % (surname,
return "%s, %s" % (surname,
name.model.first_name)
elif isinstance(name, Person): # name is a Person
person = name
@ -1446,7 +1447,7 @@ def date_as_text(obj, user):
"""
if user.is_authenticated() or (obj and obj.public):
if obj:
date_tuple = dji.get_date(obj)
date_tuple = db.dji.get_date(obj)
if date_tuple:
gdate = GDate().unserialize(date_tuple)
return dd(gdate)
@ -1455,7 +1456,7 @@ def date_as_text(obj, user):
return ""
def person_get_event(person, event_type=None):
event_ref_list = dji.get_event_ref_list(person)
event_ref_list = db.dji.get_event_ref_list(person)
if event_type:
index = libdjango.lookup_role_index(event_type, event_ref_list)
if index >= 0:
@ -1470,8 +1471,8 @@ def person_get_event(person, event_type=None):
else:
return ""
else:
retval = [[obj.ref_object for obj in
models.EventRef.objects.filter(ref_object__handle=event_handle[3])]
retval = [[obj.ref_object for obj in
models.EventRef.objects.filter(ref_object__handle=event_handle[3])]
for event_handle in event_ref_list]
return [j for i in retval for j in i]
@ -1485,7 +1486,7 @@ def update_last_changed(obj, user):
register_plugins(GUser())
# works after registering plugins:
from gramps.plugins.docgen.htmldoc import HtmlDoc
from gramps.plugins.docgen.htmldoc import HtmlDoc
from gramps.plugins.lib.libhtmlbackend import HtmlBackend, DocBackend, process_spaces
from gramps.plugins.lib.libhtml import Html
@ -1537,10 +1538,10 @@ class StyledNoteFormatter(object):
if obj:
handle = obj.handle
else:
raise AttributeError("gramps_id '%s' not found in '%s'" %
raise AttributeError("gramps_id '%s' not found in '%s'" %
(handle, obj_class))
else:
raise AttributeError("invalid gramps_id lookup " +
raise AttributeError("invalid gramps_id lookup " +
"in table name '%s'" % obj_class)
# handle, ppl
return "/%s/%s" % (obj_class.lower(), handle)
@ -1696,7 +1697,7 @@ def make_log(obj, log_type, last_changed_by, reason, cache):
last_changed_by=last_changed_by,
cache=cache)
log.save()
def person_get_birth_date(person):
#db = DbDjango()
#event = get_birth_or_fallback(db, db.get_person_from_handle(person.handle))
@ -1710,4 +1711,3 @@ def person_get_death_date(person):
#if event:
# return event.date
return None