Refactor to allow references to be viewed/edited
svn: r20086
This commit is contained in:
parent
6c4f7b5699
commit
bd15d69989
@ -845,6 +845,14 @@ class BaseRef(models.Model):
|
|||||||
#attributes = models.ManyToManyField("Attribute", null=True)
|
#attributes = models.ManyToManyField("Attribute", null=True)
|
||||||
private = models.BooleanField()
|
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):
|
class Log(BaseRef):
|
||||||
log_type = models.CharField(max_length=10) # edit, delete, add
|
log_type = models.CharField(max_length=10) # edit, delete, add
|
||||||
reason = models.TextField() # must be filled in
|
reason = models.TextField() # must be filled in
|
||||||
@ -859,6 +867,9 @@ class Log(BaseRef):
|
|||||||
class NoteRef(BaseRef):
|
class NoteRef(BaseRef):
|
||||||
ref_object = models.ForeignKey('Note')
|
ref_object = models.ForeignKey('Note')
|
||||||
|
|
||||||
|
def get_reference_to(self):
|
||||||
|
return self.ref_object
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return "NoteRef to " + str(self.ref_object)
|
return "NoteRef to " + str(self.ref_object)
|
||||||
|
|
||||||
@ -869,6 +880,9 @@ class EventRef(BaseRef):
|
|||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return str(self.ref_object)
|
return str(self.ref_object)
|
||||||
|
|
||||||
|
def get_reference_to(self):
|
||||||
|
return self.ref_object
|
||||||
|
|
||||||
def get_url(self):
|
def get_url(self):
|
||||||
# /person/3536453463/reference/event/2
|
# /person/3536453463/reference/event/2
|
||||||
ref_by = self.object_type.model_class().objects.get(id=self.object_id)
|
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')
|
source_media_type = models.ForeignKey('SourceMediaType')
|
||||||
call_number = models.CharField(max_length=50)
|
call_number = models.CharField(max_length=50)
|
||||||
|
|
||||||
|
def get_reference_to(self):
|
||||||
|
return self.ref_object
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return "RepositoryRef to " + str(self.ref_object)
|
return "RepositoryRef to " + str(self.ref_object)
|
||||||
|
|
||||||
@ -890,6 +907,9 @@ class PersonRef(BaseRef):
|
|||||||
ref_object = models.ForeignKey('Person')
|
ref_object = models.ForeignKey('Person')
|
||||||
description = models.CharField(max_length=50, blank=True, null=True)
|
description = models.CharField(max_length=50, blank=True, null=True)
|
||||||
|
|
||||||
|
def get_reference_to(self):
|
||||||
|
return self.ref_object
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return "PersonRef to " + str(self.ref_object)
|
return "PersonRef to " + str(self.ref_object)
|
||||||
|
|
||||||
@ -899,6 +919,9 @@ class CitationRef(BaseRef):
|
|||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return "CitationRef to " + str(self.citation)
|
return "CitationRef to " + str(self.citation)
|
||||||
|
|
||||||
|
def get_reference_to(self):
|
||||||
|
return self.citation
|
||||||
|
|
||||||
class ChildRef(BaseRef):
|
class ChildRef(BaseRef):
|
||||||
father_rel_type = models.ForeignKey('ChildRefType',
|
father_rel_type = models.ForeignKey('ChildRefType',
|
||||||
related_name="child_father_rel")
|
related_name="child_father_rel")
|
||||||
@ -906,6 +929,13 @@ class ChildRef(BaseRef):
|
|||||||
related_name="child_mother_rel")
|
related_name="child_mother_rel")
|
||||||
ref_object = models.ForeignKey('Person')
|
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):
|
def __unicode__(self):
|
||||||
return "ChildRef to " + str(self.ref_object)
|
return "ChildRef to " + str(self.ref_object)
|
||||||
|
|
||||||
@ -916,6 +946,9 @@ class MediaRef(BaseRef):
|
|||||||
y2 = models.IntegerField()
|
y2 = models.IntegerField()
|
||||||
ref_object = models.ForeignKey('Media')
|
ref_object = models.ForeignKey('Media')
|
||||||
|
|
||||||
|
def get_reference_to(self):
|
||||||
|
return self.ref_object
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return "MediaRef to " + str(self.ref_object)
|
return "MediaRef to " + str(self.ref_object)
|
||||||
|
|
||||||
|
@ -1250,8 +1250,9 @@ def process_reference(request, ref_by, handle, ref_to, order):
|
|||||||
context["tviews"] = _('References')
|
context["tviews"] = _('References')
|
||||||
context["object"] = referenced_by
|
context["object"] = referenced_by
|
||||||
context["handle"] = referenced_by.handle
|
context["handle"] = referenced_by.handle
|
||||||
context["url"] = "/%s/%s" % (referenced_to[0].ref_object.__class__.__name__.lower(),
|
context["url"] = referenced_to[0].get_reference_to().get_url()
|
||||||
referenced_to[0].ref_object.handle)
|
#"/%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(),
|
context["referenced_by"] = "/%s/%s" % (referenced_by.__class__.__name__.lower(),
|
||||||
referenced_by.handle)
|
referenced_by.handle)
|
||||||
context["action"] = "view"
|
context["action"] = "view"
|
||||||
@ -1324,6 +1325,9 @@ def process_list_item(request, view, handle, act, item, index):
|
|||||||
if item == "eventref":
|
if item == "eventref":
|
||||||
refs = dji.EventRef.filter(object_id=obj.id,
|
refs = dji.EventRef.filter(object_id=obj.id,
|
||||||
object_type=obj_type).order_by("order")
|
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:
|
# Next, perform action:
|
||||||
if act == "remove":
|
if act == "remove":
|
||||||
count = 1
|
count = 1
|
||||||
|
@ -312,6 +312,7 @@ def event_table(obj, user, act, url, args):
|
|||||||
object_id=obj.id,
|
object_id=obj.id,
|
||||||
object_type=obj_type).order_by("order")
|
object_type=obj_type).order_by("order")
|
||||||
event_list = [(o.ref_object, o) for o in event_ref_list]
|
event_list = [(o.ref_object, o) for o in event_ref_list]
|
||||||
|
links = []
|
||||||
count = 1
|
count = 1
|
||||||
for (djevent, event_ref) in event_list:
|
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 "",
|
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),
|
display_date(djevent),
|
||||||
get_title(djevent.place),
|
get_title(djevent.place),
|
||||||
str(event_ref.role_type))
|
str(event_ref.role_type))
|
||||||
|
links.append(('URL', event_ref.get_url()))
|
||||||
count += 1
|
count += 1
|
||||||
|
table.links(links)
|
||||||
retval += table.get_html()
|
retval += table.get_html()
|
||||||
if user.is_superuser and act == "view":
|
if user.is_superuser and act == "view":
|
||||||
count = 1
|
count = 1
|
||||||
@ -435,17 +438,20 @@ def citation_table(obj, user, act, url=None, *args):
|
|||||||
obj_type = ContentType.objects.get_for_model(obj)
|
obj_type = ContentType.objects.get_for_model(obj)
|
||||||
citation_refs = dji.CitationRef.filter(object_type=obj_type,
|
citation_refs = dji.CitationRef.filter(object_type=obj_type,
|
||||||
object_id=obj.id).order_by("order")
|
object_id=obj.id).order_by("order")
|
||||||
|
links = []
|
||||||
count = 1
|
count = 1
|
||||||
for citation_ref in citation_refs:
|
for citation_ref in citation_refs:
|
||||||
if citation_ref.citation:
|
if citation_ref.citation:
|
||||||
citation = table.db.get_citation_from_handle(
|
citation = table.db.get_citation_from_handle(
|
||||||
citation_ref.citation.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 "",
|
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.confidence),
|
||||||
str(citation.page),
|
str(citation.page),
|
||||||
)
|
)
|
||||||
|
links.append(('URL', citation_ref.get_url()))
|
||||||
count += 1
|
count += 1
|
||||||
|
table.links(links)
|
||||||
retval += table.get_html()
|
retval += table.get_html()
|
||||||
if user.is_superuser and url and act == "view":
|
if user.is_superuser and url and act == "view":
|
||||||
count = 1
|
count = 1
|
||||||
@ -895,7 +901,7 @@ def children_table(obj, user, act, url=None, *args):
|
|||||||
childref.mother_rel_type,
|
childref.mother_rel_type,
|
||||||
date_as_text(child.birth, user),
|
date_as_text(child.birth, user),
|
||||||
)
|
)
|
||||||
links.append(('URL', ("/person/%s" % child.handle)))
|
links.append(('URL', childref.get_url()))
|
||||||
count += 1
|
count += 1
|
||||||
else:
|
else:
|
||||||
table.row("",
|
table.row("",
|
||||||
@ -907,8 +913,8 @@ def children_table(obj, user, act, url=None, *args):
|
|||||||
"[Private]",
|
"[Private]",
|
||||||
"[Private]",
|
"[Private]",
|
||||||
)
|
)
|
||||||
if not child.private:
|
if not child.private and not childref.private:
|
||||||
links.append(('URL', ("/person/%s" % child.handle)))
|
links.append(('URL', childref.get_url()))
|
||||||
else:
|
else:
|
||||||
links.append((None, None))
|
links.append((None, None))
|
||||||
count += 1
|
count += 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user