diff --git a/src/webapp/libdjango.py b/src/webapp/libdjango.py
index e8c216628..d9ab20e75 100644
--- a/src/webapp/libdjango.py
+++ b/src/webapp/libdjango.py
@@ -295,15 +295,22 @@ class DjangoInterface(object):
citation_list, note_list, media_list, attribute_list,
change, private)
- def get_note(self, note):
- styled_text = [note.text, []]
+ def get_note_markup(self, note):
+ retval = []
markups = models.Markup.objects.filter(note=note).order_by("order")
for markup in markups:
- value = markup.string
+ # FIXME: not all of these are strings; bummer
+ if markup.string and markup.string.isdigit():
+ value = int(markup.string)
+ else:
+ value = markup.string
start_stop_list = markup.start_stop_list
ss_list = eval(start_stop_list)
- styled_text[1] += [(tuple(markup.markup_type),
- value, ss_list)]
+ retval += [(tuple(markup.markup_type), value, ss_list)]
+ return retval
+
+ def get_note(self, note):
+ styled_text = [note.text, self.get_note_markup(note)]
changed = totime(note.last_changed)
return (str(note.handle),
note.gramps_id,
@@ -1243,6 +1250,20 @@ class DjangoInterface(object):
Dummy method for consistency with other two-pass adds.
"""
pass
+
+ def save_note_markup(self, note, markup_list):
+ # delete any prexisting markup:
+ models.Markup.objects.filter(note=note).delete()
+ count = 1
+ for markup in markup_list:
+ markup_code, value, start_stop_list = markup
+ m = models.Markup(note=note, order=count,
+ markup_type=models.get_type(models.MarkupType,
+ markup_code,
+ get_or_create=True),
+ string=value,
+ start_stop_list=str(start_stop_list))
+ m.save()
def add_note(self, data):
# Unpack from the BSDDB:
@@ -1258,16 +1279,7 @@ class DjangoInterface(object):
note_type=models.get_type(models.NoteType, note_type))
#n.cache = base64.encodestring(cPickle.dumps(data))
n.save()
- count = 1
- for markup in markup_list:
- markup_code, value, start_stop_list = markup
- m = models.Markup(note=n, order=count,
- markup_type=models.get_type(models.MarkupType,
- markup_code,
- get_or_create=True),
- string=value,
- start_stop_list=str(start_stop_list))
- m.save()
+ self.save_note_markup(n, markup_list)
def add_family(self, data):
# Unpack from the BSDDB:
diff --git a/src/webapp/shell.py b/src/webapp/shell.py
index 984cdfcd2..06ae4dae1 100644
--- a/src/webapp/shell.py
+++ b/src/webapp/shell.py
@@ -1,7 +1,7 @@
#### This sets up Django so you can interact with it via the Python
#### command line.
#### Start with something like:
-#### $ PYTHONPATH=.. python -i shell.py
+#### $ PYTHONPATH=..:../plugins/lib python -i shell.py
#### >>> Person.objects.all()
from django.conf import settings
@@ -30,8 +30,11 @@ dp = parser.parse
# "/home/dblank/gramps/trunk/example/gramps/data.gramps",
# cli.user.User())
-#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)
+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)
+
+#note = Note.objects.get(handle="aef30789d3d2090abe2")
+#st = gen.lib.StyledText(note.text, dji.get_note_markup(note))
diff --git a/src/webapp/utils.py b/src/webapp/utils.py
index c949cce69..e66461274 100644
--- a/src/webapp/utils.py
+++ b/src/webapp/utils.py
@@ -733,13 +733,31 @@ register_plugins()
# works after registering plugins:
import HtmlDoc
-from libhtmlbackend import HtmlBackend, process_spaces
+from libhtmlbackend import HtmlBackend, DocBackend, process_spaces
from libhtml import Html
+class WebAppBackend(HtmlBackend):
+ SUPPORTED_MARKUP = [
+ DocBackend.BOLD,
+ DocBackend.ITALIC,
+ DocBackend.UNDERLINE,
+ DocBackend.FONTFACE,
+ DocBackend.FONTSIZE,
+ DocBackend.FONTCOLOR,
+ DocBackend.LINK,
+ ]
+
+ STYLETAG_MARKUP = {
+ DocBackend.BOLD : ("", ""),
+ DocBackend.ITALIC : ("", ""),
+ DocBackend.UNDERLINE : ('', ''),
+ }
+
+### Taken from Narrated Web Report
class StyledNoteFormatter(object):
def __init__(self, database):
self.database = database
- self._backend = HtmlBackend()
+ self._backend = WebAppBackend()
self._backend.build_link = self.build_link
#self.report = report
@@ -770,7 +788,7 @@ class StyledNoteFormatter(object):
s_tags = styledtext.get_tags()
markuptext = self._backend.add_markup_from_styled(text, s_tags,
split='\n')
- htmllist = Html("div", class_="grampsstylednote")
+ htmllist = [] # Html("p") #"div", class_="grampsstylednote")
if contains_html:
htmllist += text
else:
@@ -799,7 +817,7 @@ class StyledNoteFormatter(object):
if sigcount == 0:
linelist = [" "]
htmllist.extend(Html('p') + linelist)
- return htmllist
+ return "".join(htmllist)
def build_link(self, prop, handle, obj_class):
"""