Working on formatted notes; everything done but the split into text/tags and save

svn: r19691
This commit is contained in:
Doug Blank 2012-05-29 00:32:55 +00:00
parent 3073f58940
commit d71494b3d8
4 changed files with 40 additions and 34 deletions

View File

@ -9,8 +9,8 @@
$('.wysiwyg').htmlarea({ $('.wysiwyg').htmlarea({
toolbar: [ toolbar: [
"bold", "italic", "underline", "bold", "italic", "underline",
"|", "|", "link", "unlink",
"link", "unlink" "|", "html"
] ]
}); });
// FIXME: easier way? // FIXME: easier way?
@ -35,13 +35,13 @@
{% endif %} {% endif %}
<form method="post" onsubmit="setnotetext()">{% csrf_token %} <form method="post" onsubmit="setnotetext()">{% csrf_token %}
<tr> <tr>
<td class="ColumnAttribute">{{noteform.text.label}}:</td> <td class="ColumnAttribute">{{noteform.notetext.label}}:</td>
<td class="ColumnValue" id="data" colspan="3"> <td class="ColumnValue" id="data" colspan="3">
{% if action == "edit" or action == "add" %} {% if action == "edit" or action == "add" %}
<input type="hidden" id="notetext" name="notetext" value="this is hidden"></input> <input type="hidden" id="notetext" name="notetext" value=""></input>
{% render noteform.notetext user action %} {% render noteform.notetext user action %}
{% else %} {% else %}
<p style="overflow-y: scroll; height: 100px;">{{notetext}}</p> <div style="overflow-y: scroll; height: 100px;">{{notetext|safe}}</div>
{% endif %} {% endif %}
</td> </td>
</tr> </tr>

View File

@ -22,10 +22,11 @@
""" Views for Person, Name, and Surname """ """ Views for Person, Name, and Surname """
## Gramps Modules ## 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.models import Note
from webapp.grampsdb.forms import * from webapp.grampsdb.forms import *
from webapp.libdjango import DjangoInterface from webapp.libdjango import DjangoInterface
from webapp.dbdjango import DbDjango
## Django Modules ## Django Modules
from django.shortcuts import get_object_or_404, render_to_response, redirect from django.shortcuts import get_object_or_404, render_to_response, redirect
@ -33,6 +34,8 @@ from django.template import Context, RequestContext
## Globals ## Globals
dji = DjangoInterface() dji = DjangoInterface()
db = DbDjango()
snf = StyledNoteFormatter(db)
def process_note(request, context, handle, action, add_to=None): # view, edit, save 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 # Handle: edit, view, add, create, save, delete
if action == "add": if action == "add":
note = Note(gramps_id=dji.get_next_id(Note, "N")) 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 noteform.model = note
elif action in ["view", "edit"]: elif action in ["view", "edit"]:
note = Note.objects.get(handle=handle) 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 noteform.model = note
elif action == "save": elif action == "save":
note = Note.objects.get(handle=handle) 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 noteform.model = note
note.text = noteform.data["notetext"] #note.text = noteform.data["notetext"] # FIXME: split text and tags
if noteform.is_valid(): if noteform.is_valid():
update_last_changed(note, request.user.username) update_last_changed(note, request.user.username)
note = noteform.save() note = noteform.save()
dji.rebuild_cache(note) dji.rebuild_cache(note)
notetext = noteform.data["notetext"]
action = "view" action = "view"
else: else:
notetext = noteform.data["notetext"]
action = "edit" action = "edit"
elif action == "create": elif action == "create":
note = Note(handle=create_id()) 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 noteform.model = note
note.text = noteform.data["notetext"] #note.text = noteform.data["notetext"] # FIXME: split text and tags
if noteform.is_valid(): if noteform.is_valid():
update_last_changed(note, request.user.username) update_last_changed(note, request.user.username)
note = noteform.save() 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) model = dji.get_model(item)
obj = model.objects.get(handle=handle) obj = model.objects.get(handle=handle)
dji.add_note_ref(obj, note) 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" action = "view"
else: else:
notetext = noteform.data["notetext"]
action = "add" action = "add"
elif action == "delete": elif action == "delete":
# FIXME: delete markup too for this note
note = Note.objects.get(handle=handle) note = Note.objects.get(handle=handle)
note.delete() note.delete()
return redirect("/note/") return redirect("/note/")
@ -96,7 +110,7 @@ def process_note(request, context, handle, action, add_to=None): # view, edit, s
context["noteform"] = noteform context["noteform"] = noteform
context["object"] = note context["object"] = note
context["notetext"] = note.text context["notetext"] = notetext
context["note"] = note context["note"] = note
context["action"] = action context["action"] = action

View File

@ -32,9 +32,11 @@ dp = parser.parse
from webapp.utils import StyledNoteFormatter from webapp.utils import StyledNoteFormatter
snf = StyledNoteFormatter(db) snf = StyledNoteFormatter(db)
for n in Note.objects.all(): #for n in Note.objects.all():
note = db.get_note_from_handle(n.handle) # note = db.get_note_from_handle(n.handle)
print snf.get_note_format(note) # 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)) #st = gen.lib.StyledText(note.text, dji.get_note_markup(note))

View File

@ -759,22 +759,12 @@ class StyledNoteFormatter(object):
self.database = database self.database = database
self._backend = WebAppBackend() self._backend = WebAppBackend()
self._backend.build_link = self.build_link self._backend.build_link = self.build_link
#self.report = report
def get_note_format(self, note): def format(self, note):
""" return self.styled_note(
will get the note from the database, and will return either the note.get_styledtext(),
styled text or plain note note.get_format(),
""" contains_html=(note.get_type() == gen.lib.NoteType.HTML_CODE))
# 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 styled_note(self, styledtext, format, contains_html=False): def styled_note(self, styledtext, format, contains_html=False):
""" """
@ -788,7 +778,7 @@ class StyledNoteFormatter(object):
s_tags = styledtext.get_tags() s_tags = styledtext.get_tags()
markuptext = self._backend.add_markup_from_styled(text, s_tags, markuptext = self._backend.add_markup_from_styled(text, s_tags,
split='\n') split='\n')
htmllist = [] # Html("p") #"div", class_="grampsstylednote") htmllist = Html("div") #"div", class_="grampsstylednote")
if contains_html: if contains_html:
htmllist += text htmllist += text
else: else: