Working on formatted notes; everything done but the split into text/tags and save
svn: r19691
This commit is contained in:
parent
3073f58940
commit
d71494b3d8
@ -9,8 +9,8 @@
|
||||
$('.wysiwyg').htmlarea({
|
||||
toolbar: [
|
||||
"bold", "italic", "underline",
|
||||
"|",
|
||||
"link", "unlink"
|
||||
"|", "link", "unlink",
|
||||
"|", "html"
|
||||
]
|
||||
});
|
||||
// FIXME: easier way?
|
||||
@ -35,13 +35,13 @@
|
||||
{% endif %}
|
||||
<form method="post" onsubmit="setnotetext()">{% csrf_token %}
|
||||
<tr>
|
||||
<td class="ColumnAttribute">{{noteform.text.label}}:</td>
|
||||
<td class="ColumnAttribute">{{noteform.notetext.label}}:</td>
|
||||
<td class="ColumnValue" id="data" colspan="3">
|
||||
{% 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 %}
|
||||
{% else %}
|
||||
<p style="overflow-y: scroll; height: 100px;">{{notetext}}</p>
|
||||
<div style="overflow-y: scroll; height: 100px;">{{notetext|safe}}</div>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -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
|
||||
|
||||
|
@ -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))
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user