Working on styled text editing on web app
svn: r19690
This commit is contained in:
@ -295,15 +295,22 @@ class DjangoInterface(object):
|
|||||||
citation_list, note_list, media_list, attribute_list,
|
citation_list, note_list, media_list, attribute_list,
|
||||||
change, private)
|
change, private)
|
||||||
|
|
||||||
def get_note(self, note):
|
def get_note_markup(self, note):
|
||||||
styled_text = [note.text, []]
|
retval = []
|
||||||
markups = models.Markup.objects.filter(note=note).order_by("order")
|
markups = models.Markup.objects.filter(note=note).order_by("order")
|
||||||
for markup in markups:
|
for markup in markups:
|
||||||
|
# FIXME: not all of these are strings; bummer
|
||||||
|
if markup.string and markup.string.isdigit():
|
||||||
|
value = int(markup.string)
|
||||||
|
else:
|
||||||
value = markup.string
|
value = markup.string
|
||||||
start_stop_list = markup.start_stop_list
|
start_stop_list = markup.start_stop_list
|
||||||
ss_list = eval(start_stop_list)
|
ss_list = eval(start_stop_list)
|
||||||
styled_text[1] += [(tuple(markup.markup_type),
|
retval += [(tuple(markup.markup_type), value, ss_list)]
|
||||||
value, ss_list)]
|
return retval
|
||||||
|
|
||||||
|
def get_note(self, note):
|
||||||
|
styled_text = [note.text, self.get_note_markup(note)]
|
||||||
changed = totime(note.last_changed)
|
changed = totime(note.last_changed)
|
||||||
return (str(note.handle),
|
return (str(note.handle),
|
||||||
note.gramps_id,
|
note.gramps_id,
|
||||||
@ -1244,6 +1251,20 @@ class DjangoInterface(object):
|
|||||||
"""
|
"""
|
||||||
pass
|
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):
|
def add_note(self, data):
|
||||||
# Unpack from the BSDDB:
|
# Unpack from the BSDDB:
|
||||||
(handle, gid, styled_text, format, note_type,
|
(handle, gid, styled_text, format, note_type,
|
||||||
@ -1258,16 +1279,7 @@ class DjangoInterface(object):
|
|||||||
note_type=models.get_type(models.NoteType, note_type))
|
note_type=models.get_type(models.NoteType, note_type))
|
||||||
#n.cache = base64.encodestring(cPickle.dumps(data))
|
#n.cache = base64.encodestring(cPickle.dumps(data))
|
||||||
n.save()
|
n.save()
|
||||||
count = 1
|
self.save_note_markup(n, markup_list)
|
||||||
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()
|
|
||||||
|
|
||||||
def add_family(self, data):
|
def add_family(self, data):
|
||||||
# Unpack from the BSDDB:
|
# Unpack from the BSDDB:
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#### This sets up Django so you can interact with it via the Python
|
#### This sets up Django so you can interact with it via the Python
|
||||||
#### command line.
|
#### command line.
|
||||||
#### Start with something like:
|
#### Start with something like:
|
||||||
#### $ PYTHONPATH=.. python -i shell.py
|
#### $ PYTHONPATH=..:../plugins/lib python -i shell.py
|
||||||
#### >>> Person.objects.all()
|
#### >>> Person.objects.all()
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@ -30,8 +30,11 @@ dp = parser.parse
|
|||||||
# "/home/dblank/gramps/trunk/example/gramps/data.gramps",
|
# "/home/dblank/gramps/trunk/example/gramps/data.gramps",
|
||||||
# cli.user.User())
|
# cli.user.User())
|
||||||
|
|
||||||
#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.get_note_format(note)
|
||||||
|
|
||||||
|
#note = Note.objects.get(handle="aef30789d3d2090abe2")
|
||||||
|
#st = gen.lib.StyledText(note.text, dji.get_note_markup(note))
|
||||||
|
@ -733,13 +733,31 @@ register_plugins()
|
|||||||
|
|
||||||
# works after registering plugins:
|
# works after registering plugins:
|
||||||
import HtmlDoc
|
import HtmlDoc
|
||||||
from libhtmlbackend import HtmlBackend, process_spaces
|
from libhtmlbackend import HtmlBackend, DocBackend, process_spaces
|
||||||
from libhtml import Html
|
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 : ("<b>", "</b>"),
|
||||||
|
DocBackend.ITALIC : ("<i>", "</i>"),
|
||||||
|
DocBackend.UNDERLINE : ('<u>', '</u>'),
|
||||||
|
}
|
||||||
|
|
||||||
|
### Taken from Narrated Web Report
|
||||||
class StyledNoteFormatter(object):
|
class StyledNoteFormatter(object):
|
||||||
def __init__(self, database):
|
def __init__(self, database):
|
||||||
self.database = database
|
self.database = database
|
||||||
self._backend = HtmlBackend()
|
self._backend = WebAppBackend()
|
||||||
self._backend.build_link = self.build_link
|
self._backend.build_link = self.build_link
|
||||||
#self.report = report
|
#self.report = report
|
||||||
|
|
||||||
@ -770,7 +788,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("div", class_="grampsstylednote")
|
htmllist = [] # Html("p") #"div", class_="grampsstylednote")
|
||||||
if contains_html:
|
if contains_html:
|
||||||
htmllist += text
|
htmllist += text
|
||||||
else:
|
else:
|
||||||
@ -799,7 +817,7 @@ class StyledNoteFormatter(object):
|
|||||||
if sigcount == 0:
|
if sigcount == 0:
|
||||||
linelist = [" "]
|
linelist = [" "]
|
||||||
htmllist.extend(Html('p') + linelist)
|
htmllist.extend(Html('p') + linelist)
|
||||||
return htmllist
|
return "".join(htmllist)
|
||||||
|
|
||||||
def build_link(self, prop, handle, obj_class):
|
def build_link(self, prop, handle, obj_class):
|
||||||
"""
|
"""
|
||||||
|
Reference in New Issue
Block a user