From bd15d69989f0ab778df77f76c374ca480a320712 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Thu, 26 Jul 2012 13:27:49 +0000 Subject: [PATCH] Refactor to allow references to be viewed/edited svn: r20086 --- src/webapp/grampsdb/models.py | 33 +++++++++++++++++++++++++++++++++ src/webapp/grampsdb/views.py | 8 ++++++-- src/webapp/utils.py | 14 ++++++++++---- 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/webapp/grampsdb/models.py b/src/webapp/grampsdb/models.py index a74abc203..fc80237b5 100644 --- a/src/webapp/grampsdb/models.py +++ b/src/webapp/grampsdb/models.py @@ -845,6 +845,14 @@ class BaseRef(models.Model): #attributes = models.ManyToManyField("Attribute", null=True) private = models.BooleanField() + def get_url(self): + # /person/3536453463/reference/event/2 + ref_by = self.object_type.model_class().objects.get(id=self.object_id) + ref_to = self.get_reference_to() + return "/%s/%s/reference/%s/%s" % (ref_by.__class__.__name__.lower(), + ref_by.handle, + ref_to.__class__.__name__.lower(), + self.order) class Log(BaseRef): log_type = models.CharField(max_length=10) # edit, delete, add reason = models.TextField() # must be filled in @@ -859,6 +867,9 @@ class Log(BaseRef): class NoteRef(BaseRef): ref_object = models.ForeignKey('Note') + def get_reference_to(self): + return self.ref_object + def __unicode__(self): return "NoteRef to " + str(self.ref_object) @@ -869,6 +880,9 @@ class EventRef(BaseRef): def __unicode__(self): return str(self.ref_object) + def get_reference_to(self): + return self.ref_object + def get_url(self): # /person/3536453463/reference/event/2 ref_by = self.object_type.model_class().objects.get(id=self.object_id) @@ -883,6 +897,9 @@ class RepositoryRef(BaseRef): source_media_type = models.ForeignKey('SourceMediaType') call_number = models.CharField(max_length=50) + def get_reference_to(self): + return self.ref_object + def __unicode__(self): return "RepositoryRef to " + str(self.ref_object) @@ -890,6 +907,9 @@ class PersonRef(BaseRef): ref_object = models.ForeignKey('Person') description = models.CharField(max_length=50, blank=True, null=True) + def get_reference_to(self): + return self.ref_object + def __unicode__(self): return "PersonRef to " + str(self.ref_object) @@ -899,6 +919,9 @@ class CitationRef(BaseRef): def __unicode__(self): return "CitationRef to " + str(self.citation) + def get_reference_to(self): + return self.citation + class ChildRef(BaseRef): father_rel_type = models.ForeignKey('ChildRefType', related_name="child_father_rel") @@ -906,6 +929,13 @@ class ChildRef(BaseRef): related_name="child_mother_rel") ref_object = models.ForeignKey('Person') + def get_reference_to(self): + return self.ref_object + + def get_url(self): + # FIXME: go to child reference + return "/person/%s" % self.ref_object.handle + def __unicode__(self): return "ChildRef to " + str(self.ref_object) @@ -916,6 +946,9 @@ class MediaRef(BaseRef): y2 = models.IntegerField() ref_object = models.ForeignKey('Media') + def get_reference_to(self): + return self.ref_object + def __unicode__(self): return "MediaRef to " + str(self.ref_object) diff --git a/src/webapp/grampsdb/views.py b/src/webapp/grampsdb/views.py index cb400b56c..8a096cc15 100644 --- a/src/webapp/grampsdb/views.py +++ b/src/webapp/grampsdb/views.py @@ -1250,8 +1250,9 @@ def process_reference(request, ref_by, handle, ref_to, order): context["tviews"] = _('References') context["object"] = referenced_by context["handle"] = referenced_by.handle - context["url"] = "/%s/%s" % (referenced_to[0].ref_object.__class__.__name__.lower(), - referenced_to[0].ref_object.handle) + context["url"] = referenced_to[0].get_reference_to().get_url() + #"/%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) context["action"] = "view" @@ -1324,6 +1325,9 @@ def process_list_item(request, view, handle, act, item, index): if item == "eventref": refs = dji.EventRef.filter(object_id=obj.id, object_type=obj_type).order_by("order") + elif item == "citationref": + refs = dji.CitationRef.filter(object_id=obj.id, + object_type=obj_type).order_by("order") # Next, perform action: if act == "remove": count = 1 diff --git a/src/webapp/utils.py b/src/webapp/utils.py index 5f2553a0d..446a35fb7 100644 --- a/src/webapp/utils.py +++ b/src/webapp/utils.py @@ -312,6 +312,7 @@ def event_table(obj, user, act, url, args): object_id=obj.id, object_type=obj_type).order_by("order") event_list = [(o.ref_object, o) for o in event_ref_list] + links = [] count = 1 for (djevent, event_ref) in event_list: table.row(Link("[[x%d]][[^%d]][[v%d]]" % (count, count, count)) if user.is_superuser and act == "view" else "", @@ -321,7 +322,9 @@ def event_table(obj, user, act, url, args): display_date(djevent), get_title(djevent.place), str(event_ref.role_type)) + links.append(('URL', event_ref.get_url())) count += 1 + table.links(links) retval += table.get_html() if user.is_superuser and act == "view": count = 1 @@ -435,17 +438,20 @@ def citation_table(obj, user, act, url=None, *args): obj_type = ContentType.objects.get_for_model(obj) citation_refs = dji.CitationRef.filter(object_type=obj_type, object_id=obj.id).order_by("order") + links = [] count = 1 for citation_ref in citation_refs: if citation_ref.citation: citation = table.db.get_citation_from_handle( citation_ref.citation.handle) table.row(Link("[[x%d]][[^%d]][[v%d]]" % (count, count, count)) if user.is_superuser and url and act == "view" else "", - citation, + citation.gramps_id, str(citation.confidence), str(citation.page), ) + links.append(('URL', citation_ref.get_url())) count += 1 + table.links(links) retval += table.get_html() if user.is_superuser and url and act == "view": count = 1 @@ -895,7 +901,7 @@ def children_table(obj, user, act, url=None, *args): childref.mother_rel_type, date_as_text(child.birth, user), ) - links.append(('URL', ("/person/%s" % child.handle))) + links.append(('URL', childref.get_url())) count += 1 else: table.row("", @@ -907,8 +913,8 @@ def children_table(obj, user, act, url=None, *args): "[Private]", "[Private]", ) - if not child.private: - links.append(('URL', ("/person/%s" % child.handle))) + if not child.private and not childref.private: + links.append(('URL', childref.get_url())) else: links.append((None, None)) count += 1