Editing of Person, Family, and Event main data complete
svn: r19652
This commit is contained in:
parent
355bbd6d7b
commit
c0eaa76d68
@ -17,27 +17,30 @@
|
||||
<div id="summaryarea">
|
||||
<table class="infolist" style="width:90%;">
|
||||
<trbody>
|
||||
{% if eventform.errors %}
|
||||
<hr>
|
||||
<p id="error">The following fields have errors. Please correct and try again.</p>
|
||||
<div id="error">{{eventform.errors}}</div>
|
||||
<hr>
|
||||
{% endif %}
|
||||
<form method="post">{% csrf_token %}
|
||||
<tr>
|
||||
<td class="ColumnAttribute">Event type:</td>
|
||||
<td class="ColumnValue" id="data"> {{event.event_type|escape}}</td>
|
||||
<td class="ColumnAttribute">{{eventform.event_type.label}}:</td>
|
||||
<td class="ColumnValue" id="data"> {% render eventform.event_type user action %}</td>
|
||||
<td class="ColumnAttribute">Date:</td>
|
||||
<td class="ColumnValue" id="data">{{event|display_date}}</td>
|
||||
<td class="ColumnValue" id="data">{% render eventform.date user action %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="ColumnAttribute">Description:</td>
|
||||
{% if user.is_authenticated %}
|
||||
<td class="ColumnValue" id="data" colspan="3">{{event.description|escape}}</td>
|
||||
{% else %}
|
||||
<td class="ColumnValue" id="data" colspan="3">[Private]</td>
|
||||
{% endif %}
|
||||
<td class="ColumnValue" id="data" colspan="3">{% render eventform.description user action %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="ColumnAttribute">ID:</td>
|
||||
<td class="ColumnValue" id="data" colspan="3">{{event.gramps_id|escape}}</td>
|
||||
<td class="ColumnValue" id="data" colspan="3">{% render eventform.gramps_id user action %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="ColumnAttribute">Place:</td>
|
||||
<td class="ColumnValue" id="data" colspan="3">{{event.place.title|escape}} [{{event.place.gramps_id}}]</td>
|
||||
<td class="ColumnValue" id="data" colspan="3">{% render eventform.place user action %}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
@ -64,6 +67,25 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
{% if user.is_superuser %}
|
||||
{% if action == "edit" %}
|
||||
{% make_button "Back to Event" "/event/%s" event.handle %}
|
||||
<input type="hidden" name="action" value="save"/>
|
||||
<input type="submit" value="Save"/>
|
||||
{% else %}
|
||||
{% ifequal action "add" %}
|
||||
{% make_button "Cancel" "/event/" %}
|
||||
<input type="hidden" name="action" value="create"/>
|
||||
<input type="submit" value="Create"/>
|
||||
{% else %}
|
||||
{% make_button "Back to Families" "/event" %}
|
||||
{% make_button "Add Event" "/event/add" %}
|
||||
{% make_button "Edit Event" "/event/%s/edit" event.handle %}
|
||||
{% make_button "Delete Event" "/event/%s/delete" event.handle %}
|
||||
{% endifequal %}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{% endif %}
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
<td><a href="/{{view}}/{{event.handle|escape}}">{{event.event_type|nbsp}}</a>
|
||||
<td><a href="/{{view}}/{{event.handle|escape}}">{{event.description|nbsp}}</a>
|
||||
<td><a href="/{{view}}/{{event.handle|escape}}">{{event|render_date:user}}</a>
|
||||
<td><a href="/{{view}}/{{event.handle|escape}}">{{event|date_as_text:user}}</a>
|
||||
<td><a href="/{{view}}/{{event.handle|escape}}">{{event.place.title|nbsp}}</a>
|
||||
|
||||
{% else %}
|
||||
|
@ -19,9 +19,12 @@
|
||||
<div id="summaryarea">
|
||||
<table class="infolist" style="width:90%;"> {% comment %} 4 cols {% endcomment %}
|
||||
<tbody>
|
||||
{% for error in familyform.errors %}
|
||||
<p id="error">Error in family: {{error}}</p>
|
||||
{% endfor %}
|
||||
{% if familyform.errors %}
|
||||
<hr>
|
||||
<p id="error">The following fields have errors. Please correct and try again.</p>
|
||||
<div id="error">{{familyform.errors}}</div>
|
||||
<hr>
|
||||
{% endif %}
|
||||
<form method="post">{% csrf_token %}
|
||||
<tr>
|
||||
<th colspan="2">Father</th>
|
||||
@ -36,23 +39,23 @@
|
||||
{% if user.is_authenticated or not familyform.father.probably_alive %}
|
||||
<tr>
|
||||
<td class="ColumnAttribute">Birth:</td>
|
||||
<td class="ColumnValue" id="data">{{familyform.father.birth|render_date:user}}</td>
|
||||
<td class="ColumnValue" id="data">{{familyform.father.birth|date_as_text:user}}</td>
|
||||
<td class="ColumnAttribute">Birth:</td>
|
||||
<td class="ColumnValue" id="data">{{familyform.mother.birth|render_date:user}}</td>
|
||||
<td class="ColumnValue" id="data">{{familyform.mother.birth|date_as_text:user}}</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr>
|
||||
<td class="ColumnAttribute">Death:</td>
|
||||
<td class="ColumnValue" id="data">{{familyform.father.death|render_date:user}}</td>
|
||||
<td class="ColumnValue" id="data">{{familyform.father.death|date_as_text:user}}</td>
|
||||
<td class="ColumnAttribute">Death:</td>
|
||||
<td class="ColumnValue" id="data">{{familyform.mother.death|render_date:user}}</td>
|
||||
<td class="ColumnValue" id="data">{{familyform.mother.death|date_as_text:user}}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<tr>
|
||||
<td class="ColumnAttribute">Death:</td>
|
||||
<td class="ColumnValue" id="data">{{familyform.father.death|render_date:user}}</td>
|
||||
<td class="ColumnValue" id="data">{{familyform.father.death|date_as_text:user}}</td>
|
||||
<td class="ColumnAttribute">Death:</td>
|
||||
<td class="ColumnValue" id="data">{{familyform.mother.death|render_date:user}}</td>
|
||||
<td class="ColumnValue" id="data">{{familyform.mother.death|date_as_text:user}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
@ -24,8 +24,8 @@
|
||||
</td>
|
||||
<td><a href="{{name.person.handle}}/" class="grampsid">[{{name.person.gramps_id}}]</a></td>
|
||||
<td><a href="{{name.person.handle}}/" class="noThumb">{{name.person.gender_type}}</a></td>
|
||||
<td><a href="{{name.person.handle}}/" class="noThumb">{{name.person.birth|render_date:user}}</a></td>
|
||||
<td><a href="{{name.person.handle}}/" class="noThumb">{{name.person.death|render_date:user}}</a></td>
|
||||
<td><a href="{{name.person.handle}}/" class="noThumb">{{name.person.birth|date_as_text:user}}</a></td>
|
||||
<td><a href="{{name.person.handle}}/" class="noThumb">{{name.person.death|date_as_text:user}}</a></td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
@ -17,15 +17,16 @@
|
||||
<div id="summaryarea">
|
||||
<table class="infolist" style="width:90%;"> {% comment %} 5 cols {% endcomment %}
|
||||
<tbody>
|
||||
{% for error in personform.errors %}
|
||||
<p id="error">Error in person: {{error}}</p>
|
||||
{% endfor %}
|
||||
{% for error in nameform.errors %}
|
||||
<p id="error">Error in name: {{error}}</p>
|
||||
{% endfor %}
|
||||
{% for error in surnameform.errors %}
|
||||
<p id="error">Error in surname: {{error}}</p>
|
||||
{% endfor %}
|
||||
{% if personform.errors or nameform.errors or surnameform.errors %}
|
||||
<hr>
|
||||
<p id="error">The following fields have errors. Please correct and try again.</p>
|
||||
<div id="error">
|
||||
{{personform.errors}}
|
||||
{{nameform.errors}}
|
||||
{{surnameform.errors}}
|
||||
</div>
|
||||
<hr>
|
||||
{% endif %}
|
||||
<form method="post">{% csrf_token %}
|
||||
<tr>
|
||||
<td colspan="4" id="subtitle">{{nameform|render_name:user}}</td>
|
||||
|
@ -126,3 +126,51 @@ class FamilyForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Family
|
||||
exclude = ["handle"]
|
||||
|
||||
class EventForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Event
|
||||
exclude = ["handle", "sortval", "month1", "year1", "day1",
|
||||
"newyear", "calendar", "modifier", "quality"]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
from webapp.utils import display_date
|
||||
super(EventForm, self).__init__(*args, **kwargs)
|
||||
|
||||
# Set the form fields based on the model object
|
||||
if kwargs.has_key('instance'):
|
||||
instance = kwargs['instance']
|
||||
sdate = display_date(instance)
|
||||
if sdate != "0000-00-00":
|
||||
self.initial['date'] = sdate
|
||||
try:
|
||||
self.data['date'] = self.initial['date']
|
||||
except:
|
||||
pass
|
||||
|
||||
def clean(self):
|
||||
from webapp.utils import dp
|
||||
data = super(EventForm, self).clean()
|
||||
dobj = dp(data.get('date'))
|
||||
if not dobj.is_valid():
|
||||
msg = u"Invalid date format"
|
||||
self._errors["date"] = self.error_class([msg])
|
||||
del data["date"]
|
||||
else:
|
||||
data["date"] = str(dobj)
|
||||
return data
|
||||
|
||||
def save(self, commit=True):
|
||||
from webapp.utils import dp
|
||||
from webapp.libdjango import DjangoInterface
|
||||
dji = DjangoInterface()
|
||||
model = super(EventForm, self).save(commit=False)
|
||||
dobj = dp(self.cleaned_data['date'])
|
||||
dji.add_date(model, dobj.serialize())
|
||||
if commit:
|
||||
model.save()
|
||||
return model
|
||||
|
||||
date = forms.CharField(label="Date",
|
||||
required=False,
|
||||
widget=TextInput(attrs={'size':'30'}))
|
||||
|
@ -517,7 +517,7 @@ class Source(PrimaryObject):
|
||||
class Event(DateObject, PrimaryObject):
|
||||
event_type = models.ForeignKey('EventType')
|
||||
description = models.CharField('description', max_length=50, blank=True)
|
||||
place = models.ForeignKey('Place', null=True)
|
||||
place = models.ForeignKey('Place', null=True, blank=True)
|
||||
references = generic.GenericRelation('EventRef', related_name="refs",
|
||||
content_type_field="object_type",
|
||||
object_id_field="object_id")
|
||||
|
@ -22,10 +22,11 @@
|
||||
""" Views for Person, Name, and Surname """
|
||||
|
||||
## Gramps Modules
|
||||
from webapp.utils import _, boolean
|
||||
from webapp.utils import _, boolean, update_last_changed
|
||||
from webapp.grampsdb.models import Event
|
||||
from webapp.grampsdb.forms import *
|
||||
from webapp.libdjango import DjangoInterface
|
||||
import DateHandler
|
||||
|
||||
## Django Modules
|
||||
from django.shortcuts import get_object_or_404, render_to_response, redirect
|
||||
@ -33,6 +34,8 @@ from django.template import Context, RequestContext
|
||||
|
||||
## Globals
|
||||
dji = DjangoInterface()
|
||||
dd = DateHandler.displayer.display
|
||||
dp = DateHandler.parser.parse
|
||||
|
||||
def process_event(request, context, handle, action): # view, edit, save
|
||||
"""
|
||||
@ -41,89 +44,54 @@ def process_event(request, context, handle, action): # view, edit, save
|
||||
context["tview"] = _("Event")
|
||||
context["tviews"] = _("Events")
|
||||
context["action"] = "view"
|
||||
context["event"] = Event()
|
||||
context["object"] = Event()
|
||||
view_template = "view_event_detail.html"
|
||||
|
||||
if handle == "add":
|
||||
action = "add"
|
||||
if request.POST.has_key("action"):
|
||||
action = request.POST.get("action")
|
||||
|
||||
# Handle: edit, view, add, create, save, delete
|
||||
if action == "add":
|
||||
event = Event()
|
||||
eventform = EventForm(instance=event)
|
||||
eventform.model = event
|
||||
elif action in ["view", "edit"]:
|
||||
event = Event.objects.get(handle=handle)
|
||||
eventform = EventForm(instance=event)
|
||||
eventform.model = event
|
||||
elif action == "save":
|
||||
event = Event.objects.get(handle=handle)
|
||||
eventform = EventForm(request.POST, instance=event)
|
||||
eventform.model = event
|
||||
if eventform.is_valid():
|
||||
update_last_changed(event, request.user.username)
|
||||
event = eventform.save()
|
||||
dji.rebuild_cache(event)
|
||||
action = "view"
|
||||
else:
|
||||
action = "edit"
|
||||
elif action == "create":
|
||||
event = Event(handle=create_id())
|
||||
eventform = EventForm(request.POST, instance=event)
|
||||
eventform.model = event
|
||||
if eventform.is_valid():
|
||||
update_last_changed(event, request.user.username)
|
||||
event = eventform.save()
|
||||
dji.rebuild_cache(event)
|
||||
action = "view"
|
||||
else:
|
||||
action = "add"
|
||||
elif action == "delete":
|
||||
event = Event.objects.get(handle=handle)
|
||||
event.delete()
|
||||
return redirect("/event/")
|
||||
else:
|
||||
raise Exception("Unhandled action: '%s'" % action)
|
||||
|
||||
context["eventform"] = eventform
|
||||
context["object"] = event
|
||||
context["event"] = event
|
||||
context["action"] = action
|
||||
|
||||
return render_to_response(view_template, context)
|
||||
if request.user.is_authenticated():
|
||||
if action in ["edit", "view"]:
|
||||
pf, nf, sf, person = get_person_forms(handle, empty=False)
|
||||
elif action == "add":
|
||||
pf, nf, sf, person = get_person_forms(handle=None, protect=False, empty=True)
|
||||
elif action == "delete":
|
||||
pf, nf, sf, person = get_person_forms(handle, protect=False, empty=True)
|
||||
person.delete()
|
||||
return redirect("/person/")
|
||||
elif action in ["save", "create"]: # could be create a new person
|
||||
# look up old data, if any:
|
||||
if handle:
|
||||
person = Person.objects.get(handle=handle)
|
||||
name = person.name_set.get(preferred=True)
|
||||
surname = name.surname_set.get(primary=True)
|
||||
else: # create new item
|
||||
person = Person(handle=create_id())
|
||||
name = Name(person=person, preferred=True)
|
||||
surname = Surname(name=name, primary=True, order=1)
|
||||
surname = Surname(name=name,
|
||||
primary=True,
|
||||
order=1,
|
||||
name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0]))
|
||||
# combine with user data:
|
||||
pf = PersonForm(request.POST, instance=person)
|
||||
pf.model = person
|
||||
nf = NameFormFromPerson(request.POST, instance=name)
|
||||
nf.model = name
|
||||
sf = SurnameForm(request.POST, instance=surname)
|
||||
# check if valid:
|
||||
if nf.is_valid() and pf.is_valid() and sf.is_valid():
|
||||
# name.preferred and surname.primary get set False in the above is_valid()
|
||||
person = pf.save()
|
||||
# Process data:
|
||||
name.person = person
|
||||
name = nf.save(commit=False)
|
||||
# Manually set any data:
|
||||
name.suffix = nf.cleaned_data["suffix"] if nf.cleaned_data["suffix"] != " suffix " else ""
|
||||
name.preferred = True # FIXME: why is this False?
|
||||
check_preferred(name, person)
|
||||
name.save()
|
||||
# Process data:
|
||||
surname.name = name
|
||||
surname = sf.save(commit=False)
|
||||
# Manually set any data:
|
||||
surname.prefix = sf.cleaned_data["prefix"] if sf.cleaned_data["prefix"] != " prefix " else ""
|
||||
surname.primary = True # FIXME: why is this False?
|
||||
surname.save()
|
||||
# FIXME: last_saved, last_changed, last_changed_by
|
||||
dji.rebuild_cache(person)
|
||||
# FIXME: update probably_alive
|
||||
return redirect("/person/%s" % person.handle)
|
||||
else:
|
||||
# need to edit again
|
||||
if handle:
|
||||
action = "edit"
|
||||
else:
|
||||
action = "add"
|
||||
else: # error?
|
||||
raise Http404(_("Requested %s does not exist.") % "person")
|
||||
else: # not authenticated
|
||||
# BEGIN NON-AUTHENTICATED ACCESS
|
||||
try:
|
||||
person = Person.objects.get(handle=handle)
|
||||
except:
|
||||
raise Http404(_("Requested %s does not exist.") % "person")
|
||||
if person.private:
|
||||
raise Http404(_("Requested %s does not exist.") % "person")
|
||||
pf, nf, sf, person = get_person_forms(handle, protect=True)
|
||||
# END NON-AUTHENTICATED ACCESS
|
||||
context["action"] = action
|
||||
context["view"] = "person"
|
||||
context["tview"] = _("Person")
|
||||
context["tviews"] = _("People")
|
||||
context["personform"] = pf
|
||||
context["nameform"] = nf
|
||||
context["surnameform"] = sf
|
||||
context["person"] = person
|
||||
context["object"] = person
|
||||
context["next"] = "/person/%s" % person.handle
|
||||
|
||||
|
@ -49,7 +49,8 @@ def process_family(request, context, handle, action): # view, edit, save
|
||||
|
||||
# Handle: edit, view, add, create, save, delete
|
||||
if action == "add":
|
||||
family = Family(family_rel_type=FamilyRelType.objects.get(
|
||||
family = Family(
|
||||
family_rel_type=FamilyRelType.objects.get(
|
||||
val=FamilyRelType._DEFAULT[0]))
|
||||
familyform = FamilyForm(instance=family)
|
||||
familyform.model = family
|
||||
|
@ -12,8 +12,12 @@ from webapp.dbdjango import DbDjango
|
||||
from webapp.reports import import_file
|
||||
from webapp.libdjango import DjangoInterface, totime, todate
|
||||
|
||||
import DateHandler
|
||||
|
||||
db = DbDjango()
|
||||
dji = DjangoInterface()
|
||||
dd = DateHandler.displayer.display
|
||||
dp = DateHandler.parser.parse
|
||||
|
||||
#def Print(m):
|
||||
# print m
|
||||
|
@ -67,7 +67,7 @@ _ = lambda msg: msg
|
||||
|
||||
util_filters = [
|
||||
'nbsp',
|
||||
'render_date',
|
||||
'date_as_text',
|
||||
'render_name',
|
||||
]
|
||||
|
||||
@ -97,8 +97,9 @@ util_tags = [
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
dji = libdjango.DjangoInterface()
|
||||
_dd = gen.datehandler.displayer.display
|
||||
_dp = gen.datehandler.parser.parse
|
||||
dd = DateHandler.displayer.display
|
||||
dp = DateHandler.parser.parse
|
||||
db = DbDjango()
|
||||
|
||||
def register_plugins():
|
||||
dbstate = DbState.DbState()
|
||||
@ -122,7 +123,6 @@ def get_person_from_handle(db, handle):
|
||||
|
||||
def probably_alive(handle):
|
||||
return False
|
||||
db = DbDjango()
|
||||
person = db.get_person_from_handle(handle)
|
||||
return Utils.probably_alive(person, db)
|
||||
|
||||
@ -553,7 +553,7 @@ def children_table(obj, user, action, url=None, *args):
|
||||
child.gender_type,
|
||||
childref.father_rel_type,
|
||||
childref.mother_rel_type,
|
||||
render_date(child.birth, user),
|
||||
date_as_text(child.birth, user),
|
||||
)
|
||||
links.append(('URL', ("/person/%s" % child.handle)))
|
||||
else:
|
||||
@ -603,7 +603,7 @@ def display_date(obj):
|
||||
if date_tuple:
|
||||
gdate = GDate()
|
||||
gdate.unserialize(date_tuple)
|
||||
return _dd(gdate)
|
||||
return dd(gdate)
|
||||
else:
|
||||
return ""
|
||||
|
||||
@ -615,13 +615,15 @@ def render(formfield, user, action, test=False, truetext="", id=None):
|
||||
fieldname = formfield.name # 'surname'
|
||||
try:
|
||||
retval = str(getattr(formfield.form.model, fieldname))
|
||||
if retval == "True":
|
||||
retval = "Yes"
|
||||
elif retval == "False":
|
||||
retval = "No"
|
||||
except:
|
||||
# name, "prefix"
|
||||
try:
|
||||
retval = str(formfield.form.data[fieldname]) # formfield._data()
|
||||
retval = str(formfield.form.data[fieldname])
|
||||
except:
|
||||
#import pdb; pdb.set_trace()
|
||||
#retval = "[ERROR: %s]" % fieldname
|
||||
retval = "[None]"
|
||||
else:
|
||||
retval = truetext
|
||||
@ -684,7 +686,7 @@ def render_name(name, user):
|
||||
def make_name(name, user):
|
||||
return render_name(name, user)
|
||||
|
||||
def render_date(obj, user):
|
||||
def date_as_text(obj, user):
|
||||
"""
|
||||
Given a Django object, render the date as text and return. This
|
||||
function uses authentication settings.
|
||||
@ -695,7 +697,7 @@ def render_date(obj, user):
|
||||
date_tuple = dji.get_date(obj)
|
||||
if date_tuple:
|
||||
gdate = GDate().unserialize(date_tuple)
|
||||
return _dd(gdate)
|
||||
return dd(gdate)
|
||||
return ""
|
||||
return "[Private]"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user