First draft of gramps-connect using django Forms

svn: r13831
This commit is contained in:
Doug Blank 2009-12-17 00:04:22 +00:00
parent bfd2a9629f
commit 00f2a1859a
8 changed files with 108 additions and 28 deletions

View File

@ -8,7 +8,7 @@
<p> &nbsp; </p> <p> &nbsp; </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 %} {% if user.is_authenticated %}
You are now logged in You are now logged in

View File

@ -48,11 +48,13 @@
</ul> </ul>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom" id="tabs-sources"> <div class="ui-tabs-panel ui-widget-content ui-corner-bottom" id="tabs-sources">
</div> </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 class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tabs-gallery">
</div> </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>
<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>
</div> </div>

View File

@ -11,33 +11,39 @@
</script> </script>
<div class="content" id="IndividualDetail"> <div class="content" id="IndividualDetail">
<h3>{{name|make_name:user}}</h3> <h3>NAME{# form|make_name:user #}</h3>
<div id="summaryarea"> <div id="summaryarea">
<table class="infolist"> {% comment %} 4 cols {% endcomment %} <table class="infolist"> {% comment %} 4 cols {% endcomment %}
<tbody> <tbody>
{% if user.is_authenticated %} {% if user.is_authenticated %}
{% ifequal action "edit" %}
{% for error in form.errors %}
{{error}}<br>
{% endfor %}
<form method="post">
{% endifequal %}
<tr> <tr>
<td class="ColumnAttribute">Family:</td> <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="ColumnAttribute">Prefix:</td>
<td class="ColumnValue" id="data">{{name.prefix}}</td> <td class="ColumnValue" id="data">{{form.prefix|render:action}}</td>
</tr> </tr>
<td class="ColumnAttribute">Given:</td> <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="ColumnAttribute">Call Name:</td>
<td class="ColumnValue" id="data">{{name.call}}</td> <td class="ColumnValue" id="data">{{form.call|render:action}}</td>
<tr> <tr>
</tr> </tr>
<td class="ColumnAttribute">Title:</td> <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="ColumnAttribute">Suffix:</td>
<td class="ColumnValue" id="data">{{name.suffix}}</td> <td class="ColumnValue" id="data">{{form.suffix|render:action}}</td>
<tr> <tr>
<td class="ColumnAttribute">Patronymic:</td> <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="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>
</tr> </tr>
</tbody> </tbody>
@ -47,7 +53,7 @@
<tr> <tr>
<td class="ColumnAttribute">Family:</td> <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="ColumnAttribute">Prefix:</td>
<td class="ColumnValue" id="data">[Private]</td> <td class="ColumnValue" id="data">[Private]</td>
<tr> <tr>
@ -65,7 +71,7 @@
<td class="ColumnAttribute">Patronymic:</td> <td class="ColumnAttribute">Patronymic:</td>
<td class="ColumnValue" id="data">[Private]</td> <td class="ColumnValue" id="data">[Private]</td>
<td class="ColumnAttribute">Type:</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> </tr>
</tbody> </tbody>
</table> </table>
@ -91,6 +97,17 @@
</div> </div>
[<a href="/person/{{person.handle}}/">Back to Person Details</a>] [<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 %} {% endblock %}

View File

@ -4,12 +4,14 @@ from django import forms
from web.grampsdb.models import * from web.grampsdb.models import *
from django.forms.models import inlineformset_factory from django.forms.models import inlineformset_factory
from django.forms.models import BaseModelFormSet from django.forms.models import BaseModelFormSet
from django.forms.widgets import TextInput
import datetime import datetime
class PersonForm(forms.ModelForm): class PersonForm(forms.ModelForm):
class Meta: class Meta:
model = Person model = Person
exclude = ('handle',) exclude = ('handle',)
'''def clean(self): '''def clean(self):
cleaned_data['last_changed'] = datetime.datetime.now() cleaned_data['last_changed'] = datetime.datetime.now()
super(PersonForm, self).clean() # validate based on model super(PersonForm, self).clean() # validate based on model
@ -18,6 +20,15 @@ class PersonForm(forms.ModelForm):
class NameForm(forms.ModelForm): class NameForm(forms.ModelForm):
class Meta: class Meta:
model = Name 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): '''class NameFormset(BaseModelFormSet):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):

View File

@ -15,7 +15,7 @@ util_filters = ['person_event_table', 'person_name_table',
'family_source_table', 'family_attribute_table', 'family_source_table', 'family_attribute_table',
'family_note_table', 'family_gallery_table', 'family_note_table', 'family_gallery_table',
'family_lds_table', 'family_lds_table',
'nbsp'] 'nbsp', 'render']
for filter_name in util_filters: for filter_name in util_filters:
func = getattr(web.utils, filter_name) func = getattr(web.utils, filter_name)
func.is_safe = True func.is_safe = True

View File

@ -30,7 +30,7 @@ from django.contrib.auth import logout
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.paginator import Paginator, InvalidPage, EmptyPage from django.core.paginator import Paginator, InvalidPage, EmptyPage
from django.http import Http404, HttpResponseRedirect 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.template import Context, RequestContext, escape
from django.db.models import Q from django.db.models import Q
@ -41,6 +41,7 @@ from django.db.models import Q
#------------------------------------------------------------------------ #------------------------------------------------------------------------
import web import web
from web.grampsdb.models import * from web.grampsdb.models import *
from web.forms import NameForm
_ = lambda text: text _ = lambda text: text
@ -102,18 +103,49 @@ def user_page(request, username):
context["cview"] = _('User') context["cview"] = _('User')
return render_to_response('user_page.html', context) return render_to_response('user_page.html', context)
def view_name_detail(request, handle, id): def view_name_detail(request, handle, order, action="view"):
view_template = "view_name_detail.html" if request.POST.has_key("action"):
name = Name.objects.get(id=id) action = request.POST.get("action")
person = Person.objects.get(handle=handle) 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 = RequestContext(request)
context["cview"] = 'Name' context["action"] = action
context["cview"] = action #_('Name')
context["view"] = 'name' context["view"] = 'name'
context["handle"] = handle context["handle"] = handle
context["id"] = id context["id"] = id
context["name"] = name
context["person"] = person context["person"] = person
return render_to_response(view_template, context) 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): def view_detail(request, view, handle):
if view == "event": if view == "event":

View File

@ -68,7 +68,8 @@ urlpatterns += patterns('',
url(r'^person/(?P<handle>(\w+))/$', view_detail, url(r'^person/(?P<handle>(\w+))/$', view_detail,
{"view": "person"}, name="view-person-detail"), {"view": "person"}, name="view-person-detail"),
(r'^(?P<view>(\w+))/(?P<handle>(\w+))/$', view_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: # In urls:

View File

@ -107,6 +107,12 @@ class Table(object):
def link(self, object_type_name, handle): def link(self, object_type_name, handle):
self.table.set_link_col((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): def get_html(self):
# The HTML writer escapes data: # The HTML writer escapes data:
self.table.write(self.doc) # forces to htmllist self.table.write(self.doc) # forces to htmllist
@ -115,6 +121,15 @@ class Table(object):
_ = lambda text: text _ = 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): def person_event_table(djperson, user):
table = Table() table = Table()
table.columns(_("Description"), table.columns(_("Description"),
@ -147,7 +162,8 @@ def person_name_table(djperson, user):
_("Source"), _("Source"),
_("Note Preview")) _("Note Preview"))
if user.is_authenticated(): 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) obj_type = ContentType.objects.get_for_model(name)
sourceq = dji.SourceRef.filter(object_type=obj_type, sourceq = dji.SourceRef.filter(object_type=obj_type,
object_id=name.id).count() > 0 object_id=name.id).count() > 0
@ -161,8 +177,9 @@ def person_name_table(djperson, user):
name.group_as, name.group_as,
["No", "Yes"][sourceq], ["No", "Yes"][sourceq],
note) note)
table.link('URL', "/person/%s/name/%s" % links.append(('URL', "/person/%s/name/%s" %
(name.person.handle, name.id)) (name.person.handle, name.order)))
table.links(links)
return table.get_html() return table.get_html()
def person_source_table(djperson, user): def person_source_table(djperson, user):