Implement adding refs to shared objects

svn: r20034
This commit is contained in:
Doug Blank 2012-07-20 17:11:13 +00:00
parent 17350a8c2f
commit 747c1c8af3
14 changed files with 318 additions and 106 deletions

View File

@ -90,7 +90,7 @@
<hr>
<h2>Shared source information</h2>
<h2>Source information (shared)</h2>
<div class="ui-tabs ui-widget ui-widget-content ui-corner-all" id="shared-tabs">
<ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
<li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a href="#tab-shared-general">General</a></li>

View File

@ -303,3 +303,10 @@ class LogForm(forms.ModelForm):
reason = forms.CharField(label="Reason for change",
widget=forms.widgets.Textarea(attrs={'rows':'2',
'cols': '65'}))
class PickForm(forms.Form):
picklist = forms.ChoiceField()
def __init__(self, label, item, order_by, *args, **kwargs):
super(PickForm, self).__init__(*args, **kwargs)
self.fields['picklist'].choices = \
[("", "---------")] + [(p.handle, p) for p in item.objects.all() \
.order_by(*order_by)]

View File

@ -532,7 +532,10 @@ class Citation(DateObject, PrimaryObject):
object_id_field="object_id")
def __unicode__(self):
return "Citation to " + str(self.source)
return "[%s] (%s, %s) to %s" % (self.gramps_id,
self.confidence,
self.page,
self.source)
# Other keys here:
# .datamap_set
@ -544,7 +547,8 @@ class Source(PrimaryObject):
abbrev = models.CharField("Abbreviation", max_length=50, blank=True, null=True)
def __unicode__(self):
return str(self.title)
return "[%s] %s" % (self.gramps_id,
self.title)
# Other keys here:
# .datamap_set
@ -558,7 +562,9 @@ class Event(DateObject, PrimaryObject):
object_id_field="object_id")
def __unicode__(self):
return str(self.description) or str(self.event_type)
return "[%s] (%s) %s" % (self.gramps_id,
self.event_type,
self.description)
class Repository(PrimaryObject):
repository_type = models.ForeignKey('RepositoryType', verbose_name="Type")
@ -570,7 +576,7 @@ class Repository(PrimaryObject):
#url_list = models.ManyToManyField('Url', null=True, blank=True)
def __unicode__(self):
return str(self.name)
return "[%s] %s" % (self.gramps_id, self.name)
# Others keys here:
# .address_set

View File

@ -22,7 +22,7 @@
""" Views for Person, Name, and Surname """
## Gramps Modules
from webapp.utils import _, boolean, update_last_changed
from webapp.utils import _, boolean, update_last_changed, build_search
from webapp.grampsdb.models import Citation
from webapp.grampsdb.forms import *
from webapp.libdjango import DjangoInterface
@ -48,8 +48,36 @@ def process_citation(request, context, handle, action, add_to=None): # view, edi
if request.POST.has_key("action"):
action = request.POST.get("action")
# Handle: edit, view, add, create, save, delete
if action == "add":
# Handle: edit, view, add, create, save, delete, share, save-share
if action == "share":
item, handle = add_to
context["pickform"] = PickForm("Pick citation",
Citation,
(),
request.POST)
context["object_handle"] = handle
context["object_type"] = item
return render_to_response("pick.html", context)
elif action == "save-share":
item, handle = add_to
pickform = PickForm("Pick citation",
Citation,
(),
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 = Citation.objects.get(handle=ref_handle)
dji.add_citation_ref_default(parent_obj, ref_obj)
dji.rebuild_cache(parent_obj) # rebuild cache
return redirect("/%s/%s%s#tab-citations" % (item, handle, build_search(request)))
else:
context["pickform"] = pickform
context["object_handle"] = handle
context["object_type"] = item
return render_to_response("pick.html", context)
elif action == "add":
source = Source(gramps_id=dji.get_next_id(Source, "S"))
sourceform = SourceForm(instance=source)
sourceform.model = source

View File

@ -22,7 +22,7 @@
""" Views for Person, Name, and Surname """
## Gramps Modules
from webapp.utils import _, boolean, update_last_changed
from webapp.utils import _, boolean, update_last_changed, build_search
from webapp.grampsdb.models import Event
from webapp.grampsdb.forms import *
from webapp.libdjango import DjangoInterface
@ -53,8 +53,36 @@ def process_event(request, context, handle, action, add_to=None): # view, edit,
if request.POST.has_key("action"):
action = request.POST.get("action")
# Handle: edit, view, add, create, save, delete
if action == "add":
# Handle: edit, view, add, create, save, delete, share, save-share
if action == "share":
item, handle = add_to
context["pickform"] = PickForm("Pick event",
Event,
(),
request.POST)
context["object_handle"] = handle
context["object_type"] = item
return render_to_response("pick.html", context)
elif action == "save-share":
item, handle = add_to
pickform = PickForm("Pick event",
Media,
(),
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)
dji.add_event_ref_default(parent_obj, ref_obj)
dji.rebuild_cache(parent_obj) # rebuild cache
return redirect("/%s/%s%s#tab-events" % (item, handle, build_search(request)))
else:
context["pickform"] = pickform
context["object_handle"] = handle
context["object_type"] = item
return render_to_response("pick.html", context)
elif action == "add":
event = Event(gramps_id=dji.get_next_id(Event, "E"))
eventform = EventForm(instance=event)
eventform.model = event

View File

@ -22,7 +22,7 @@
""" Views for Person, Name, and Surname """
## Gramps Modules
from webapp.utils import _, boolean, update_last_changed
from webapp.utils import _, boolean, update_last_changed, build_search
from webapp.grampsdb.models import Media
from webapp.grampsdb.forms import *
from webapp.libdjango import DjangoInterface
@ -61,8 +61,36 @@ def process_media(request, context, handle, action, add_to=None): # view, edit,
if request.POST.has_key("action"):
action = request.POST.get("action")
# Handle: edit, view, add, create, save, delete
if action == "full":
# Handle: edit, view, add, create, save, delete, share, save-share
if action == "share":
item, handle = add_to
context["pickform"] = PickForm("Pick media",
Media,
(),
request.POST)
context["object_handle"] = handle
context["object_type"] = item
return render_to_response("pick.html", context)
elif action == "save-share":
item, handle = add_to
pickform = PickForm("Pick media",
Media,
(),
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 = Media.objects.get(handle=ref_handle)
dji.add_media_ref_default(parent_obj, ref_obj)
dji.rebuild_cache(parent_obj) # rebuild cache
return redirect("/%s/%s%s#tab-media" % (item, handle, build_search(request)))
else:
context["pickform"] = pickform
context["object_handle"] = handle
context["object_type"] = item
return render_to_response("pick.html", context)
elif action == "full":
media = Media.objects.get(handle=handle)
media_type, media_ext = media.mime.split("/", 1)
# FIXME: This should be absolute:

View File

@ -22,7 +22,7 @@
""" Views for Person, Name, and Surname """
## Gramps Modules
from webapp.utils import _, boolean, update_last_changed, StyledNoteFormatter, parse_styled_text
from webapp.utils import _, boolean, update_last_changed, StyledNoteFormatter, parse_styled_text, build_search
from webapp.grampsdb.models import Note
from webapp.grampsdb.forms import *
from webapp.libdjango import DjangoInterface
@ -51,8 +51,36 @@ def process_note(request, context, handle, action, add_to=None): # view, edit, s
if request.POST.has_key("action"):
action = request.POST.get("action")
# Handle: edit, view, add, create, save, delete
if action == "add":
# Handle: edit, view, add, create, save, delete, share, save-share
if action == "share":
item, handle = add_to
context["pickform"] = PickForm("Pick note",
Note,
(),
request.POST)
context["object_handle"] = handle
context["object_type"] = item
return render_to_response("pick.html", context)
elif action == "save-share":
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)
dji.add_note_ref(parent_obj, ref_obj)
dji.rebuild_cache(parent_obj) # rebuild cache
return redirect("/%s/%s%s#tab-notes" % (item, handle, build_search(request)))
else:
context["pickform"] = pickform
context["object_handle"] = handle
context["object_type"] = item
return render_to_response("pick.html", context)
elif action == "add":
note = Note(gramps_id=dji.get_next_id(Note, "N"))
notetext = ""
noteform = NoteForm(instance=note, initial={"notetext": notetext})

View File

@ -346,7 +346,39 @@ def process_person(request, context, handle, action, add_to=None): # view, edit,
context["tviews"] = _("People")
logform = None
if request.user.is_authenticated():
if action in ["edit", "view"]:
if action == "share":
item, handle = add_to
context["pickform"] = PickForm("Pick a person",
Person,
("name__surname__surname",
"name__first_name"),
request.POST)
context["object_handle"] = handle
context["object_type"] = item
return render_to_response("pick.html", context)
elif action == "save-share":
item, handle = add_to # ("Family", handle)
pickform = PickForm("Pick a person",
Person,
("name__surname__surname",
"name__first_name"),
request.POST)
if pickform.data["picklist"]:
person_handle = pickform.data["picklist"]
person = Person.objects.get(handle=person_handle)
model = dji.get_model(item) # what model?
obj = model.objects.get(handle=handle) # get family
dji.add_child_ref_default(obj, person) # add person to family
person.parent_families.add(obj) # add family to child
dji.rebuild_cache(person) # rebuild child
dji.rebuild_cache(obj) # rebuild family
return redirect("/%s/%s%s" % (item, handle, build_search(request)))
else:
context["pickform"] = pickform
context["object_handle"] = handle
context["object_type"] = "family"
return render_to_response("pick.html", context)
elif action in ["edit", "view"]:
pf, nf, sf, person = get_person_forms(handle, empty=False)
if action == "edit":
logform = LogForm()

View File

@ -22,7 +22,7 @@
""" Views for Person, Name, and Surname """
## Gramps Modules
from webapp.utils import _, boolean, update_last_changed
from webapp.utils import _, boolean, update_last_changed, build_search
from webapp.grampsdb.models import Repository
from webapp.grampsdb.forms import *
from webapp.libdjango import DjangoInterface
@ -48,8 +48,36 @@ def process_repository(request, context, handle, action, add_to=None): # view, e
if request.POST.has_key("action"):
action = request.POST.get("action")
# Handle: edit, view, add, create, save, delete
if action == "add":
# Handle: edit, view, add, create, save, delete, share, save-share
if action == "share":
item, handle = add_to
context["pickform"] = PickForm("Pick repository",
Repository,
(),
request.POST)
context["object_handle"] = handle
context["object_type"] = item
return render_to_response("pick.html", context)
elif action == "save-share":
item, handle = add_to
pickform = PickForm("Pick repository",
Repository,
(),
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 = Repository.objects.get(handle=ref_handle)
dji.add_repository_ref_default(parent_obj, ref_obj)
dji.rebuild_cache(parent_obj) # rebuild cache
return redirect("/%s/%s%s#tab-repositories" % (item, handle, build_search(request)))
else:
context["pickform"] = pickform
context["object_handle"] = handle
context["object_type"] = item
return render_to_response("pick.html", context)
elif action == "add":
repository = Repository(gramps_id=dji.get_next_id(Repository, "R"))
repositoryform = RepositoryForm(instance=repository)
repositoryform.model = repository
@ -80,7 +108,7 @@ def process_repository(request, context, handle, action, add_to=None): # view, e
item, handle = add_to
model = dji.get_model(item)
obj = model.objects.get(handle=handle)
dji.add_repository_ref(obj, repository)
dji.add_repository_ref_default(obj, repository)
dji.rebuild_cache(obj)
return redirect("/%s/%s#tab-repositories" % (item, handle))
action = "view"

View File

@ -22,7 +22,7 @@
""" Views for Person, Name, and Surname """
## Gramps Modules
from webapp.utils import _, boolean, update_last_changed
from webapp.utils import _, boolean, update_last_changed, build_search
from webapp.grampsdb.models import Source
from webapp.grampsdb.forms import *
from webapp.libdjango import DjangoInterface
@ -48,8 +48,36 @@ def process_source(request, context, handle, action, add_to=None): # view, edit,
if request.POST.has_key("action"):
action = request.POST.get("action")
# Handle: edit, view, add, create, save, delete
if action == "add":
# Handle: edit, view, add, create, save, delete, share, save-share
if action == "share":
item, handle = add_to
context["pickform"] = PickForm("Pick source",
Source,
(),
request.POST)
context["object_handle"] = handle
context["object_type"] = item
return render_to_response("pick.html", context)
elif action == "save-share":
item, handle = add_to
pickform = PickForm("Pick source",
Source,
(),
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 = Source.objects.get(handle=ref_handle)
dji.add_source_ref_default(parent_obj, ref_obj)
dji.rebuild_cache(parent_obj) # rebuild cache
return redirect("/%s/%s%s#tab-sources" % (item, handle, build_search(request)))
else:
context["pickform"] = pickform
context["object_handle"] = handle
context["object_type"] = item
return render_to_response("pick.html", context)
elif action == "add":
source = Source(gramps_id=dji.get_next_id(Source, "S"))
sourceform = SourceForm(instance=source)
sourceform.model = source

View File

@ -399,7 +399,7 @@ def view_list(request, view):
context["search_query"] = ""
return render_to_response(view_template, context)
def check_access(request, context, obj, action):
def check_access(request, context, obj, act):
"""
Check to see if user has access to object. We don't need to
sanitize here, just check to see if we even acknowledge it exists.
@ -408,16 +408,21 @@ def check_access(request, context, obj, action):
if request.user.is_superuser:
return True
else:
return action in ["view"]
return act in ["view"]
else: # outside viewer
return not obj.private
def add_share(request, view, item, handle):
"""
Add a reference to an existing <view> referenced from <item>.
Add a new <view> referenced from <item>.
"""
# /view/share/person/handle
raise Http404(_('Not implemented yet.'))
# /person/share/family/handle
# Use an existing person with this family
# r'^(?P<view>(\w+))/share/(?P<item>(\w+))/(?P<handle>(\w+))$',
act = "share"
if request.POST.has_key("action"):
act = request.POST.get("action") # can be "save-share"
return action(request, view, None, act, (item, handle))
def add_to(request, view, item, handle):
"""
@ -426,7 +431,7 @@ def add_to(request, view, item, handle):
# /view/add/person/handle
return action(request, view, None, "add", (item, handle))
def action(request, view, handle, action, add_to=None):
def action(request, view, handle, act, add_to=None):
"""
View a particular object given /object/handle (implied view),
/object/handle/action, or /object/add.
@ -436,100 +441,100 @@ def action(request, view, handle, action, add_to=None):
obj = None
context = RequestContext(request)
if request.POST.has_key("action"):
action = request.POST.get("action")
context["action"] = action
act = request.POST.get("action")
context["action"] = act
context["view"] = view
context["tview"] = _('Browse')
if view == "event":
if action not in ["add", "create"]:
if act not in ["add", "create", "share", "save-share"]:
try:
obj = Event.objects.get(handle=handle)
except:
raise Http404(_("Requested %s does not exist.") % view)
if not check_access(request, context, obj, action):
if not check_access(request, context, obj, act):
raise Http404(_("Requested %s does not exist.") % view)
view_template = 'view_event_detail.html'
rd = process_event(request, context, handle, action, add_to)
rd = process_event(request, context, handle, act, add_to)
elif view == "family":
if action not in ["add", "create"]:
if act not in ["add", "create", "share", "save-share"]:
try:
obj = Family.objects.get(handle=handle)
except:
raise Http404(_("Requested %s does not exist.") % view)
view_template = 'view_family_detail.html'
rd = process_family(request, context, handle, action, add_to)
rd = process_family(request, context, handle, act, add_to)
elif view == "media":
if action not in ["add", "create"]:
if act not in ["add", "create", "share", "save-share"]:
try:
obj = Media.objects.get(handle=handle)
except:
raise Http404(_("Requested %s does not exist.") % view)
view_template = 'view_media_detail.html'
rd = process_media(request, context, handle, action, add_to)
rd = process_media(request, context, handle, act, add_to)
elif view == "note":
if action not in ["add", "create"]:
if act not in ["add", "create", "share", "save-share"]:
try:
obj = Note.objects.get(handle=handle)
except:
raise Http404(_("Requested %s does not exist.") % view)
view_template = 'view_note_detail.html'
rd = process_note(request, context, handle, action, add_to)
rd = process_note(request, context, handle, act, add_to)
elif view == "person":
if action not in ["add", "create"]:
if act not in ["add", "create", "share", "save-share"]:
try:
obj = Person.objects.get(handle=handle)
except:
raise Http404(_("Requested %s does not exist.") % view)
view_template = 'view_person_detail.html'
rd = process_person(request, context, handle, action, add_to)
rd = process_person(request, context, handle, act, add_to)
elif view == "place":
if action not in ["add", "create"]:
if act not in ["add", "create", "share", "save-share"]:
try:
obj = Place.objects.get(handle=handle)
except:
raise Http404(_("Requested %s does not exist.") % view)
view_template = 'view_place_detail.html'
rd = process_place(request, context, handle, action, add_to)
rd = process_place(request, context, handle, act, add_to)
elif view == "repository":
if action not in ["add", "create"]:
if act not in ["add", "create", "share", "save-share"]:
try:
obj = Repository.objects.get(handle=handle)
except:
raise Http404(_("Requested %s does not exist.") % view)
view_template = 'view_repository_detail.html'
rd = process_repository(request, context, handle, action, add_to)
rd = process_repository(request, context, handle, act, add_to)
elif view == "citation":
if action not in ["add", "create"]:
if act not in ["add", "create", "share", "save-share"]:
try:
obj = Citation.objects.get(handle=handle)
except:
raise Http404(_("Requested %s does not exist.") % view)
view_template = 'view_citation_detail.html'
rd = process_citation(request, context, handle, action, add_to)
rd = process_citation(request, context, handle, act, add_to)
elif view == "source":
if action not in ["add", "create"]:
if act not in ["add", "create", "share", "save-share"]:
try:
obj = Source.objects.get(handle=handle)
except:
raise Http404(_("Requested %s does not exist.") % view)
view_template = 'view_source_detail.html'
rd = process_source(request, context, handle, action, add_to)
rd = process_source(request, context, handle, act, add_to)
elif view == "tag":
if action not in ["add", "create"]:
if act not in ["add", "create", "share", "save-share"]:
try:
obj = Tag.objects.get(handle=handle)
except:
raise Http404(_("Requested %s does not exist.") % view)
view_template = 'view_tag_detail.html'
rd = process_tag(request, context, handle, action, add_to)
rd = process_tag(request, context, handle, act, add_to)
elif view == "report":
if action not in ["add", "create"]:
if act not in ["add", "create", "share", "save-share"]:
try:
obj = Report.objects.get(handle=handle)
except:
raise Http404(_("Requested %s does not exist.") % view)
view_template = 'view_report_detail.html'
rd = process_report(request, context, handle, action)
rd = process_report(request, context, handle, act)
else:
raise Http404(_("Requested page type not known"))
if rd:
@ -540,11 +545,11 @@ def action(request, view, handle, action, add_to=None):
context["next"] = "/%s/%s" % (view, obj.handle)
return render_to_response(view_template, context)
def process_report(request, context, handle, action):
def process_report(request, context, handle, act):
"""
Process action on report. Can return a redirect.
"""
if action == "run":
if act == "run":
return process_report_run(request, handle)
context["tview"] = _("Report")
context["tviews"] = _("Reports")

View File

@ -829,6 +829,15 @@ class DjangoInterface(object):
self.add_attribute_list(media_ref, attribute_list)
self.add_citation_list(media_ref, citation_list)
def add_citation_ref_default(self, obj, citation, private=False):
object_type = ContentType.objects.get_for_model(obj)
count = models.CitationRef.objects.filter(object_id=obj.id,object_type=object_type).count()
citation_ref = models.CitationRef(private=private,
referenced_by=obj,
citation=citation,
order=count + 1)
citation_ref.save()
def add_citation_ref(self, obj, handle):
try:
citation = models.Citation.objects.get(handle=handle)
@ -939,6 +948,19 @@ class DjangoInterface(object):
self.add_note_list(event_ref, note_list)
self.add_attribute_list(event_ref, attribute_list)
def add_repository_ref_default(self, obj, repository, private=False, call_number="",
source_media_type=models.SourceMediaType._DEFAULT):
object_type = ContentType.objects.get_for_model(obj)
count = models.RepositoryRef.objects.filter(object_id=obj.id,object_type=object_type).count()
repos_ref = models.RepositoryRef(private=private,
referenced_by=obj,
call_number=call_number,
source_media_type=models.get_type(models.SourceMediaType,
source_media_type),
ref_object=repository,
order=count + 1)
repos_ref.save()
def add_repository_ref(self, obj, reporef_data):
(note_list,
ref,

View File

@ -70,24 +70,24 @@ urlpatterns += patterns('',
(r'^logout/$', logout_page),
(r'^(?P<view>(\w+))/$', view_list), # /view/
(r'^(?P<view>(\w+))/add$', action,
{"handle": None, "action": "add"}), # /view/add
{"handle": None, "act": "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+))$',
{"act": "view"}), # /view/handle/
(r'^(?P<view>(\w+))/(?P<handle>(\w+))/(?P<act>(\w+))$',
action), # /view/handle/action
(r'^(?P<ref_by>(\w+))/(?P<handle>(\w+))/reference/(?P<ref_to>(\w+))/(?P<order>(\w+))$',
process_reference), # /view/handle/reference/item/order
(r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))$', process_name),
(r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))/(?P<action>(\w+))$',
(r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))/(?P<act>(\w+))$',
process_name),
(r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))/surname/(?P<sorder>(\w+))$',
process_surname),
(r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))/surname/(?P<sorder>(\w+))/(?P<action>(\w+))$',
(r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))/surname/(?P<sorder>(\w+))/(?P<act>(\w+))$',
process_surname),
)

View File

@ -84,7 +84,6 @@ util_tags = [
"name_table",
"surname_table",
"citation_table",
"source_table",
"note_table",
"attribute_table",
"data_table",
@ -312,7 +311,7 @@ def event_table(obj, user, action, url, args):
event_list = [(obj.ref_object, obj) for obj in event_ref_list]
for (djevent, event_ref) in event_list:
table.row(
event_ref,
djevent.description,
table.db.get_event_from_handle(djevent.handle),
djevent.gramps_id,
display_date(djevent),
@ -320,8 +319,8 @@ def event_table(obj, user, action, url, args):
str(event_ref.role_type))
retval += table.get_html()
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"))
retval += make_button(_("Add New Event"), (url % args).replace("$act", "add"))
retval += make_button(_("Add Existing Event"), (url % args).replace("$act", "share"))
else:
retval += nbsp("") # to keep tabs same height
return retval
@ -412,34 +411,6 @@ def surname_table(obj, user, action, url=None, *args):
retval += nbsp("") # to keep tabs same height
return retval
def source_table(obj, user, action, url=None, *args):
retval = ""
table = Table("source_table")
table.columns(_("ID"),
_("Title"),
_("Author"),
_("Page"))
if user.is_authenticated():
obj_type = ContentType.objects.get_for_model(obj)
citation_refs = dji.CitationRef.filter(object_type=obj_type,
object_id=obj.id)
for citation_ref in citation_refs:
if citation_ref.citation:
if citation_ref.citation.source:
source = citation_ref.citation.source
table.row(source,
source.title,
source.author,
citation_ref.citation.page,
)
retval += table.get_html()
if user.is_superuser and url and action == "view":
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
def citation_table(obj, user, action, url=None, *args):
retval = ""
table = Table("citation_table")
@ -460,8 +431,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).replace("$act", "add"))
retval += make_button(_("Share Citation"), (url % args).replace("$act", "share"))
retval += make_button(_("Add New Citation"), (url % args).replace("$act", "add"))
retval += make_button(_("Add Existing Citation"), (url % args).replace("$act", "share"))
else:
retval += nbsp("") # to keep tabs same height
return retval
@ -477,8 +448,8 @@ def repository_table(obj, user, action, url=None, *args):
pass
retval += table.get_html()
if user.is_superuser and url and action == "view":
retval += make_button(_("Add Repository"), (url % args).replace("$act", "add"))
retval += make_button(_("Share Repository"), (url % args).replace("$act", "share"))
retval += make_button(_("Add New Repository"), (url % args).replace("$act", "add"))
retval += make_button(_("Add Existing Repository"), (url % args).replace("$act", "share"))
else:
retval += nbsp("") # to keep tabs same height
return retval
@ -502,8 +473,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).replace("$act", "add"))
retval += make_button(_("Share Note"), (url % args).replace("$act", "share"))
retval += make_button(_("Add New Note"), (url % args).replace("$act", "add"))
retval += make_button(_("Add Existing Note"), (url % args).replace("$act", "share"))
else:
retval += nbsp("") # to keep tabs same height
return retval
@ -589,6 +560,7 @@ def media_table(obj, user, action, url=None, *args):
table = Table("media_table")
table.columns(_("Description"),
_("Type"),
_("Path/Filename"),
)
if user.is_authenticated():
obj_type = ContentType.objects.get_for_model(obj)
@ -602,8 +574,8 @@ def media_table(obj, user, action, url=None, *args):
media_ref.ref_object.path)
retval += table.get_html()
if user.is_superuser and url and action == "view":
retval += make_button(_("Add Media"), (url % args).replace("$act", "add"))
retval += make_button(_("Share Media"), (url % args).replace("$act", "share"))
retval += make_button(_("Add New Media"), (url % args).replace("$act", "add"))
retval += make_button(_("Add Existing Media"), (url % args).replace("$act", "share"))
else:
retval += nbsp("") # to keep tabs same height
return retval
@ -895,8 +867,8 @@ def children_table(obj, user, action, url=None, *args):
table.links(links)
retval += table.get_html()
if user.is_superuser and url and action == "view":
retval += make_button(_("Add Child"), (url.replace("$act", "add") % args))
retval += make_button(_("Share Child"), (url.replace("$act", "share") % args))
retval += make_button(_("Add New Person as Child"), (url.replace("$act", "add") % args))
retval += make_button(_("Add Existing Person as Child"), (url.replace("$act", "share") % args))
else:
retval += nbsp("") # to keep tabs same height
return retval