diff --git a/src/data/templates/view_event_detail.html b/src/data/templates/view_event_detail.html index ef7a873d3..b48e42317 100644 --- a/src/data/templates/view_event_detail.html +++ b/src/data/templates/view_event_detail.html @@ -78,7 +78,7 @@ {% else %} - {% make_button "Back to Families" "/event" %} + {% make_button "Back to Events" "/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 %} diff --git a/src/data/templates/view_note_detail.html b/src/data/templates/view_note_detail.html index b865f861b..fe77f9eac 100644 --- a/src/data/templates/view_note_detail.html +++ b/src/data/templates/view_note_detail.html @@ -17,18 +17,32 @@
+ {% if noteform.errors %} +
+

The following fields have errors. Please correct and try again.

+
{{noteform.errors}}
+
+ {% endif %} +{% csrf_token %} - - - - + + - - - - - + + + + + + + + + + + + + +
ID: {{note.gramps_id|escape}}Marker:{{note.note_marker_type|escape}}{{noteform.gramps_id.label}}: {% render noteform.gramps_id user action %}
Type:{{event.description|escape}}PreformattedPrivate{{noteform.note_type.label}}:{% render noteform.note_type user action %}
{{noteform.text.label}}:{% render noteform.text user action %}
{{noteform.preformatted.label}}:{% render noteform.preformatted user action %}
{{noteform.tags.label}}:{% render noteform.tags user action %}
@@ -36,17 +50,34 @@
-
- {{note.text}} -
{{note.references.all.to_list}}
+ +{% if user.is_superuser %} + {% if action == "edit" %} + {% make_button "Back to Note" "/note/%s" note.handle %} + + + {% else %} + {% ifequal action "add" %} + {% make_button "Cancel" "/note/" %} + + + {% else %} + {% make_button "Back to Notes" "/note" %} + {% make_button "Add Note" "/note/add" %} + {% make_button "Edit Note" "/note/%s/edit" note.handle %} + {% make_button "Delete Note" "/note/%s/delete" note.handle %} + {% endifequal %} + {% endif %} +{% else %} +{% endif %} + {% endblock %} diff --git a/src/data/templates/view_notes.html b/src/data/templates/view_notes.html index f1e6d77f0..6ec00b1ff 100644 --- a/src/data/templates/view_notes.html +++ b/src/data/templates/view_notes.html @@ -20,7 +20,7 @@ [{{note.gramps_id}}] {% if user.is_authenticated %} {{note.note_type|escape}} - {{note.text|preview:40}} + {{note.text|preview:70}} {% else %} diff --git a/src/data/templates/view_page_detail.html b/src/data/templates/view_page_detail.html index 696c8283a..226fdc643 100644 --- a/src/data/templates/view_page_detail.html +++ b/src/data/templates/view_page_detail.html @@ -1,10 +1,6 @@ {% extends "gramps-base.html" %} {% load my_tags %} - {% block title %}{{sitename}}: {{tview}} detail {% endblock %} {% block heading %}{{sitename}}: {{tview}} detail {% endblock %} - {% block content %} - - {% endblock %} diff --git a/src/webapp/grampsdb/forms.py b/src/webapp/grampsdb/forms.py index f945013df..ce81d9d95 100644 --- a/src/webapp/grampsdb/forms.py +++ b/src/webapp/grampsdb/forms.py @@ -157,3 +157,9 @@ class EventForm(forms.ModelForm): text = forms.CharField(label="Date", required=False, widget=TextInput(attrs={'size':'45'})) + +class NoteForm(forms.ModelForm): + class Meta: + model = Note + exclude = ["handle"] + diff --git a/src/webapp/grampsdb/templatetags/my_tags.py b/src/webapp/grampsdb/templatetags/my_tags.py index 182712663..5f0738b38 100644 --- a/src/webapp/grampsdb/templatetags/my_tags.py +++ b/src/webapp/grampsdb/templatetags/my_tags.py @@ -111,6 +111,8 @@ register.filter('person_get_events', person_get_event) def preview(text, width=40): text = text.replace("\n", " ") #return escape(text[:width]) + if len(text) > width: + return text[:width] + "..." return text #preview.is_safe = True register.filter('preview', preview) diff --git a/src/webapp/grampsdb/view/note.py b/src/webapp/grampsdb/view/note.py index bdeb768c4..bc2b1e877 100644 --- a/src/webapp/grampsdb/view/note.py +++ b/src/webapp/grampsdb/view/note.py @@ -22,7 +22,7 @@ """ 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 Note from webapp.grampsdb.forms import * from webapp.libdjango import DjangoInterface @@ -41,88 +41,54 @@ def process_note(request, context, handle, action): # view, edit, save context["tview"] = _("Note") context["tviews"] = _("Notes") context["action"] = "view" - context["object"] = Note() view_template = "view_note_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": + note = Note() + noteform = NoteForm(instance=note) + noteform.model = note + elif action in ["view", "edit"]: + note = Note.objects.get(handle=handle) + noteform = NoteForm(instance=note) + noteform.model = note + elif action == "save": + note = Note.objects.get(handle=handle) + noteform = NoteForm(request.POST, instance=note) + noteform.model = note + if noteform.is_valid(): + update_last_changed(note, request.user.username) + note = noteform.save() + dji.rebuild_cache(note) + action = "view" + else: + action = "edit" + elif action == "create": + note = Note(handle=create_id()) + noteform = NoteForm(request.POST, instance=note) + noteform.model = note + if noteform.is_valid(): + update_last_changed(note, request.user.username) + note = noteform.save() + dji.rebuild_cache(note) + action = "view" + else: + action = "add" + elif action == "delete": + note = Note.objects.get(handle=handle) + note.delete() + return redirect("/note/") + else: + raise Exception("Unhandled action: '%s'" % action) + + context["noteform"] = noteform + context["object"] = note + context["note"] = note + 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 -