Working on editing references; fixed an error in ordering of references
svn: r19704
This commit is contained in:
parent
ee794b5077
commit
38b50049f2
35
src/data/templates/reference.html
Normal file
35
src/data/templates/reference.html
Normal file
@ -0,0 +1,35 @@
|
||||
{% extends "view_page_detail.html" %}
|
||||
{% load my_tags %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="content" id="IndividualDetail">
|
||||
|
||||
{% include "detail_breadcrumb.html" %}
|
||||
<h2>Reference Detail</h2>
|
||||
<div id="summaryarea">
|
||||
<table class="infolist" style="width:90%;">
|
||||
<trbody>
|
||||
{% if form.errors %}
|
||||
<hr>
|
||||
<p id="error">The following fields have errors. Please correct and try again.</p>
|
||||
<div id="error">{{form.errors}}</div>
|
||||
<hr>
|
||||
{% endif %}
|
||||
<form method="post">{% csrf_token %}
|
||||
|
||||
{% for field in form %}
|
||||
|
||||
<tr>
|
||||
{{field}}
|
||||
</tr>
|
||||
|
||||
{% endfor %}
|
||||
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
@ -272,3 +272,7 @@ class TagForm(forms.ModelForm):
|
||||
required=False,
|
||||
widget=TextInput(attrs={'size':'70'}))
|
||||
|
||||
class EventRefForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = EventRef
|
||||
|
||||
|
@ -818,6 +818,13 @@ class EventRef(BaseRef):
|
||||
def __unicode__(self):
|
||||
return "EventRef to " + 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()
|
||||
return "/%s/%s/reference/%s/%s" % (ref_by.__class__.__name__.lower(),
|
||||
ref_by.handle, ref_to, self.order)
|
||||
|
||||
class RepositoryRef(BaseRef):
|
||||
ref_object = models.ForeignKey('Repository')
|
||||
source_media_type = models.ForeignKey('SourceMediaType')
|
||||
|
@ -26,6 +26,7 @@ from webapp.utils import _, boolean, update_last_changed
|
||||
from webapp.grampsdb.models import Event
|
||||
from webapp.grampsdb.forms import *
|
||||
from webapp.libdjango import DjangoInterface
|
||||
from webapp.dbdjango import DbDjango
|
||||
from gen.datehandler import displayer, parser
|
||||
|
||||
## Django Modules
|
||||
@ -34,6 +35,7 @@ from django.template import Context, RequestContext
|
||||
|
||||
## Globals
|
||||
dji = DjangoInterface()
|
||||
db = DbDjango()
|
||||
dd = displayer.display
|
||||
dp = parser.parse
|
||||
|
||||
@ -58,6 +60,10 @@ def process_event(request, context, handle, action, add_to=None): # view, edit,
|
||||
eventform.model = event
|
||||
elif action in ["view", "edit"]:
|
||||
event = Event.objects.get(handle=handle)
|
||||
genlibevent = db.get_event_from_handle(handle)
|
||||
if genlibevent:
|
||||
date = genlibevent.get_date_object()
|
||||
event.text = dd(date)
|
||||
eventform = EventForm(instance=event)
|
||||
eventform.model = event
|
||||
elif action == "save":
|
||||
|
@ -46,6 +46,7 @@ from django.http import Http404, HttpResponseRedirect, HttpResponse
|
||||
from django.shortcuts import get_object_or_404, render_to_response, redirect
|
||||
from django.template import Context, RequestContext
|
||||
from django.db.models import Q
|
||||
from django.forms.models import modelformset_factory
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
@ -698,3 +699,25 @@ def build_person_query(search, protect):
|
||||
if protect:
|
||||
query &= (Q(private=False) & Q(person__private=False))
|
||||
return query
|
||||
|
||||
|
||||
|
||||
def process_reference(request, ref_by, handle, ref_to, order):
|
||||
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())
|
||||
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.model = referenced_to[0]
|
||||
context["form"] = form
|
||||
context["view"] = 'Reference'
|
||||
context["tview"] = _('Reference')
|
||||
context["tviews"] = _('References')
|
||||
context["object"] = referenced_by
|
||||
context["handle"] = referenced_by.handle
|
||||
context["action"] = "view"
|
||||
return render_to_response("reference.html", context)
|
||||
|
@ -161,10 +161,12 @@ class DjangoInterface(object):
|
||||
return "%s%04d" % (prefix, count)
|
||||
|
||||
def get_model(self, name):
|
||||
if hasattr(models, name.title()):
|
||||
if hasattr(models, name):
|
||||
return getattr(models, name)
|
||||
elif hasattr(models, name.title()):
|
||||
return getattr(models, name.title())
|
||||
else:
|
||||
raise AttributeError("no such model: '%s'" % name.title())
|
||||
raise AttributeError("no such model: '%s'" % name)
|
||||
|
||||
# -----------------------------------------------
|
||||
# Get methods to retrieve list data from the tables
|
||||
@ -827,7 +829,8 @@ class DjangoInterface(object):
|
||||
handle)
|
||||
return
|
||||
|
||||
count = models.CitationRef.objects.filter(object_id=obj.id,object_type=obj).count()
|
||||
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=False,
|
||||
referenced_by=obj,
|
||||
citation=citation,
|
||||
@ -876,7 +879,8 @@ class DjangoInterface(object):
|
||||
print >> sys.stderr, ("ERROR: Person does not exist: '%s'" %
|
||||
ref)
|
||||
return
|
||||
count = models.ChildRef.objects.filter(object_id=obj.id,object_type=obj).count()
|
||||
object_type = ContentType.objects.get_for_model(obj)
|
||||
count = models.ChildRef.objects.filter(object_id=obj.id,object_type=object_type).count()
|
||||
child_ref = models.ChildRef(private=private,
|
||||
referenced_by=obj,
|
||||
ref_object=child,
|
||||
@ -888,7 +892,8 @@ class DjangoInterface(object):
|
||||
self.add_note_list(child_ref, note_list)
|
||||
|
||||
def add_event_ref_default(self, obj, event, private=False, role=models.EventRoleType._DEFAULT):
|
||||
count = models.EventRef.objects.filter(object_id=obj.id,object_type=obj).count()
|
||||
object_type = ContentType.objects.get_for_model(obj)
|
||||
count = models.EventRef.objects.filter(object_id=obj.id,object_type=object_type).count()
|
||||
event_ref = models.EventRef(private=private,
|
||||
referenced_by=obj,
|
||||
ref_object=event,
|
||||
@ -904,7 +909,8 @@ class DjangoInterface(object):
|
||||
print >> sys.stderr, ("ERROR: Event does not exist: '%s'" %
|
||||
ref)
|
||||
return
|
||||
count = models.EventRef.objects.filter(object_id=obj.id,object_type=obj).count()
|
||||
object_type = ContentType.objects.get_for_model(obj)
|
||||
count = models.EventRef.objects.filter(object_id=obj.id,object_type=object_type).count()
|
||||
event_ref = models.EventRef(private=private,
|
||||
referenced_by=obj,
|
||||
ref_object=event,
|
||||
@ -926,7 +932,8 @@ class DjangoInterface(object):
|
||||
print >> sys.stderr, ("ERROR: Repository does not exist: '%s'" %
|
||||
ref)
|
||||
return
|
||||
count = models.RepositoryRef.objects.filter(object_id=obj.id,object_type=obj).count()
|
||||
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,
|
||||
@ -1227,7 +1234,7 @@ class DjangoInterface(object):
|
||||
events = models.EventRef.objects.filter(
|
||||
object_id=person.id,
|
||||
object_type=obj_type,
|
||||
ref_object__event_type__val=models.EventType.BIRTH)
|
||||
ref_object__event_type__val=models.EventType.BIRTH).order_by("order")
|
||||
|
||||
all_events = self.get_event_ref_list(person)
|
||||
if events:
|
||||
@ -1237,7 +1244,7 @@ class DjangoInterface(object):
|
||||
events = models.EventRef.objects.filter(
|
||||
object_id=person.id,
|
||||
object_type=obj_type,
|
||||
ref_object__event_type__val=models.EventType.DEATH)
|
||||
ref_object__event_type__val=models.EventType.DEATH).order_by("order")
|
||||
if events:
|
||||
person.death = events[0].ref_object
|
||||
person.death_ref_index = lookup_role_index(models.EventType.DEATH, all_events)
|
||||
|
@ -18,6 +18,7 @@ from webapp.dbdjango import DbDjango
|
||||
from webapp.reports import import_file
|
||||
from webapp.libdjango import DjangoInterface, totime, todate
|
||||
from gen.datehandler import displayer, parser
|
||||
from webapp.utils import StyledNoteFormatter, parse_styled_text
|
||||
import gen.lib
|
||||
import cli.user
|
||||
|
||||
@ -30,16 +31,15 @@ dp = parser.parse
|
||||
# "/home/dblank/gramps/trunk/example/gramps/data.gramps",
|
||||
# cli.user.User())
|
||||
|
||||
from webapp.utils import StyledNoteFormatter, parse_styled_text
|
||||
snf = StyledNoteFormatter(db)
|
||||
#snf = StyledNoteFormatter(db)
|
||||
#for n in Note.objects.all():
|
||||
# note = db.get_note_from_handle(n.handle)
|
||||
# print snf.format(note)
|
||||
|
||||
note = Note.objects.get(handle="aef30789d3d2090abe2")
|
||||
genlibnote = db.get_note_from_handle(note.handle)
|
||||
html_text = snf.format(genlibnote)
|
||||
# FIXME: this looks wrong:
|
||||
#note = Note.objects.get(handle="aef30789d3d2090abe2")
|
||||
#genlibnote = db.get_note_from_handle(note.handle)
|
||||
#html_text = snf.format(genlibnote)
|
||||
## FIXME: this looks wrong:
|
||||
#print html_text
|
||||
#print parse_styled_text(html_text)
|
||||
|
||||
|
@ -77,10 +77,16 @@ urlpatterns += patterns('',
|
||||
{"action": "view"}), # /view/handle/
|
||||
(r'^(?P<view>(\w+))/(?P<handle>(\w+))/(?P<action>(\w+))$',
|
||||
action), # /view/handle/action
|
||||
(r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))$', process_name),
|
||||
(r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))/(?P<action>(\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+))$', process_surname),
|
||||
(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+))$',
|
||||
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+))$',
|
||||
process_surname),
|
||||
)
|
||||
|
||||
# In urls:
|
||||
|
@ -213,8 +213,6 @@ class Table(object):
|
||||
# We have a couple of HTML bits that we want to unescape:
|
||||
return str(self.doc.doc.htmllist[0]).replace("&nbsp;", " ")
|
||||
|
||||
_ = lambda text: text
|
||||
|
||||
def make_button(text, url, *args):
|
||||
url = url % args
|
||||
#return """[ <a href="%s">%s</a> ] """ % (url, text)
|
||||
@ -223,12 +221,14 @@ def make_button(text, url, *args):
|
||||
def event_table(obj, user, action, url=None, *args):
|
||||
retval = ""
|
||||
table = Table()
|
||||
table.columns(_("Description"),
|
||||
_("Type"),
|
||||
_("ID"),
|
||||
_("Date"),
|
||||
_("Place"),
|
||||
_("Role"))
|
||||
table.columns(
|
||||
_("Event Reference"),
|
||||
_("Description"),
|
||||
_("Type"),
|
||||
_("ID"),
|
||||
_("Date"),
|
||||
_("Place"),
|
||||
_("Role"))
|
||||
if user.is_authenticated():
|
||||
obj_type = ContentType.objects.get_for_model(obj)
|
||||
event_ref_list = models.EventRef.objects.filter(
|
||||
@ -237,6 +237,7 @@ def event_table(obj, user, action, url=None, *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 or str(djevent),
|
||||
table.db.get_event_from_handle(djevent.handle),
|
||||
djevent.gramps_id,
|
||||
|
Loading…
Reference in New Issue
Block a user