diff --git a/src/data/templates/view_family_detail.html b/src/data/templates/view_family_detail.html index 6777012dc..1752d8f2c 100644 --- a/src/data/templates/view_family_detail.html +++ b/src/data/templates/view_family_detail.html @@ -83,25 +83,25 @@
- {{ family|family_children_table:user|safe }} + {% children_table family user action "/family/%s/children" family.handle %}
- {{ family|family_event_table:user|safe }} + {% event_table family user action "/family/%s/children" family.handle %}
- {{ family|source_table:user|safe }} + {% source_table family user action "/family/%s/children" family.handle %}
- {{ family|family_attribute_table:user|safe }} + {% attribute_table family user action "/family/%s/children" family.handle %}
- {{ family|family_note_table:user|safe }} + {% note_table family user action "/family/%s/children" family.handle %}
- {{ family|family_lds_table:user|safe }} + {% lds_table family user action "/family/%s/children" family.handle %}
{% endblock %} diff --git a/src/data/templates/view_name_detail.html b/src/data/templates/view_name_detail.html index 4d6707c7f..cd44f2d72 100644 --- a/src/data/templates/view_name_detail.html +++ b/src/data/templates/view_name_detail.html @@ -11,7 +11,7 @@
-

Name for Person [{{person.gramps_id}}]

+

{{person|make_name:user}} [{{person.gramps_id}}]

{% comment %} 4 cols {% endcomment %} @@ -69,26 +69,32 @@
  • Notes
  • -
    -
    - +
    +
    +
    {{form.group_as.label}}:
    + - + - + - +
    {{form.group_as.label}}: {{form.group_as|render:action}}
    {{form.sort_as.label}}:
    {{form.sort_as.label}}: {{form.sort_as|render:action}}
    {{form.display_as.label}}:
    {{form.display_as.label}}: {{form.display_as|render:action}}
    {{form.text.label}}:
    {{form.text.label}}: {{form.text|render:action}}
    +
    +  
    - {% source_table form.model user action "/person/%s/name/%s/source/add" person.handle form.model.order %} + {% source_table form.model user action "/person/%s/name/%s/source" person.handle form.model.order %}
    -
    +
    + {% note_table form.model user action "/person/%s/name/%s/note" person.handle form.model.order %}
    diff --git a/src/data/templates/view_people.html b/src/data/templates/view_people.html index a3b4333ad..5da19a178 100644 --- a/src/data/templates/view_people.html +++ b/src/data/templates/view_people.html @@ -24,7 +24,7 @@ {% if person %} {{ forloop.counter|row_count:page }} - {{person|make_name}} + {{person|make_name:user}} [{{person.gramps_id}}] {{person.gender_type}} diff --git a/src/data/templates/view_person_detail.html b/src/data/templates/view_person_detail.html index 95fcdec7a..b2d7852de 100644 --- a/src/data/templates/view_person_detail.html +++ b/src/data/templates/view_person_detail.html @@ -11,49 +11,61 @@
    -

    +

    {{nameform|make_name:user}} [{{person.gramps_id}}]

    {% comment %} 5 cols {% endcomment %} +{% if user.is_authenticated %} + {% ifequal action "edit" %} + {% for error in personform.errors %} + {{error}}
    + {% endfor %} + {% for error in nameform.errors %} + {{error}}
    + {% endfor %} + + {% endifequal %} +{% endif %} + - - - - + + + + - - + + - - - - + + + + - - - - + + + + - - + + - - - - + + + + - - + + @@ -80,40 +92,54 @@
    - {{ person|person_event_table:user|safe }} + {% event_table person user action "/person/%s/event" person.handle %}
    - {{ person|person_name_table:user|safe }} + {% name_table person user action "/person/%s/name" person.handle %}
    - {% source_table person user action "/person/%s/source/add" person.handle %} + {% source_table person user action "/person/%s/source" person.handle %}
    - {{ person|person_attribute_table:user|safe }} + {% attribute_table person user action "/person/%s/attribute" person.handle %}
    - {{ person|person_address_table:user|safe }} + {% address_table person user action "/person/%s/address" person.handle %}
    -
    - {{ person|person_note_table:user|safe }} +
    + {% note_table person user action "/person/%s/note" person.handle %}
    - {{ person|person_internet_table:user|safe }} + {% internet_table person user action "/person/%s/internet" person.handle %}
    - {{ person|person_association_table:user|safe }} + {% association_table person user action "/person/%s/association" person.handle %}
    - {{ person|person_lds_table:user|safe }} + {% lds_table person user action "/person/%s/lds" person.handle %}
    - {{ person|person_reference_table:user|safe }} + {% reference_table person user action "/person/%s/reference" person.handle %}
    +{% if user.is_authenticated %} + {% ifequal action "edit" %} + {% make_button "Back to Person" "/person/%s" person.handle %} + + + + {% else %} +{% make_button "Back to People" "/person/" %} +{% make_button "Edit Person" "/person/%s/edit" person.handle %} +{% make_button "Delete Person" "/person/%s/delete" person.handle %} + {% endifequal %} +{% else %} +{% endif %} {% endblock %} diff --git a/src/web/djangodb.py b/src/web/djangodb.py index 0cc540e11..9171f8e7e 100644 --- a/src/web/djangodb.py +++ b/src/web/djangodb.py @@ -92,9 +92,17 @@ class DjangoDb(DbReadBase, DbWriteBase): return obj def get_place_from_handle(self, handle): - obj = gen.lib.Place() - obj.unserialize(self.dji.get_place(self.dji.Place.get(handle=handle))) - return obj + try: + dji_obj = self.dji.Place.get(handle=handle) + except: + dji_obj = None + if dji_obj: + tuple_obj = self.dji.get_place(dji_obj) + if tuple_obj: + obj = gen.lib.Place() + obj.unserialize(tuple_obj) + return obj + return None def get_source_from_handle(self, handle): obj = gen.lib.Source() diff --git a/src/web/grampsdb/fixtures/initial_data.json b/src/web/grampsdb/fixtures/initial_data.json index 15bad817f..ced879d91 100644 --- a/src/web/grampsdb/fixtures/initial_data.json +++ b/src/web/grampsdb/fixtures/initial_data.json @@ -18,7 +18,7 @@ "setting" : "db_created" , "description" : "database creation date/time" , "value_type" : "str" , - "value" : "2009-12-26 00:38" + "value" : "2009-12-26 08:01" } }, { diff --git a/src/web/grampsdb/forms.py b/src/web/grampsdb/forms.py index 218fbfeb4..ee0f35f9e 100644 --- a/src/web/grampsdb/forms.py +++ b/src/web/grampsdb/forms.py @@ -10,7 +10,6 @@ import datetime class PersonForm(forms.ModelForm): class Meta: model = Person - exclude = ('handle',) '''def clean(self): cleaned_data['last_changed'] = datetime.datetime.now() diff --git a/src/web/grampsdb/templatetags/my_tags.py b/src/web/grampsdb/templatetags/my_tags.py index 59be2150d..bf78eec1f 100644 --- a/src/web/grampsdb/templatetags/my_tags.py +++ b/src/web/grampsdb/templatetags/my_tags.py @@ -8,16 +8,6 @@ import web.utils register = Library() -for filter_name in util_filters: - func = getattr(web.utils, filter_name) - func.is_safe = True - register.filter(filter_name, func) - -def get_person_from_handle(db, handle): - # db is a Gramps Db interface - # handle is a Person Handle - return db.get_person_from_handle(handle) - class TemplateNode(template.Node): def __init__(self, args, var_name, func): self.args = map(template.Variable, args) @@ -33,8 +23,7 @@ class TemplateNode(template.Node): return value def parse_tokens(tokens): - # Splitting by None splits by spaces - items = tokens.contents.split(None) + items = tokens.split_contents() # {% tag_name arg1 arg2 arg3 as variable %} # {% tag_name arg1 arg2 arg3 %} tag_name = items[0] @@ -52,11 +41,14 @@ def make_tag(func): return TemplateNode(args, var_name, func) return do_func -register.tag("get_person_from_handle", - make_tag(get_person_from_handle)) +for filter_name in util_filters: + func = getattr(web.utils, filter_name) + func.is_safe = True + register.filter(filter_name, func) -register.tag("source_table", - make_tag(source_table)) +for tag_name in util_tags: + func = getattr(web.utils, tag_name) + register.tag(tag_name, make_tag(func)) probably_alive.is_safe = True register.filter('probably_alive', probably_alive) diff --git a/src/web/grampsdb/views.py b/src/web/grampsdb/views.py index ace8936a8..71003354e 100644 --- a/src/web/grampsdb/views.py +++ b/src/web/grampsdb/views.py @@ -41,11 +41,11 @@ from django.db.models import Q #------------------------------------------------------------------------ import web from web.grampsdb.models import * -from web.grampsdb.forms import NameForm +from web.grampsdb.forms import NameForm, PersonForm from web.utils import probably_alive from web.djangodb import DjangoDb -from gen.proxy import LivingProxyDb +import gen.proxy _ = lambda text: text @@ -207,8 +207,9 @@ class PrivateProxy(object): def __getattr__(self, attr): return getattr(self.obj, attr) -def view_detail(request, view, handle): +def view_detail(request, view, handle, action="view"): context = RequestContext(request) + context["action"] = action context["view"] = view if view == "event": try: @@ -239,24 +240,7 @@ def view_detail(request, view, handle): view_template = 'view_note_detail.html' context["tview"] = _("Note") elif view == "person": - try: - obj = Person.objects.get(handle=handle) - except: - raise Http404(_("Requested %s does not exist.") % view) - view_template = 'view_person_detail.html' - person = obj - name = person.get_primary_name() - if request.user.is_authenticated(): - pass # see everything, no limits - elif probably_alive(person.handle): - name.first_name = "[Living]" - elif person.private: - name = Name() - name.surname = "[Private]" - name.first_name = "[Private]" - # FIXME: protect everything else; what if name.private? - context["name"] = name - context["tview"] = _("Person") + return view_person_detail(request, view, handle, action) elif view == "place": try: obj = Place.objects.get(handle=handle) @@ -281,19 +265,56 @@ def view_detail(request, view, handle): else: raise Http404(_("Requested page type not known")) context[view] = obj - context["action"] = "view" + return render_to_response(view_template, context) + +def get_gramps_db(request): + dbase = DjangoDb() + if request.user.is_authenticated(): + private_filter=False + living_filter=False + else: + private_filter=True + living_filter=True + # If the private flag is set, apply the PrivateProxyDb + if private_filter: + dbase = gen.proxy.PrivateProxyDb(dbase) + # If the restrict flag is set, apply the LivingProxyDb + if living_filter: + dbase = gen.proxy.LivingProxyDb( + dbase, + gen.proxy.LivingProxyDb.MODE_INCLUDE_LAST_NAME_ONLY) + return dbase + +def view_person_detail(request, view, handle, action="view"): + context = RequestContext(request) + context["action"] = action + context["view"] = view + context["tview"] = _("Person") + view_template = 'view_person_detail.html' + if request.user.is_authenticated(): + person = Person.objects.get(handle=handle) + name = person.name_set.get(preferred=True) + else: + db = get_gramps_db(request) + gramps_person = db.get_person_from_handle(handle) + if not gramps_person: + raise Http404(_("Requested %s is not accessible.") % view) + person = Person.objects.get(handle=handle) + name = person.name_set.get(preferred=True) + # fill forms with data from db + name.surname = gramps_person.get_primary_name().get_surname() + name.first_name = gramps_person.get_primary_name().get_first_name() + pf = PersonForm(instance=person) + pf.model = person + nf = NameForm(instance=name) + nf.model = name + context["personform"] = pf + context["nameform"] = nf + context["person"] = person return render_to_response(view_template, context) def view(request, view): - db_direct = DjangoDb() - if not request.user.is_authenticated(): - #MODE_EXCLUDE_ALL = 0 - #MODE_INCLUDE_LAST_NAME_ONLY = 1 - #MODE_INCLUDE_FULL_NAME_ONLY = 2 - db = LivingProxyDb(db_direct, - LivingProxyDb.MODE_INCLUDE_LAST_NAME_ONLY) - else: - db = db_direct + db = get_gramps_db(request) search = "" if view == "event": if request.user.is_authenticated(): @@ -315,9 +336,9 @@ def view(request, view): view_template = 'view_events.html' total = Event.objects.all().count() elif view == "family": - if request.GET.has_key("search"): - search = request.GET.get("search") - if request.user.is_authenticated(): + if request.user.is_authenticated(): + if request.GET.has_key("search"): + search = request.GET.get("search") if "," in search: surname, first = [term.strip() for term in search.split(",", 1)] @@ -338,8 +359,12 @@ def view(request, view): Q(mother__name__first_name__istartswith=search) ) \ .order_by("gramps_id") - else: - # NON-AUTHENTICATED users + else: # no search + object_list = Family.objects.all().order_by("gramps_id") + else: + # NON-AUTHENTICATED users + if request.GET.has_key("search"): + search = request.GET.get("search") if "," in search: search, trash = [term.strip() for term in search.split(",", 1)] object_list = Family.objects \ @@ -347,15 +372,18 @@ def view(request, view): Q(family_rel_type__name__icontains=search) | Q(father__name__surname__istartswith=search) | Q(mother__name__surname__istartswith=search)) & - Q(private=False) + Q(private=False) & + Q(mother__private=False) & + Q(father__private=False) ) \ .order_by("gramps_id") - else: # no search - if request.user.is_authenticated(): - object_list = Family.objects.all().order_by("gramps_id") else: - # NON-AUTHENTICATED users - object_list = Family.objects.filter(private=False).order_by("gramps_id") + object_list = Family.objects \ + .filter(Q(private=False) & + Q(mother__private=False) & + Q(father__private=False) + ) \ + .order_by("gramps_id") view_template = 'view_families.html' total = Family.objects.all().count() elif view == "media": @@ -395,9 +423,9 @@ def view(request, view): view_template = 'view_notes.html' total = Note.objects.all().count() elif view == "person": - if request.GET.has_key("search"): - search = request.GET.get("search") - if request.user.is_authenticated(): + if request.user.is_authenticated(): + if request.GET.has_key("search"): + search = request.GET.get("search") if "," in search: surname, first_name = [term.strip() for term in search.split(",", 1)] @@ -417,7 +445,11 @@ def view(request, view): ) \ .order_by("surname", "first_name") else: - # BEGIN NON-AUTHENTICATED users + object_list = Name.objects.all().order_by("surname", "first_name") + else: + # BEGIN NON-AUTHENTICATED users + if request.GET.has_key("search"): + search = request.GET.get("search") if "," in search: search, trash = [term.strip() for term in search.split(",", 1)] object_list = Name.objects \ @@ -426,15 +458,12 @@ def view(request, view): Q(person__private=False) ) \ .order_by("surname", "first_name") - # END NON-AUTHENTICATED users - else: - if request.user.is_authenticated(): - object_list = Name.objects.all().order_by("surname", "first_name") else: - # BEGIN NON-AUTHENTICATED users - object_list = Name.objects.filter(Q(private=False) & - Q(person__private=False)).order_by("surname", "first_name") - # END NON-AUTHENTICATED users + object_list = Name.objects \ + .filter(Q(private=False) & + Q(person__private=False)) \ + .order_by("surname", "first_name") + # END NON-AUTHENTICATED users view_template = 'view_people.html' total = Name.objects.all().count() elif view == "place": diff --git a/src/web/urls.py b/src/web/urls.py index 06e65701f..9e38cd25d 100644 --- a/src/web/urls.py +++ b/src/web/urls.py @@ -67,6 +67,8 @@ urlpatterns += patterns('', (r'^(?P(\w+))/$', view), url(r'^person/(?P(\w+))/$', view_detail, {"view": "person"}, name="view-person-detail"), + url(r'^person/(?P(\w+))/(?P(\w+))$', view_detail, + {"view": "person"}, name="view-person-detail"), (r'^(?P(\w+))/(?P(\w+))/$', view_detail), (r'^person/(?P(\w+))/name/(?P(\w+))$', view_name_detail), (r'^person/(?P(\w+))/name/(?P(\w+))/(?P(\w+))$', view_name_detail), diff --git a/src/web/utils.py b/src/web/utils.py index 75eea13ad..b42213d57 100644 --- a/src/web/utils.py +++ b/src/web/utils.py @@ -62,17 +62,28 @@ from gen.utils import get_birth_or_fallback, get_death_or_fallback from gen.plug import BasePluginManager from cli.grampscli import CLIManager -util_filters = ['person_event_table', 'person_name_table', - 'person_attribute_table', - 'person_address_table', 'person_note_table', - 'person_gallery_table', 'person_internet_table', - 'person_association_table', 'person_lds_table', - 'person_reference_table', - 'family_children_table', 'family_event_table', - 'family_attribute_table', - 'family_note_table', 'family_gallery_table', - 'family_lds_table', - 'nbsp', 'render'] +util_filters = [ + 'nbsp', + 'render', + ] + +util_tags = [ + "get_person_from_handle", + "event_table", + "name_table", + "source_table", + "note_table", + "attribute_table", + "address_table", + "gallery_table", + "internet_table", + "association_table", + "lds_table", + "reference_table", + "children_table", + "make_button", + ] + #------------------------------------------------------------------------ # # Module Constants @@ -89,6 +100,14 @@ def register_plugins(): pmgr = BasePluginManager.get_instance() return pmgr +def get_person_from_handle(db, handle): + # db is a Gramps Db interface + # handle is a Person Handle + try: + return db.get_person_from_handle(handle) + except: + return None + def probably_alive(handle): db = DjangoDb() person = db.get_person_from_handle(handle) @@ -160,10 +179,11 @@ def render(formfield, action): retval = formfield.as_widget() return retval -def make_button(text, url): - return """[%s]""" % (url, text) +def make_button(text, url, *args): + url = url % args + return """[ %s ] """ % (url, text) -def person_event_table(djperson, user): +def event_table(obj, user, action, url=None, *args): retval = "" table = Table() table.columns(_("Description"), @@ -173,9 +193,9 @@ def person_event_table(djperson, user): _("Place"), _("Role")) if user.is_authenticated(): - obj_type = ContentType.objects.get_for_model(djperson) + obj_type = ContentType.objects.get_for_model(obj) event_ref_list = models.EventRef.objects.filter( - object_id=djperson.id, + object_id=obj.id, object_type=obj_type).order_by("order") event_list = [(obj.ref_object, obj) for obj in event_ref_list] for (djevent, event_ref) in event_list: @@ -187,12 +207,13 @@ def person_event_table(djperson, user): get_title(djevent.place), str(event_ref.role_type)) retval += table.get_html() - if user.is_authenticated(): - retval += make_button(_("Add event"), "/person/%s/event/add" % djperson.handle) + if user.is_authenticated() and url and action != "edit": + retval += make_button(_("Add event"), (url + "/add") % args) + else: + retval += nbsp("") # to keep tabs same height return retval -def person_name_table(djperson, user): - print "person_name_table", djperson, user +def name_table(obj, user, action, url=None, *args): retval = "" table = Table() table.columns(_("Name"), @@ -202,7 +223,7 @@ def person_name_table(djperson, user): _("Note Preview")) if user.is_authenticated(): links = [] - for name in djperson.name_set.all().order_by("order"): + for name in obj.name_set.all().order_by("order"): obj_type = ContentType.objects.get_for_model(name) sourceq = dji.SourceRef.filter(object_type=obj_type, object_id=name.id).count() > 0 @@ -219,12 +240,15 @@ def person_name_table(djperson, user): name.group_as, ["No", "Yes"][sourceq], note) - links.append(('URL', "/person/%s/name/%s" % - (name.person.handle, name.order))) + links.append(('URL', + # url is "/person/%s/name" + (url % name.person.handle) + ("/%s" % name.order))) table.links(links) retval += table.get_html() - if user.is_authenticated(): - retval += make_button(_("Add name"), "/person/%s/name/add" % djperson.handle) + if user.is_authenticated() and url and action != "edit": + retval += make_button(_("Add name"), (url + "/add") % args) + else: + retval += nbsp("") # to keep tabs same height return retval def source_table(obj, user, action, url=None, *args): @@ -247,28 +271,56 @@ def source_table(obj, user, action, url=None, *args): ) retval += table.get_html() if user.is_authenticated() and url and action != "edit": - retval += make_button(_("Add source"), url % args) + retval += make_button(_("Add source"), (url + "/add") % args) + else: + retval += nbsp("") # to keep tabs same height return retval -def person_attribute_table(djperson, user): +def note_table(obj, user, action, url=None, *args): + retval = "" + table = Table() + table.columns( + _("ID"), + _("Type"), + _("Note")) + if user.is_authenticated(): + obj_type = ContentType.objects.get_for_model(obj) + note_refs = dji.NoteRef.filter(object_type=obj_type, + object_id=obj.id) + for note_ref in note_refs: + note = table.db.get_note_from_handle( + note_ref.ref_object.handle) + table.row(table.db.get_note_from_handle(note.handle), + str(note_ref.ref_object.note_type), + note_ref.ref_object.text[:50]) + retval += table.get_html() + if user.is_authenticated() and url and action != "edit": + retval += make_button(_("Add note"), (url + "/add") % args) + else: + retval += nbsp("") # to keep tabs same height + return retval + +def attribute_table(obj, user, action, url=None, *args): retval = "" table = Table() table.columns(_("Type"), _("Value"), ) if user.is_authenticated(): - obj_type = ContentType.objects.get_for_model(djperson) + obj_type = ContentType.objects.get_for_model(obj) attributes = dji.Attribute.filter(object_type=obj_type, - object_id=djperson.id) + object_id=obj.id) for attribute in attributes: table.row(attribute.attribute_type.name, attribute.value) retval += table.get_html() - if user.is_authenticated(): - retval += make_button(_("Add attribute"), "/person/%s/attribute/add" % djperson.handle) + if user.is_authenticated() and url and action != "edit": + retval += make_button(_("Add attribute"), (url + "/add") % args) + else: + retval += nbsp("") # to keep tabs same height return retval -def person_address_table(djperson, user): +def address_table(obj, user, action, url=None, *args): retval = "" table = Table() table.columns(_("Date"), @@ -277,7 +329,7 @@ def person_address_table(djperson, user): _("State"), _("Country")) if user.is_authenticated(): - for address in djperson.address_set.all().order_by("order"): + for address in obj.address_set.all().order_by("order"): locations = address.location_set.all().order_by("order") for location in locations: table.row(display_date(address), @@ -286,77 +338,63 @@ def person_address_table(djperson, user): location.state, location.country) retval += table.get_html() - if user.is_authenticated(): - retval += make_button(_("Add address"), "/person/%s/address/add" % djperson.handle) + if user.is_authenticated() and url and action != "edit": + retval += make_button(_("Add address"), (url + "/add") % args) + else: + retval += nbsp("") # to keep tabs same height return retval -def person_note_table(djperson, user): - retval = "" - table = Table() - table.columns( - _("ID"), - _("Type"), - _("Note")) - if user.is_authenticated(): - obj_type = ContentType.objects.get_for_model(djperson) - note_refs = dji.NoteRef.filter(object_type=obj_type, - object_id=djperson.id) - for note_ref in note_refs: - note = table.db.get_note_from_handle( - note_ref.ref_object.handle) - table.row(table.db.get_note_from_handle(note.handle), - str(note_ref.ref_object.note_type), - note_ref.ref_object.text[:50]) - retval += table.get_html() - if user.is_authenticated(): - retval += make_button(_("Add note"), "/person/%s/note/add" % djperson.handle) - return retval - -def person_gallery_table(djperson, user): +def gallery_table(obj, user, action, url=None, *args): retval = "" table = Table() table.columns(_("Name"), _("Type"), ) retval += table.get_html() - if user.is_authenticated(): - retval += make_button(_("Add gallery"), "/person/%s/gallery/add" % djperson.handle) + if user.is_authenticated() and url and action != "edit": + retval += make_button(_("Add gallery"), (url + "/add") % args) + else: + retval += nbsp("") # to keep tabs same height return retval -def person_internet_table(djperson, user): +def internet_table(obj, user, action, url=None, *args): retval = "" table = Table() table.columns(_("Type"), _("Path"), _("Description")) if user.is_authenticated(): - urls = dji.Url.filter(person=djperson) + urls = dji.Url.filter(person=obj) for url in urls: table.row(str(url.url_type), url.path, url.desc) retval += table.get_html() - if user.is_authenticated(): - retval += make_button(_("Add internet"), "/person/%s/internet/add" % djperson.handle) + if user.is_authenticated() and url and action != "edit": + retval += make_button(_("Add internet"), (url + "/add") % args) + else: + retval += nbsp("") # to keep tabs same height return retval -def person_association_table(djperson, user): +def association_table(obj, user, action, url=None, *args): retval = "" table = Table() table.columns(_("Name"), _("ID"), _("Association")) if user.is_authenticated(): - gperson = table.db.get_person_from_handle(djperson.handle) + gperson = table.db.get_person_from_handle(obj.handle) associations = gperson.get_person_ref_list() for association in associations: table.row() retval += table.get_html() - if user.is_authenticated(): - retval += make_button(_("Add association"), "/person/%s/association/add" % djperson.handle) + if user.is_authenticated() and url and action != "edit": + retval += make_button(_("Add association"), (url + "/add") % args) + else: + retval += nbsp("") # to keep tabs same height return retval -def person_lds_table(djperson, user): +def lds_table(obj, user, action, url=None, *args): retval = "" table = Table() table.columns(_("Type"), @@ -365,8 +403,8 @@ def person_lds_table(djperson, user): _("Temple"), _("Place")) if user.is_authenticated(): - obj_type = ContentType.objects.get_for_model(djperson) - ldss = djperson.lds_set.all().order_by("order") + obj_type = ContentType.objects.get_for_model(obj) + ldss = obj.lds_set.all().order_by("order") for lds in ldss: table.row(str(lds.lds_type), display_date(lds), @@ -374,25 +412,29 @@ def person_lds_table(djperson, user): lds.temple, get_title(lds.place)) retval += table.get_html() - if user.is_authenticated(): - retval += make_button(_("Add LDS"), "/person/%s/lds/add" % djperson.handle) + if user.is_authenticated() and url and action != "edit": + retval += make_button(_("Add LDS"), (url + "/add") % args) + else: + retval += nbsp("") # to keep tabs same height return retval -def person_reference_table(djperson, user): +def reference_table(obj, user, action, url=None, *args): retval = "" table = Table() table.columns(_("Type"), _("ID"), _("Name")) if user.is_authenticated(): - references = dji.PersonRef.filter(ref_object=djperson) + references = dji.PersonRef.filter(ref_object=obj) for reference in references: table.row(str(reference.ref_object), reference.ref_object.gramps_id, make_name(reference.ref_object.name_set, user)) - return table.get_html() + retval += table.get_html() + retval += nbsp("") # to keep tabs same height + return retval -def family_children_table(djfamily, user): +def children_table(obj, user, action, url=None, *args): retval = "" table = Table() table.columns( @@ -407,74 +449,7 @@ def family_children_table(djfamily, user): #if user.is_authenticated(): #for djfamily: # table.row("test") - return table.get_html() - -def family_event_table(djfamily, user): - retval = "" - table = Table() - table.columns( - _("Description"), - _("Type"), - _("ID"), - _("Date"), - _("Place"), - _("Role"), - ) - table.row("test") - return table.get_html() - -def family_source_table(djfamily, user): - retval = "" - table = Table() - table.columns( - _("ID"), - _("Type"), - _("Author"), - _("Page"), - ) - table.row("test") - return table.get_html() - -def family_attribute_table(djfamily, user): - retval = "" - table = Table() - table.columns( - _("Type"), - _("Value"), - ) - table.row("test") - return table.get_html() - -def family_note_table(djfamily, user): - retval = "" - table = Table() - table.columns( - _("Type"), - _("Preview"), - ) - table.row("test") - return table.get_html() - -def family_gallery_table(djfamily, user): - retval = "" - table = Table() - table.columns( - _("Column"), - ) - table.row("test") - return table.get_html() - -def family_lds_table(djfamily, user): - retval = "" - table = Table() - table.columns( - _("Type"), - _("Date"), - _("Status"), - _("Temple"), - _("Place"), - ) - table.row("test") + retval += nbsp("") # to keep tabs same height return table.get_html() ## FIXME: these dji function wrappers just use the functions @@ -488,14 +463,14 @@ def get_title(place): def person_get_birth_date(person): db = DjangoDb() - event = get_birth_or_fallback(db, person) + event = get_birth_or_fallback(db, db.get_person_from_handle(person.handle)) if event: return event.date return None def person_get_death_date(person): db = DjangoDb() - event = get_death_or_fallback(db, person) + event = get_death_or_fallback(db, db.get_person_from_handle(person.handle)) if event: return event.date return None @@ -530,7 +505,7 @@ def person_get_event(person, event_type=None): for event_handle in event_ref_list] return [j for i in retval for j in i] -def make_name(name, user=None): +def make_name(name, user): if isinstance(name, models.Name): surname = name.surname.strip() if not surname: @@ -560,6 +535,9 @@ def make_name(name, user=None): return "[No preferred name]" else: return "%s, %s" % (name.get_surname(), name.get_first_name()) + elif isinstance(name, models.Person): # django person + person = name + return make_name(person.name_set.get(preferred=True), user) else: # no name return ""
    Family:{{name.surname}}Prefix:{{name.prefix}}{{nameform.surname.label}}{{nameform.surname|render:action}}{{nameform.prefix.label}}{{nameform.prefix|render:action}} Image:
    Suffix:{{name.suffix}}{{nameform.suffix.label}}{{nameform.suffix|render:action}}
    Given:{{name.first_name}}Call Name:{{name.call}}{{nameform.first_name.label}}{{nameform.first_name|render:action}}{{nameform.call.label}}{{nameform.call|render:action}}
    Type:{{name.name_type}}Patronymic:{{name.patronymic}}{{nameform.name_type.label}}{{nameform.name_type|render:action}}{{nameform.patronymic.label}}{{nameform.patronymic|render:action}}
    Title:{{name.title}}{{nameform.title.label}}{{nameform.title|render:action}}
    Gender:{{person.gender_type}}ID:{{person.gramps_id}}{{personform.gender_type.label}}{{personform.gender_type|render:action}}{{personform.gramps_id.label}}{{personform.gramps_id|render:action}}
    Marker:{{person.marker_type}}{{personform.marker_type.label}}{{personform.marker_type|render:action}}