First draft of gramps-connect using django Forms
svn: r13831
This commit is contained in:
parent
bfd2a9629f
commit
00f2a1859a
@ -8,7 +8,7 @@
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p id="description">Welcome to Gramps Connect, a new web-based collaboration tool.
|
||||
<p id="description">Welcome to Gramps-Connect, a new web-based collaboration tool.
|
||||
|
||||
{% if user.is_authenticated %}
|
||||
You are now logged in
|
||||
|
@ -48,11 +48,13 @@
|
||||
</ul>
|
||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom" id="tabs-sources">
|
||||
</div>
|
||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tabs-notes">
|
||||
</div>
|
||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tabs-gallery">
|
||||
</div>
|
||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom" id="tabs-attributes">
|
||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tabs-attributes">
|
||||
</div>
|
||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom" id="tabs-references">
|
||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tabs-references">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -11,33 +11,39 @@
|
||||
</script>
|
||||
|
||||
<div class="content" id="IndividualDetail">
|
||||
<h3>{{name|make_name:user}}</h3>
|
||||
<h3>NAME{# form|make_name:user #}</h3>
|
||||
<div id="summaryarea">
|
||||
<table class="infolist"> {% comment %} 4 cols {% endcomment %}
|
||||
<tbody>
|
||||
|
||||
{% if user.is_authenticated %}
|
||||
{% ifequal action "edit" %}
|
||||
{% for error in form.errors %}
|
||||
{{error}}<br>
|
||||
{% endfor %}
|
||||
<form method="post">
|
||||
{% endifequal %}
|
||||
<tr>
|
||||
<td class="ColumnAttribute">Family:</td>
|
||||
<td class="ColumnValue" id="data">{{name.surname}}</td>
|
||||
<td class="ColumnValue" id="data">{{form.surname|render:action}}</td>
|
||||
<td class="ColumnAttribute">Prefix:</td>
|
||||
<td class="ColumnValue" id="data">{{name.prefix}}</td>
|
||||
<td class="ColumnValue" id="data">{{form.prefix|render:action}}</td>
|
||||
</tr>
|
||||
<td class="ColumnAttribute">Given:</td>
|
||||
<td class="ColumnValue" id="data">{{name.first_name}}</td>
|
||||
<td class="ColumnValue" id="data">{{form.first_name|render:action}}</td>
|
||||
<td class="ColumnAttribute">Call Name:</td>
|
||||
<td class="ColumnValue" id="data">{{name.call}}</td>
|
||||
<td class="ColumnValue" id="data">{{form.call|render:action}}</td>
|
||||
<tr>
|
||||
</tr>
|
||||
<td class="ColumnAttribute">Title:</td>
|
||||
<td class="ColumnValue" id="data">{{name.title}}</td>
|
||||
<td class="ColumnValue" id="data">{{form.title|render:action}}</td>
|
||||
<td class="ColumnAttribute">Suffix:</td>
|
||||
<td class="ColumnValue" id="data">{{name.suffix}}</td>
|
||||
<td class="ColumnValue" id="data">{{form.suffix|render:action}}</td>
|
||||
<tr>
|
||||
<td class="ColumnAttribute">Patronymic:</td>
|
||||
<td class="ColumnValue" id="data">{{name.patronymic}}</td>
|
||||
<td class="ColumnValue" id="data">{{form.patronymic|render:action}}</td>
|
||||
<td class="ColumnAttribute">Type:</td>
|
||||
<td class="ColumnValue" id="data">{{name.name_type}}</td>
|
||||
<td class="ColumnValue" id="data">{{form.name_type|render:action}}</td>
|
||||
</tr>
|
||||
</tr>
|
||||
</tbody>
|
||||
@ -47,7 +53,7 @@
|
||||
|
||||
<tr>
|
||||
<td class="ColumnAttribute">Family:</td>
|
||||
<td class="ColumnValue" id="data">{{name.surname}}</td>
|
||||
<td class="ColumnValue" id="data">{{form.surname}}</td>
|
||||
<td class="ColumnAttribute">Prefix:</td>
|
||||
<td class="ColumnValue" id="data">[Private]</td>
|
||||
<tr>
|
||||
@ -65,7 +71,7 @@
|
||||
<td class="ColumnAttribute">Patronymic:</td>
|
||||
<td class="ColumnValue" id="data">[Private]</td>
|
||||
<td class="ColumnAttribute">Type:</td>
|
||||
<td class="ColumnValue" id="data">{{name.name_type}}</td>
|
||||
<td class="ColumnValue" id="data">{{form.name_type}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@ -91,6 +97,17 @@
|
||||
</div>
|
||||
|
||||
[<a href="/person/{{person.handle}}/">Back to Person Details</a>]
|
||||
|
||||
{% if user.is_authenticated %}
|
||||
{% ifequal action "edit" %}
|
||||
<input type="hidden" name="action" value="save"/>
|
||||
<input type="submit" value="Submit"/>
|
||||
</form>
|
||||
{% else %}
|
||||
[<a href="/person/{{person.handle}}/name/{{order}}/edit">Edit Name</a>]
|
||||
[<a href="/person/{{person.handle}}/name/{{order}}/delete">Delete Name</a>]
|
||||
[<a href="/person/{{person.handle}}/name/{{order}}/add">Add Name</a>]
|
||||
{% endifequal %}
|
||||
{% else %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
|
@ -4,12 +4,14 @@ from django import forms
|
||||
from web.grampsdb.models import *
|
||||
from django.forms.models import inlineformset_factory
|
||||
from django.forms.models import BaseModelFormSet
|
||||
from django.forms.widgets import TextInput
|
||||
import datetime
|
||||
|
||||
class PersonForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Person
|
||||
exclude = ('handle',)
|
||||
|
||||
'''def clean(self):
|
||||
cleaned_data['last_changed'] = datetime.datetime.now()
|
||||
super(PersonForm, self).clean() # validate based on model
|
||||
@ -18,6 +20,15 @@ class PersonForm(forms.ModelForm):
|
||||
class NameForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Name
|
||||
fields = ("suffix", "first_name", "title", "prefix",
|
||||
"call", "surname", "patronymic", "name_type")
|
||||
surname = forms.CharField(required=False, widget=TextInput())
|
||||
first_name = forms.CharField(required=False, widget=TextInput())
|
||||
title = forms.CharField(required=False, widget=TextInput())
|
||||
prefix = forms.CharField(required=False, widget=TextInput())
|
||||
suffix = forms.CharField(required=False, widget=TextInput())
|
||||
call = forms.CharField(required=False, widget=TextInput())
|
||||
patronymic = forms.CharField(required=False, widget=TextInput())
|
||||
|
||||
'''class NameFormset(BaseModelFormSet):
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
@ -15,7 +15,7 @@ util_filters = ['person_event_table', 'person_name_table',
|
||||
'family_source_table', 'family_attribute_table',
|
||||
'family_note_table', 'family_gallery_table',
|
||||
'family_lds_table',
|
||||
'nbsp']
|
||||
'nbsp', 'render']
|
||||
for filter_name in util_filters:
|
||||
func = getattr(web.utils, filter_name)
|
||||
func.is_safe = True
|
||||
|
@ -30,7 +30,7 @@ from django.contrib.auth import logout
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.paginator import Paginator, InvalidPage, EmptyPage
|
||||
from django.http import Http404, HttpResponseRedirect
|
||||
from django.shortcuts import get_object_or_404, render_to_response
|
||||
from django.shortcuts import get_object_or_404, render_to_response, redirect
|
||||
from django.template import Context, RequestContext, escape
|
||||
from django.db.models import Q
|
||||
|
||||
@ -41,6 +41,7 @@ from django.db.models import Q
|
||||
#------------------------------------------------------------------------
|
||||
import web
|
||||
from web.grampsdb.models import *
|
||||
from web.forms import NameForm
|
||||
|
||||
_ = lambda text: text
|
||||
|
||||
@ -102,17 +103,48 @@ def user_page(request, username):
|
||||
context["cview"] = _('User')
|
||||
return render_to_response('user_page.html', context)
|
||||
|
||||
def view_name_detail(request, handle, id):
|
||||
view_template = "view_name_detail.html"
|
||||
name = Name.objects.get(id=id)
|
||||
def view_name_detail(request, handle, order, action="view"):
|
||||
if request.POST.has_key("action"):
|
||||
action = request.POST.get("action")
|
||||
if action == "view":
|
||||
person = Person.objects.get(handle=handle)
|
||||
name = person.name_set.get(order=order)
|
||||
form = NameForm(instance=name)
|
||||
form.model = name
|
||||
elif action == "edit":
|
||||
person = Person.objects.get(handle=handle)
|
||||
name = person.name_set.get(order=order)
|
||||
form = NameForm(instance=name)
|
||||
form.model = name
|
||||
elif action == "delete":
|
||||
pass
|
||||
elif action == "add":
|
||||
pass
|
||||
elif action == "save":
|
||||
person = Person.objects.get(handle=handle)
|
||||
name = person.name_set.get(order=order)
|
||||
form = NameForm(request.POST, instance=name)
|
||||
form.model = name
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
else:
|
||||
action = "edit"
|
||||
context = RequestContext(request)
|
||||
context["cview"] = 'Name'
|
||||
context["action"] = action
|
||||
context["cview"] = action #_('Name')
|
||||
context["view"] = 'name'
|
||||
context["handle"] = handle
|
||||
context["id"] = id
|
||||
context["name"] = name
|
||||
context["person"] = person
|
||||
context["form"] = form
|
||||
context["order"] = name.order
|
||||
view_template = "view_name_detail.html"
|
||||
print "action:", action
|
||||
if action == "save":
|
||||
context["action"] = "view"
|
||||
return redirect("/person/%s/name/%d" %
|
||||
(person.handle, name.order), context)
|
||||
else:
|
||||
return render_to_response(view_template, context)
|
||||
|
||||
def view_detail(request, view, handle):
|
||||
|
@ -68,7 +68,8 @@ urlpatterns += patterns('',
|
||||
url(r'^person/(?P<handle>(\w+))/$', view_detail,
|
||||
{"view": "person"}, name="view-person-detail"),
|
||||
(r'^(?P<view>(\w+))/(?P<handle>(\w+))/$', view_detail),
|
||||
(r'^person/(?P<handle>(\w+))/name/(?P<id>(\w+))$', view_name_detail),
|
||||
(r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))$', view_name_detail),
|
||||
(r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))/(?P<action>(\w+))$', view_name_detail),
|
||||
)
|
||||
|
||||
# In urls:
|
||||
|
@ -107,6 +107,12 @@ class Table(object):
|
||||
def link(self, object_type_name, handle):
|
||||
self.table.set_link_col((object_type_name, handle))
|
||||
|
||||
def links(self, links):
|
||||
"""
|
||||
A list of (object_type_name, handle) pairs, one per row.
|
||||
"""
|
||||
self.table.set_link_col(links)
|
||||
|
||||
def get_html(self):
|
||||
# The HTML writer escapes data:
|
||||
self.table.write(self.doc) # forces to htmllist
|
||||
@ -115,6 +121,15 @@ class Table(object):
|
||||
|
||||
_ = lambda text: text
|
||||
|
||||
def render(formfield, action):
|
||||
retval = "error"
|
||||
name = formfield.name # 'surname'
|
||||
if action == "view": # gets the unicode from model
|
||||
retval = str(getattr(formfield.form.model, name))
|
||||
else: # renders as default
|
||||
retval = formfield.as_widget()
|
||||
return retval
|
||||
|
||||
def person_event_table(djperson, user):
|
||||
table = Table()
|
||||
table.columns(_("Description"),
|
||||
@ -147,7 +162,8 @@ def person_name_table(djperson, user):
|
||||
_("Source"),
|
||||
_("Note Preview"))
|
||||
if user.is_authenticated():
|
||||
for name in djperson.name_set.all():
|
||||
links = []
|
||||
for name in djperson.name_set.all().order_by("order"):
|
||||
obj_type = ContentType.objects.get_for_model(name)
|
||||
sourceq = dji.SourceRef.filter(object_type=obj_type,
|
||||
object_id=name.id).count() > 0
|
||||
@ -161,8 +177,9 @@ def person_name_table(djperson, user):
|
||||
name.group_as,
|
||||
["No", "Yes"][sourceq],
|
||||
note)
|
||||
table.link('URL', "/person/%s/name/%s" %
|
||||
(name.person.handle, name.id))
|
||||
links.append(('URL', "/person/%s/name/%s" %
|
||||
(name.person.handle, name.order)))
|
||||
table.links(links)
|
||||
return table.get_html()
|
||||
|
||||
def person_source_table(djperson, user):
|
||||
|
Loading…
Reference in New Issue
Block a user