From d71494b3d8f06b6d82e612b0a7a19a051165877d Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Tue, 29 May 2012 00:32:55 +0000 Subject: [PATCH] Working on formatted notes; everything done but the split into text/tags and save svn: r19691 --- src/data/templates/view_note_detail.html | 10 ++++---- src/webapp/grampsdb/view/note.py | 32 +++++++++++++++++------- src/webapp/shell.py | 10 +++++--- src/webapp/utils.py | 22 +++++----------- 4 files changed, 40 insertions(+), 34 deletions(-) diff --git a/src/data/templates/view_note_detail.html b/src/data/templates/view_note_detail.html index cba627190..a629874aa 100644 --- a/src/data/templates/view_note_detail.html +++ b/src/data/templates/view_note_detail.html @@ -9,8 +9,8 @@ $('.wysiwyg').htmlarea({ toolbar: [ "bold", "italic", "underline", - "|", - "link", "unlink" + "|", "link", "unlink", + "|", "html" ] }); // FIXME: easier way? @@ -35,13 +35,13 @@ {% endif %}
{% csrf_token %} -{{noteform.text.label}}: +{{noteform.notetext.label}}: {% if action == "edit" or action == "add" %} - + {% render noteform.notetext user action %} {% else %} -

{{notetext}}

+
{{notetext|safe}}
{% endif %} diff --git a/src/webapp/grampsdb/view/note.py b/src/webapp/grampsdb/view/note.py index ff827607d..4437d4222 100644 --- a/src/webapp/grampsdb/view/note.py +++ b/src/webapp/grampsdb/view/note.py @@ -22,10 +22,11 @@ """ Views for Person, Name, and Surname """ ## Gramps Modules -from webapp.utils import _, boolean, update_last_changed +from webapp.utils import _, boolean, update_last_changed, StyledNoteFormatter from webapp.grampsdb.models import Note from webapp.grampsdb.forms import * from webapp.libdjango import DjangoInterface +from webapp.dbdjango import DbDjango ## 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() +db = DbDjango() +snf = StyledNoteFormatter(db) def process_note(request, context, handle, action, add_to=None): # view, edit, save """ @@ -51,29 +54,37 @@ def process_note(request, context, handle, action, add_to=None): # view, edit, s # Handle: edit, view, add, create, save, delete if action == "add": note = Note(gramps_id=dji.get_next_id(Note, "N")) - noteform = NoteForm(instance=note, initial={"notetext": note.text}) + notetext = "" + noteform = NoteForm(instance=note, initial={"notetext": notetext}) noteform.model = note elif action in ["view", "edit"]: note = Note.objects.get(handle=handle) - noteform = NoteForm(instance=note, initial={"notetext": note.text}) + genlibnote = db.get_note_from_handle(note.handle) + notetext = snf.format(genlibnote) + noteform = NoteForm(instance=note, initial={"notetext": notetext}) noteform.model = note elif action == "save": note = Note.objects.get(handle=handle) - noteform = NoteForm(request.POST, instance=note, initial={"notetext": note.text}) + genlibnote = db.get_note_from_handle(note.handle) + notetext = snf.format(genlibnote) # FIXME + noteform = NoteForm(request.POST, instance=note, initial={"notetext": notetext}) noteform.model = note - note.text = noteform.data["notetext"] + #note.text = noteform.data["notetext"] # FIXME: split text and tags if noteform.is_valid(): update_last_changed(note, request.user.username) note = noteform.save() dji.rebuild_cache(note) + notetext = noteform.data["notetext"] action = "view" else: + notetext = noteform.data["notetext"] action = "edit" elif action == "create": note = Note(handle=create_id()) - noteform = NoteForm(request.POST, instance=note, initial={"notetext": note.text}) + notetext = "" # FIXME + noteform = NoteForm(request.POST, instance=note, initial={"notetext": notetext}) noteform.model = note - note.text = noteform.data["notetext"] + #note.text = noteform.data["notetext"] # FIXME: split text and tags if noteform.is_valid(): update_last_changed(note, request.user.username) note = noteform.save() @@ -83,11 +94,14 @@ def process_note(request, context, handle, action, add_to=None): # view, edit, s model = dji.get_model(item) obj = model.objects.get(handle=handle) dji.add_note_ref(obj, note) - return redirect("/%s/%s" % (item, handle)) + return redirect("/%s/%s#tab-notes" % (item, handle)) + notetext = noteform.data["notetext"] action = "view" else: + notetext = noteform.data["notetext"] action = "add" elif action == "delete": + # FIXME: delete markup too for this note note = Note.objects.get(handle=handle) note.delete() return redirect("/note/") @@ -96,7 +110,7 @@ def process_note(request, context, handle, action, add_to=None): # view, edit, s context["noteform"] = noteform context["object"] = note - context["notetext"] = note.text + context["notetext"] = notetext context["note"] = note context["action"] = action diff --git a/src/webapp/shell.py b/src/webapp/shell.py index 06ae4dae1..ba7aa9049 100644 --- a/src/webapp/shell.py +++ b/src/webapp/shell.py @@ -32,9 +32,11 @@ dp = parser.parse from webapp.utils import StyledNoteFormatter snf = StyledNoteFormatter(db) -for n in Note.objects.all(): - note = db.get_note_from_handle(n.handle) - print snf.get_note_format(note) +#for n in Note.objects.all(): +# note = db.get_note_from_handle(n.handle) +# print snf.format(note) -#note = Note.objects.get(handle="aef30789d3d2090abe2") +note = Note.objects.get(handle="aef30789d3d2090abe2") +genlibnote = db.get_note_from_handle(note.handle) +print snf.format(genlibnote) #st = gen.lib.StyledText(note.text, dji.get_note_markup(note)) diff --git a/src/webapp/utils.py b/src/webapp/utils.py index e66461274..d1d07e8aa 100644 --- a/src/webapp/utils.py +++ b/src/webapp/utils.py @@ -759,22 +759,12 @@ class StyledNoteFormatter(object): self.database = database self._backend = WebAppBackend() self._backend.build_link = self.build_link - #self.report = report - def get_note_format(self, note): - """ - will get the note from the database, and will return either the - styled text or plain note - """ - # retrieve the body of the note - note_text = note.get() - # styled notes - htmlnotetext = self.styled_note(note.get_styledtext(), - note.get_format(), contains_html = - note.get_type() == gen.lib.NoteType.HTML_CODE) - text = htmlnotetext or Html("p", note_text) - # return text of the note to its callers - return text + def format(self, note): + return self.styled_note( + note.get_styledtext(), + note.get_format(), + contains_html=(note.get_type() == gen.lib.NoteType.HTML_CODE)) def styled_note(self, styledtext, format, contains_html=False): """ @@ -788,7 +778,7 @@ class StyledNoteFormatter(object): s_tags = styledtext.get_tags() markuptext = self._backend.add_markup_from_styled(text, s_tags, split='\n') - htmllist = [] # Html("p") #"div", class_="grampsstylednote") + htmllist = Html("div") #"div", class_="grampsstylednote") if contains_html: htmllist += text else: