Infrastructure to add or share references
svn: r19706
This commit is contained in:
parent
ecf49d95e8
commit
f33986204c
@ -6,7 +6,7 @@
|
||||
<div class="content" id="IndividualDetail">
|
||||
|
||||
{% include "detail_breadcrumb.html" %}
|
||||
<h2>Reference Detail</h2>
|
||||
<h2>Temporary Reference Detail</h2>
|
||||
<div id="summaryarea">
|
||||
<table class="infolist" style="width:90%;">
|
||||
<trbody>
|
||||
@ -19,11 +19,9 @@
|
||||
<form method="post">{% csrf_token %}
|
||||
|
||||
{% for field in form %}
|
||||
|
||||
<tr>
|
||||
{{field}}
|
||||
</tr>
|
||||
|
||||
{% endfor %}
|
||||
|
||||
</table>
|
||||
|
@ -61,7 +61,7 @@
|
||||
|
||||
</div>
|
||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-notes">
|
||||
{% note_table citation user action "/note/add/citation/%s" citation.handle %}
|
||||
{% note_table citation user action "/note/$act/citation/%s" citation.handle %}
|
||||
</div>
|
||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-gallery">
|
||||
</div>
|
||||
@ -115,7 +115,7 @@
|
||||
|
||||
</div>
|
||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-shared-notes">
|
||||
{% note_table source user action "/note/add/source/%s" source.handle %}
|
||||
{% note_table source user action "/note/$act/source/%s" source.handle %}
|
||||
</div>
|
||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-shared-gallery">
|
||||
</div>
|
||||
|
@ -98,19 +98,19 @@
|
||||
{% children_table family user action "/family/%s/add/child" family.handle %}
|
||||
</div>
|
||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-events">
|
||||
{% event_table family user action "/event/add/family/%s" family.handle %}
|
||||
{% event_table family user action "/event/$act/family/%s" family.handle %}
|
||||
</div>
|
||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-sources">
|
||||
{% source_table family user action "/source/add/family/%s" family.handle %}
|
||||
{% source_table family user action "/source/$act/family/%s" family.handle %}
|
||||
</div>
|
||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-attributes">
|
||||
{% attribute_table family user action "/attribute/add/family/%s" family.handle %}
|
||||
</div>
|
||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-notes">
|
||||
{% note_table family user action "/note/add/family/%s" family.handle %}
|
||||
{% note_table family user action "/note/$act/family/%s" family.handle %}
|
||||
</div>
|
||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-gallery">
|
||||
{% gallery_table family user action "/media/add/family/%s" family.handle %}
|
||||
{% gallery_table family user action "/media/$act/family/%s" family.handle %}
|
||||
</div>
|
||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-lds">
|
||||
{% lds_table family user action "/lds/add/family/%s" family.handle %}
|
||||
|
@ -111,7 +111,7 @@
|
||||
|
||||
<input type="button"
|
||||
value="Back to Person"
|
||||
onclick="document.location.href='/person/{{person.handle}}'"/>
|
||||
onclick="document.location.href='/person/{{person.handle}}#tab-names'"/>
|
||||
{% if user.is_authenticated %}
|
||||
{% ifequal action "add" %}
|
||||
<input type="hidden" name="action" value="create"/>
|
||||
|
@ -93,38 +93,38 @@
|
||||
</ul>
|
||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom" id="tab-events">
|
||||
<!-- Events -->
|
||||
{% event_table person user action "/event/add/person/%s" person.handle %}
|
||||
{% event_table person user action "/event/$act/person/%s" person.handle %}
|
||||
</div>
|
||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-names">
|
||||
{% name_table person user action "/person/%s/name" person.handle %}
|
||||
</div>
|
||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-citations">
|
||||
{% citation_table person user action "/citation/add/person/%s" person.handle %}
|
||||
{% citation_table person user action "/citation/$act/person/%s" person.handle %}
|
||||
</div>
|
||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-attributes">
|
||||
{% attribute_table person user action "/attribute/add/person/%s" person.handle %}
|
||||
{% attribute_table person user action "/attribute/$act/person/%s" person.handle %}
|
||||
</div>
|
||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-addresses">
|
||||
{% address_table person user action "/place/add/person/%s" person.handle %}
|
||||
{% address_table person user action "/place/$act/person/%s" person.handle %}
|
||||
</div>
|
||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom
|
||||
ui-tabs-hide" id="tab-notes">
|
||||
{% note_table person user action "/note/add/person/%s" person.handle %}
|
||||
{% note_table person user action "/note/$act/person/%s" person.handle %}
|
||||
</div>
|
||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-gallery">
|
||||
{% gallery_table person user action "/media/add/person/%s" person.handle %}
|
||||
{% gallery_table person user action "/media/$act/person/%s" person.handle %}
|
||||
</div>
|
||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-internet">
|
||||
{% internet_table person user action "/person/%s/add/internet" person.handle %}
|
||||
{% internet_table person user action "/person/%s/$act/internet" person.handle %}
|
||||
</div>
|
||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-association">
|
||||
{% association_table person user action "/person/%s/add/association" person.handle %}
|
||||
{% association_table person user action "/person/%s/$act/association" person.handle %}
|
||||
</div>
|
||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-lds">
|
||||
{% lds_table person user action "/person/%s/add/lds" person.handle %}
|
||||
{% lds_table person user action "/person/%s/$act/lds" person.handle %}
|
||||
</div>
|
||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-references">
|
||||
{% reference_table person user action "/reference/add/person/%s" person.handle %}
|
||||
{% reference_table person user action "/reference/$act/person/%s" person.handle %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -78,10 +78,10 @@
|
||||
{% else %}
|
||||
<input type="button"
|
||||
value="Back to Person"
|
||||
onclick="document.location.href='/person/{{person.handle}}'"/>
|
||||
onclick="document.location.href='/person/{{person.handle}}#tab-names'"/>
|
||||
<input type="button"
|
||||
value="Back to Name"
|
||||
onclick="document.location.href='/person/{{person.handle}}/name/{{order}}'"/>
|
||||
onclick="document.location.href='/person/{{person.handle}}/name/{{order}}#tab-surnames'"/>
|
||||
<input type="button"
|
||||
value="Edit Surname"
|
||||
onclick="document.location.href='/person/{{person.handle}}/name/{{order}}/surname/{{sorder}}/edit'"/>
|
||||
@ -93,10 +93,10 @@
|
||||
{% else %}
|
||||
<input type="button"
|
||||
value="Back to Person"
|
||||
onclick="document.location.href='/person/{{person.handle}}'"/>
|
||||
onclick="document.location.href='/person/{{person.handle}}#tab-names'"/>
|
||||
<input type="button"
|
||||
value="Back to Name"
|
||||
onclick="document.location.href='/person/{{person.handle}}/name/order'"/>
|
||||
onclick="document.location.href='/person/{{person.handle}}/name/order#tab-surnames'"/>
|
||||
{% endif %}
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
@ -816,14 +816,16 @@ class EventRef(BaseRef):
|
||||
role_type = models.ForeignKey('EventRoleType')
|
||||
|
||||
def __unicode__(self):
|
||||
return "EventRef to " + str(self.ref_object)
|
||||
return str(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)
|
||||
ref_to = self.ref_object.__class__.__name__.lower()
|
||||
ref_to = self.ref_object
|
||||
return "/%s/%s/reference/%s/%s" % (ref_by.__class__.__name__.lower(),
|
||||
ref_by.handle, ref_to, self.order)
|
||||
ref_by.handle,
|
||||
ref_to.__class__.__name__.lower(),
|
||||
self.order)
|
||||
|
||||
class RepositoryRef(BaseRef):
|
||||
ref_object = models.ForeignKey('Repository')
|
||||
|
@ -94,7 +94,7 @@ def process_citation(request, context, handle, action, add_to=None): # view, edi
|
||||
model = dji.get_model(item)
|
||||
obj = model.objects.get(handle=handle)
|
||||
dji.add_citation_ref(obj, citation.handle)
|
||||
return redirect("/%s/%s" % (item, handle))
|
||||
return redirect("/%s/%s#tab-citations" % (item, handle))
|
||||
action = "view"
|
||||
else:
|
||||
action = "add"
|
||||
|
@ -90,7 +90,7 @@ def process_event(request, context, handle, action, add_to=None): # view, edit,
|
||||
model = dji.get_model(item)
|
||||
obj = model.objects.get(handle=handle)
|
||||
dji.add_event_ref_default(obj, event)
|
||||
return redirect("/%s/%s" % (item, handle))
|
||||
return redirect("/%s/%s#tab-events" % (item, handle))
|
||||
action = "view"
|
||||
else:
|
||||
action = "add"
|
||||
|
@ -81,7 +81,7 @@ def process_media(request, context, handle, action, add_to=None): # view, edit,
|
||||
model = dji.get_model(item)
|
||||
obj = model.objects.get(handle=handle)
|
||||
dji.add_media_ref_default(obj, media)
|
||||
return redirect("/%s/%s" % (item, handle))
|
||||
return redirect("/%s/%s#tab-gallery" % (item, handle))
|
||||
action = "view"
|
||||
else:
|
||||
action = "add"
|
||||
|
@ -146,7 +146,7 @@ def process_surname(request, handle, order, sorder, action="view"):
|
||||
neworder += 1
|
||||
else:
|
||||
request.user.message_set.create(message="You can't delete the only surname")
|
||||
return redirect("/person/%s/name/%s" % (person.handle, name.order))
|
||||
return redirect("/person/%s/name/%s#tab-surnames" % (person.handle, name.order))
|
||||
elif action in ["add"]:
|
||||
surname = Surname(name=name, primary=False,
|
||||
name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0]))
|
||||
@ -166,7 +166,7 @@ def process_surname(request, handle, order, sorder, action="view"):
|
||||
surname = sf.save(commit=False)
|
||||
check_primary(surname, surnames)
|
||||
surname.save()
|
||||
return redirect("/person/%s/name/%s/surname/%s" %
|
||||
return redirect("/person/%s/name/%s/surname/%s#tab-surnames" %
|
||||
(person.handle, name.order, sorder))
|
||||
action = "add"
|
||||
surname.prefix = make_empty(True, surname.prefix, " prefix ")
|
||||
@ -179,7 +179,7 @@ def process_surname(request, handle, order, sorder, action="view"):
|
||||
surname = sf.save(commit=False)
|
||||
check_primary(surname, name.surname_set.all().exclude(order=surname.order))
|
||||
surname.save()
|
||||
return redirect("/person/%s/name/%s/surname/%s" %
|
||||
return redirect("/person/%s/name/%s/surname/%s#tab-surnames" %
|
||||
(person.handle, name.order, sorder))
|
||||
action = "edit"
|
||||
surname.prefix = make_empty(True, surname.prefix, " prefix ")
|
||||
@ -224,7 +224,7 @@ def process_name(request, handle, order, action="view"):
|
||||
check_order(request, person)
|
||||
else:
|
||||
request.user.message_set.create(message = "Can't delete only name.")
|
||||
return redirect("/person/%s" % person.handle)
|
||||
return redirect("/person/%s#tab-names" % person.handle)
|
||||
elif action == "add": # add name
|
||||
person = Person.objects.get(handle=handle)
|
||||
name = Name(person=person,
|
||||
@ -275,7 +275,7 @@ def process_name(request, handle, order, action="view"):
|
||||
surname.primary = True # FIXME: why is this False?
|
||||
surname.save()
|
||||
dji.rebuild_cache(person)
|
||||
return redirect("/person/%s/name/%s" % (person.handle, name.order))
|
||||
return redirect("/person/%s/name/%s#tab-surnames" % (person.handle, name.order))
|
||||
else:
|
||||
action = "add"
|
||||
elif action == "save":
|
||||
@ -309,7 +309,7 @@ def process_name(request, handle, order, action="view"):
|
||||
surname.primary = True # FIXME: why is this False?
|
||||
surname.save()
|
||||
dji.rebuild_cache(person)
|
||||
return redirect("/person/%s/name/%s" % (person.handle, name.order))
|
||||
return redirect("/person/%s/name/%s#tab-surnames" % (person.handle, name.order))
|
||||
else:
|
||||
action = "edit"
|
||||
context = RequestContext(request)
|
||||
|
@ -81,7 +81,7 @@ def process_place(request, context, handle, action, add_to=None): # view, edit,
|
||||
model = dji.get_model(item)
|
||||
obj = model.objects.get(handle=handle)
|
||||
dji.add_place_ref(obj, place.handle)
|
||||
return redirect("/%s/%s" % (item, handle))
|
||||
return redirect("/%s/%s#tab-places" % (item, handle))
|
||||
action = "view"
|
||||
else:
|
||||
action = "add"
|
||||
|
@ -81,7 +81,7 @@ def process_repository(request, context, handle, action, add_to=None): # view, e
|
||||
model = dji.get_model(item)
|
||||
obj = model.objects.get(handle=handle)
|
||||
dji.add_repository_ref(obj, repository)
|
||||
return redirect("/%s/%s" % (item, handle))
|
||||
return redirect("/%s/%s#tab-repositories" % (item, handle))
|
||||
action = "view"
|
||||
else:
|
||||
action = "add"
|
||||
|
@ -79,7 +79,7 @@ def process_tag(request, context, handle, action, add_to=None): # view, edit, sa
|
||||
model = dji.get_model(item)
|
||||
obj = model.objects.get(handle=handle)
|
||||
dji.add_tag_ref_default(obj, tag)
|
||||
return redirect("/%s/%s" % (item, handle))
|
||||
return redirect("/%s/%s#tab-tags" % (item, handle))
|
||||
action = "view"
|
||||
else:
|
||||
action = "add"
|
||||
|
@ -537,6 +537,13 @@ def check_access(request, context, obj, action):
|
||||
else: # outside viewer
|
||||
return not obj.private
|
||||
|
||||
def add_share(request, view, item, handle):
|
||||
"""
|
||||
Add a reference to an existing <view> referenced from <item>.
|
||||
"""
|
||||
# /view/share/person/handle
|
||||
raise Http404(_('Not implemented yet.'))
|
||||
|
||||
def add_to(request, view, item, handle):
|
||||
"""
|
||||
Add a new <view> referenced from <item>.
|
||||
@ -703,18 +710,26 @@ def build_person_query(search, protect):
|
||||
|
||||
|
||||
def process_reference(request, ref_by, handle, ref_to, order):
|
||||
# FIXME: can I make this work for all?
|
||||
context = RequestContext(request)
|
||||
ref_by_class = dji.get_model(ref_by)
|
||||
referenced_by = ref_by_class.objects.get(handle=handle)
|
||||
object_type = ContentType.objects.get_for_model(referenced_by)
|
||||
ref_to_class = dji.get_model("%sRef" % ref_to.title())
|
||||
exclude = ["last_changed_by", "last_changed", "object_type", "object_id", "order"]
|
||||
if order == "new":
|
||||
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,
|
||||
object_type=object_type,
|
||||
order=order)
|
||||
form = modelformset_factory(ref_to_class, extra=0)(queryset=referenced_to)
|
||||
form = modelformset_factory(ref_to_class, exclude=exclude, extra=0)(queryset=referenced_to)
|
||||
form.model = referenced_to[0]
|
||||
context["form"] = form
|
||||
context["view"] = 'Reference'
|
||||
context["view"] = 'reference'
|
||||
context["tview"] = _('Reference')
|
||||
context["tviews"] = _('References')
|
||||
context["object"] = referenced_by
|
||||
|
@ -73,6 +73,8 @@ urlpatterns += patterns('',
|
||||
{"handle": None, "action": "add"}), # /view/add
|
||||
(r'^(?P<view>(\w+))/add/(?P<item>(\w+))/(?P<handle>(\w+))$',
|
||||
add_to), # /view/add/item/handle
|
||||
(r'^(?P<view>(\w+))/share/(?P<item>(\w+))/(?P<handle>(\w+))$',
|
||||
add_share), # /view/share/item/handle
|
||||
(r'^(?P<view>(\w+))/(?P<handle>(\w+))/$', action,
|
||||
{"action": "view"}), # /view/handle/
|
||||
(r'^(?P<view>(\w+))/(?P<handle>(\w+))/(?P<action>(\w+))$',
|
||||
|
@ -218,11 +218,10 @@ def make_button(text, url, *args):
|
||||
#return """[ <a href="%s">%s</a> ] """ % (url, text)
|
||||
return """<input type="button" value="%s" onclick="document.location.href='%s'"/>""" % (text, url)
|
||||
|
||||
def event_table(obj, user, action, url=None, *args):
|
||||
def event_table(obj, user, action, url, args):
|
||||
retval = ""
|
||||
table = Table()
|
||||
table.columns(
|
||||
_("Event Reference"),
|
||||
_("Description"),
|
||||
_("Type"),
|
||||
_("ID"),
|
||||
@ -238,15 +237,15 @@ def event_table(obj, user, action, url=None, *args):
|
||||
for (djevent, event_ref) in event_list:
|
||||
table.row(
|
||||
event_ref,
|
||||
djevent.description or str(djevent),
|
||||
table.db.get_event_from_handle(djevent.handle),
|
||||
djevent.gramps_id,
|
||||
display_date(djevent),
|
||||
get_title(djevent.place),
|
||||
str(event_ref.role_type))
|
||||
retval += table.get_html()
|
||||
if user.is_superuser and url and action == "view":
|
||||
retval += make_button(_("Add event"), (url % args))
|
||||
if user.is_superuser and action == "view":
|
||||
retval += make_button(_("Add event"), (url % args).replace("$act", "add"))
|
||||
retval += make_button(_("Share event"), (url % args).replace("$act", "share"))
|
||||
else:
|
||||
retval += nbsp("") # to keep tabs same height
|
||||
return retval
|
||||
@ -339,7 +338,8 @@ def source_table(obj, user, action, url=None, *args):
|
||||
)
|
||||
retval += table.get_html()
|
||||
if user.is_superuser and url and action == "view":
|
||||
retval += make_button(_("Add source"), (url % args))
|
||||
retval += make_button(_("Add source"), (url % args).replace("$act", "add"))
|
||||
retval += make_button(_("Share source"), (url % args).replace("$act", "share"))
|
||||
else:
|
||||
retval += nbsp("") # to keep tabs same height
|
||||
return retval
|
||||
@ -364,7 +364,8 @@ def citation_table(obj, user, action, url=None, *args):
|
||||
)
|
||||
retval += table.get_html()
|
||||
if user.is_superuser and url and action == "view":
|
||||
retval += make_button(_("Add citation"), (url % args))
|
||||
retval += make_button(_("Add citation"), (url % args).replace("$act", "add"))
|
||||
retval += make_button(_("Share citation"), (url % args).replace("$act", "share"))
|
||||
else:
|
||||
retval += nbsp("") # to keep tabs same height
|
||||
return retval
|
||||
@ -388,7 +389,8 @@ def note_table(obj, user, action, url=None, *args):
|
||||
note_ref.ref_object.text[:50])
|
||||
retval += table.get_html()
|
||||
if user.is_superuser and url and action == "view":
|
||||
retval += make_button(_("Add note"), (url % args))
|
||||
retval += make_button(_("Add note"), (url % args).replace("$act", "add"))
|
||||
retval += make_button(_("Share note"), (url % args).replace("$act", "share"))
|
||||
else:
|
||||
retval += nbsp("") # to keep tabs same height
|
||||
return retval
|
||||
@ -440,12 +442,23 @@ def address_table(obj, user, action, url=None, *args):
|
||||
def gallery_table(obj, user, action, url=None, *args):
|
||||
retval = ""
|
||||
table = Table()
|
||||
table.columns(_("Name"),
|
||||
table.columns(_("Description"),
|
||||
_("Type"),
|
||||
)
|
||||
if user.is_authenticated():
|
||||
obj_type = ContentType.objects.get_for_model(obj)
|
||||
media_refs = dji.MediaRef.filter(object_type=obj_type,
|
||||
object_id=obj.id)
|
||||
for media_ref in media_refs:
|
||||
media = table.db.get_object_from_handle(
|
||||
media_ref.ref_object.handle)
|
||||
table.row(table.db.get_object_from_handle(media.handle),
|
||||
str(media_ref.ref_object.desc),
|
||||
media_ref.ref_object.path)
|
||||
retval += table.get_html()
|
||||
if user.is_superuser and url and action == "view":
|
||||
retval += make_button(_("Add gallery"), (url % args))
|
||||
retval += make_button(_("Add media"), (url % args).replace("$act", "add"))
|
||||
retval += make_button(_("Share media"), (url % args).replace("$act", "share"))
|
||||
else:
|
||||
retval += nbsp("") # to keep tabs same height
|
||||
return retval
|
||||
@ -617,7 +630,11 @@ def render(formfield, user, action, test=False, truetext="", id=None):
|
||||
if (not user.is_authenticated() and not test) or user.is_authenticated():
|
||||
fieldname = formfield.name # 'surname'
|
||||
try:
|
||||
retval = str(getattr(formfield.form.model, fieldname))
|
||||
item = getattr(formfield.form.model, fieldname)
|
||||
if (item.__class__.__name__ == 'ManyRelatedManager'):
|
||||
retval = ", ".join([str(i) for i in item.all()])
|
||||
else:
|
||||
retval = str(item)
|
||||
if retval == "True":
|
||||
retval = "Yes"
|
||||
elif retval == "False":
|
||||
|
Loading…
Reference in New Issue
Block a user