diff --git a/src/data/templates/main_page.html b/src/data/templates/main_page.html index 5ba419490..6149db888 100644 --- a/src/data/templates/main_page.html +++ b/src/data/templates/main_page.html @@ -8,7 +8,7 @@

 

-

Welcome to Gramps Connect, a new web-based collaboration tool. +

Welcome to Gramps-Connect, a new web-based collaboration tool. {% if user.is_authenticated %} You are now logged in diff --git a/src/data/templates/view_event_detail.html b/src/data/templates/view_event_detail.html index 49bffd415..24b1bd2b6 100644 --- a/src/data/templates/view_event_detail.html +++ b/src/data/templates/view_event_detail.html @@ -48,11 +48,13 @@

+
+
-
+
-
+
diff --git a/src/data/templates/view_name_detail.html b/src/data/templates/view_name_detail.html index 26cfa8748..e622e246b 100644 --- a/src/data/templates/view_name_detail.html +++ b/src/data/templates/view_name_detail.html @@ -11,33 +11,39 @@
-

{{name|make_name:user}}

+

NAME{# form|make_name:user #}

{% comment %} 4 cols {% endcomment %} {% if user.is_authenticated %} + {% ifequal action "edit" %} + {% for error in form.errors %} + {{error}}
+ {% endfor %} + + {% endifequal %} - + - + - + - + - + - + - + - + @@ -47,7 +53,7 @@ - + @@ -65,7 +71,7 @@ - +
Family:{{name.surname}}{{form.surname|render:action}} Prefix:{{name.prefix}}{{form.prefix|render:action}}
Given:{{name.first_name}}{{form.first_name|render:action}} Call Name:{{name.call}}{{form.call|render:action}}
Title:{{name.title}}{{form.title|render:action}} Suffix:{{name.suffix}}{{form.suffix|render:action}}
Patronymic:{{name.patronymic}}{{form.patronymic|render:action}} Type:{{name.name_type}}{{form.name_type|render:action}}
Family:{{name.surname}}{{form.surname}} Prefix: [Private]
Patronymic: [Private] Type:{{name.name_type}}{{form.name_type}}
@@ -91,6 +97,17 @@
[Back to Person Details] - +{% if user.is_authenticated %} + {% ifequal action "edit" %} + + + + {% else %} +[Edit Name] +[Delete Name] +[Add Name] + {% endifequal %} +{% else %} +{% endif %} {% endblock %} diff --git a/src/web/forms.py b/src/web/forms.py index 1d4c5c821..755932c95 100644 --- a/src/web/forms.py +++ b/src/web/forms.py @@ -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): diff --git a/src/web/grampsdb/templatetags/my_tags.py b/src/web/grampsdb/templatetags/my_tags.py index daa23a09f..403677c9f 100644 --- a/src/web/grampsdb/templatetags/my_tags.py +++ b/src/web/grampsdb/templatetags/my_tags.py @@ -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 diff --git a/src/web/grampsdb/views.py b/src/web/grampsdb/views.py index bdaad8667..eb59e19a3 100644 --- a/src/web/grampsdb/views.py +++ b/src/web/grampsdb/views.py @@ -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,18 +103,49 @@ 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) - person = Person.objects.get(handle=handle) +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 - 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): if view == "event": diff --git a/src/web/urls.py b/src/web/urls.py index 671b7eeab..06e65701f 100644 --- a/src/web/urls.py +++ b/src/web/urls.py @@ -68,7 +68,8 @@ urlpatterns += patterns('', url(r'^person/(?P(\w+))/$', view_detail, {"view": "person"}, name="view-person-detail"), (r'^(?P(\w+))/(?P(\w+))/$', view_detail), - (r'^person/(?P(\w+))/name/(?P(\w+))$', view_name_detail), + (r'^person/(?P(\w+))/name/(?P(\w+))$', view_name_detail), + (r'^person/(?P(\w+))/name/(?P(\w+))/(?P(\w+))$', view_name_detail), ) # In urls: diff --git a/src/web/utils.py b/src/web/utils.py index a48de8a8d..f33171e7f 100644 --- a/src/web/utils.py +++ b/src/web/utils.py @@ -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):