Webapp changes to properly show unicode data in html

svn: r22975
This commit is contained in:
Doug Blank 2013-08-31 13:41:38 +00:00
parent 0b0d0c5c05
commit 4a8d98ec2e
3 changed files with 149 additions and 150 deletions

View File

@ -165,7 +165,7 @@ class SimpleTable(object):
if (self._link_col == col or link is None):
link = ('Date', item)
elif isinstance(item, Span):
text = str(item)
text = unicode(item)
retval.append(text)
self.row_sort_val(col, item)
elif isinstance(item, list): # [text, "PersonList", handle, ...]
@ -238,7 +238,7 @@ class SimpleTable(object):
else:
doc.start_link("/%s/%s" %
(obj_type.lower(), handle))
doc.write_text(str(col), 'Normal')
doc.write_text(unicode(col), 'Normal')
if obj_type and handle:
doc.stop_link()
doc.end_cell()

View File

@ -106,7 +106,7 @@ class mGrampsType(models.Model):
name = models.CharField(max_length=40)
def __unicode__(self):
return str(self.name)
return unicode(self.name)
def get_default_type(self):
""" return a tuple default (val,name) """
@ -178,10 +178,10 @@ class EventType(mGrampsType):
val = models.IntegerField('event type', choices=_DATAMAP, blank=False)
def get_url(self):
return "/event/?search=type%%3D%s" % self.name
return u"/event/?search=type%%3D%s" % self.name
def get_link(self):
return "<a href='%s'>%s</a>" % (self.get_url(), self.name)
return u"<a href='%s'>%s</a>" % (self.get_url(), self.name)
class FamilyRelType(mGrampsType):
@ -403,7 +403,7 @@ class Config(models.Model):
value = models.TextField('value')
def __unicode__(self):
return str(self.setting)
return unicode(self.setting)
class Tag(models.Model):
handle = models.CharField(max_length=19, unique=True)
@ -418,13 +418,13 @@ class Tag(models.Model):
priority = models.IntegerField('priority', blank=True, null=True)
def __unicode__(self):
return str(self.name)
return unicode(self.name)
def get_url(self):
return "/tag/%s" % self.handle
return u"/tag/%s" % self.handle
def get_link(self):
return "<a href='%s'>%s</a>" % (self.get_url(), self.name)
return u"<a href='%s'>%s</a>" % (self.get_url(), self.name)
# Just the following have tag lists:
# ---------------------------------
@ -454,11 +454,11 @@ class PrimaryObject(models.Model):
cache = models.TextField(blank=True, null=True)
def __unicode__(self):
return "%s: %s" % (self.__class__.__name__,
return u"%s: %s" % (self.__class__.__name__,
self.gramps_id)
def get_url(self):
return "/%s/%s" % (self.__class__.__name__.lower(),
return u"/%s/%s" % (self.__class__.__name__.lower(),
self.handle)
class MyFamilies(models.Model):
@ -510,7 +510,7 @@ class Person(PrimaryObject):
return ""
def __unicode__(self):
return "%s [%s]" % (self.get_primary_name(), self.gramps_id)
return u"%s [%s]" % (self.get_primary_name(), self.gramps_id)
def make_tag_list(self):
return tuple()
@ -546,7 +546,7 @@ class Family(PrimaryObject):
def __unicode__(self):
father = self.father.get_primary_name() if self.father else "No father"
mother = self.mother.get_primary_name() if self.mother else "No mother"
return str("%s and %s" % (father, mother))
return u"%s and %s" % (father, mother)
class Citation(DateObject, PrimaryObject):
confidence = models.IntegerField(blank=True, null=True)
@ -557,7 +557,7 @@ class Citation(DateObject, PrimaryObject):
object_id_field="object_id")
def __unicode__(self):
return "[%s] (%s, %s) to %s" % (self.gramps_id,
return u"[%s] (%s, %s) to %s" % (self.gramps_id,
self.confidence,
self.page,
self.source)
@ -572,7 +572,7 @@ class Source(PrimaryObject):
abbrev = models.CharField("Abbreviation", max_length=50, blank=True, null=True)
def __unicode__(self):
return "[%s] %s" % (self.gramps_id,
return u"[%s] %s" % (self.gramps_id,
self.title)
# Other keys here:
@ -587,7 +587,7 @@ class Event(DateObject, PrimaryObject):
object_id_field="object_id")
def __unicode__(self):
return "[%s] (%s) %s" % (self.gramps_id,
return u"[%s] (%s) %s" % (self.gramps_id,
self.event_type,
self.description)
@ -601,7 +601,7 @@ class Repository(PrimaryObject):
#url_list = models.ManyToManyField('Url', null=True, blank=True)
def __unicode__(self):
return "[%s] %s" % (self.gramps_id, self.name)
return u"[%s] %s" % (self.gramps_id, self.name)
# Others keys here:
# .address_set
@ -615,10 +615,10 @@ class Place(PrimaryObject):
#url_list = models.ManyToManyField('Url', null=True, blank=True)
def get_selection_string(self):
return "%s [%s]" % (self.title, self.gramps_id)
return u"%s [%s]" % (self.title, self.gramps_id)
def __unicode__(self):
return str(self.title)
return unicode(self.title)
# Others keys here:
# .url_set
@ -638,7 +638,7 @@ class Media(DateObject, PrimaryObject):
return tuple()
def __unicode__(self):
return str(self.desc)
return unicode(self.desc)
class Note(PrimaryObject):
note_type = models.ForeignKey('NoteType', verbose_name="Type")
@ -653,7 +653,7 @@ class Note(PrimaryObject):
return tuple()
def __unicode__(self):
return str(self.gramps_id)
return unicode(self.gramps_id)
#---------------------------------------------------------------------------
#
@ -691,11 +691,11 @@ class Surname(models.Model):
order = models.PositiveIntegerField()
def __unicode__(self):
return "%s" % self.surname
return unicode(self.surname)
def get_url(self):
# /person/handle/name/1/surname/2
return "/person/%s/name/%s/surname/%s" % (self.name.person.handle,
return u"/person/%s/name/%s/surname/%s" % (self.name.person.handle,
self.name.order,
self.order)
@ -726,15 +726,14 @@ class Name(DateObject, SecondaryObject):
surname = self.surname_set.get(primary=True)
except:
surname = "[No primary surname]"
return "%s, %s" % (surname,
self.first_name)
return u"%s, %s" % (surname, self.first_name)
def get_selection_string(self):
try:
surname = self.surname_set.get(primary=True)
except:
surname = "[No primary surname]"
return "%s, %s [%s]" % (surname, self.first_name, self.person.gramps_id)
return u"%s, %s [%s]" % (surname, self.first_name, self.person.gramps_id)
@staticmethod
def get_dummy():
@ -758,7 +757,7 @@ class Name(DateObject, SecondaryObject):
def get_url(self):
# /person/handle/name/1
return "/person/%s/name/%s" % (self.person.handle, self.order)
return u"/person/%s/name/%s" % (self.person.handle, self.order)
class Lds(DateObject, SecondaryObject):
"""
@ -890,7 +889,7 @@ class BaseRef(models.Model):
# /person/3536453463/reference/event/2
ref_by = self.object_type.model_class().objects.get(id=self.object_id)
ref_to = self.get_reference_to()
return "/%s/%s/reference/%s/%s" % (ref_by.__class__.__name__.lower(),
return u"/%s/%s/reference/%s/%s" % (ref_by.__class__.__name__.lower(),
ref_by.handle,
ref_to.__class__.__name__.lower(),
self.order)
@ -900,7 +899,7 @@ class Log(BaseRef):
cache = models.TextField(blank=True, null=True)
def __unicode__(self):
return "%s: %s on %s by %s" % (self.log_type,
return u"%s: %s on %s by %s" % (self.log_type,
self.referenced_by,
self.last_changed,
self.last_changed_by)
@ -912,14 +911,14 @@ class NoteRef(BaseRef):
return self.ref_object
def __unicode__(self):
return "NoteRef to " + str(self.ref_object)
return u"NoteRef to " + unicode(self.ref_object)
class EventRef(BaseRef):
ref_object = models.ForeignKey('Event')
role_type = models.ForeignKey('EventRoleType')
def __unicode__(self):
return str(self.ref_object)
return unicode(self.ref_object)
def get_reference_to(self):
return self.ref_object
@ -928,7 +927,7 @@ class EventRef(BaseRef):
# /person/3536453463/reference/event/2
ref_by = self.object_type.model_class().objects.get(id=self.object_id)
ref_to = self.ref_object
return "/%s/%s/reference/%s/%s" % (ref_by.__class__.__name__.lower(),
return u"/%s/%s/reference/%s/%s" % (ref_by.__class__.__name__.lower(),
ref_by.handle,
ref_to.__class__.__name__.lower(),
self.order)
@ -942,7 +941,7 @@ class RepositoryRef(BaseRef):
return self.ref_object
def __unicode__(self):
return "RepositoryRef to " + str(self.ref_object)
return u"RepositoryRef to " + unicode(self.ref_object)
class PersonRef(BaseRef):
ref_object = models.ForeignKey('Person')
@ -952,13 +951,13 @@ class PersonRef(BaseRef):
return self.ref_object
def __unicode__(self):
return "PersonRef to " + str(self.ref_object)
return u"PersonRef to " + unicode(self.ref_object)
class CitationRef(BaseRef):
citation = models.ForeignKey('Citation')
def __unicode__(self):
return "CitationRef to " + str(self.citation)
return u"CitationRef to " + unicode(self.citation)
def get_reference_to(self):
return self.citation
@ -975,10 +974,10 @@ class ChildRef(BaseRef):
def get_url(self):
# FIXME: go to child reference
return "/person/%s" % self.ref_object.handle
return u"/person/%s" % self.ref_object.handle
def __unicode__(self):
return "ChildRef to " + str(self.ref_object)
return u"ChildRef to " + unicode(self.ref_object)
class MediaRef(BaseRef):
x1 = models.IntegerField()
@ -991,7 +990,7 @@ class MediaRef(BaseRef):
return self.ref_object
def __unicode__(self):
return "MediaRef to " + str(self.ref_object)
return u"MediaRef to " + unicode(self.ref_object)
class Report(models.Model):
gramps_id = models.TextField(blank=True, null=True)
@ -1001,7 +1000,7 @@ class Report(models.Model):
options = models.TextField(blank=True, null=True)
def __unicode__(self):
return str(self.name)
return unicode(self.name)
class Result(models.Model):
name = models.TextField(blank=True, null=True)
@ -1011,7 +1010,7 @@ class Result(models.Model):
status = models.TextField(blank=True, null=True)
def __unicode__(self):
return str(self.name)
return unicode(self.name)
TABLES = [
("abstract", mGrampsType),

View File

@ -145,7 +145,7 @@ def get_person_from_handle(db, handle):
print("error in get_person_from_handle:", file=sys.stderr)
import sys, traceback
cla, exc, trbk = sys.exc_info()
print(_("Error") + (" : %s %s" %(cla, exc)), file=sys.stderr)
print(_("Error") + (u" : %s %s" %(cla, exc)), file=sys.stderr)
traceback.print_exc()
return None
@ -250,18 +250,18 @@ class Table(object):
self.table.set_link_col(links)
def get_html(self):
retval = ""
retval = u""
# The HTML writer escapes data:
self.table.write(self.doc, self.column_widths) # forces to htmllist
# FIXME: do once, or once per table?
self.doc.doc.build_style_declaration(self.id) # can pass id, for whole
# FIXME: don't want to repeat this, unless diff for each table:
retval += "<style>%s</style>" % self.doc.doc.style_declaration
retval += u"<style>%s</style>" % self.doc.doc.style_declaration
# We have a couple of HTML bits that we want to unescape:
return retval + str(self.doc.doc.htmllist[0]).replace("&amp;nbsp;", "&nbsp;")
return retval + unicode(self.doc.doc.htmllist[0]).replace("&amp;nbsp;", "&nbsp;")
def build_args(**kwargs):
retval = ""
retval = u""
first = True
for key in kwargs:
if kwargs[key] is not "":
@ -270,7 +270,7 @@ def build_args(**kwargs):
first = False
else:
retval += "&"
retval += "%s=%s" % (key, kwargs[key])
retval += u"%s=%s" % (key, kwargs[key])
return retval
def build_search(request):
@ -280,8 +280,8 @@ def build_search(request):
def make_button(text, url, *args):
newargs = []
kwargs = ""
last = ""
kwargs = u""
last = u""
for arg in args:
if isinstance(arg, STRTYPE) and arg.startswith("?"):
kwargs = arg
@ -296,7 +296,7 @@ def make_button(text, url, *args):
if text[0] in "+$-?x" or text in ["x", "^", "v", "<", "<<", ">", ">>"]:
return mark_safe(make_image_button(text, url, kwargs, last))
else:
return mark_safe("""<input type="button" value="%s" onclick="document.location.href='%s%s%s'"/>""" %
return mark_safe(u"""<input type="button" value="%s" onclick="document.location.href='%s%s%s'"/>""" %
(text, url, kwargs, last))
def make_image_button(text, url, kwargs, last):
@ -369,10 +369,10 @@ def make_image_button2(button, text, url, kwargs="", last=""):
filename = "/images/scalable/add-parent-existing-family.svg"
elif button == "add spouse to new family":
filename = "/images/scalable/gramps-parents.svg"
return """<img height="22" width="22" alt="%s" title="%s" src="%s" onmouseover="buttonOver(this)" onmouseout="buttonOut(this)" onclick="document.location.href='%s%s%s'" style="background-color: lightgray; border: 1px solid lightgray; border-radius:5px; margin: 0px 1px; padding: 1px;" />""" % (text, text, filename, url, kwargs, last)
return u"""<img height="22" width="22" alt="%s" title="%s" src="%s" onmouseover="buttonOver(this)" onmouseout="buttonOut(this)" onclick="document.location.href='%s%s%s'" style="background-color: lightgray; border: 1px solid lightgray; border-radius:5px; margin: 0px 1px; padding: 1px;" />""" % (text, text, filename, url, kwargs, last)
def event_table(obj, user, act, url, args):
retval = ""
retval = u""
has_data = False
cssid = "tab-events"
table = Table("event_table")
@ -400,18 +400,18 @@ def event_table(obj, user, act, url, args):
djevent.gramps_id,
display_date(djevent),
get_title(djevent.place),
str(event_ref.role_type))
unicode(event_ref.role_type))
links.append(('URL', event_ref.get_url()))
has_data = True
count += 1
table.links(links)
retval += """<div style="background-color: lightgray; padding: 2px 0px 0px 2px">"""
retval += u"""<div style="background-color: lightgray; padding: 2px 0px 0px 2px">"""
if user.is_superuser and act == "view":
retval += make_button(_("+Add New Event"), (url % args).replace("$act", "add"))
retval += make_button(_("$Add Existing Event"), (url % args).replace("$act", "share"))
else:
retval += """<div style="height: 26px;"></div>""" # to keep tabs same height
retval += """</div>"""
retval += u"""<div style="height: 26px;"></div>""" # to keep tabs same height
retval += u"""</div>"""
retval += table.get_html()
if user.is_superuser and act == "view":
count = 1
@ -419,16 +419,16 @@ def event_table(obj, user, act, url, args):
retval = retval.replace("}}", """</div>""")
for (djevent, event_ref) in event_list:
item = obj.__class__.__name__.lower()
retval = retval.replace("[[x%d]]" % count, make_button("x", "/%s/%s/remove/eventref/%d" % (item, obj.handle, count)))
retval = retval.replace("[[^%d]]" % count, make_button("^", "/%s/%s/up/eventref/%d" % (item, obj.handle, count)))
retval = retval.replace("[[v%d]]" % count, make_button("v", "/%s/%s/down/eventref/%d" % (item, obj.handle, count)))
retval = retval.replace("[[x%d]]" % count, make_button("x", u"/%s/%s/remove/eventref/%d" % (item, obj.handle, count)))
retval = retval.replace("[[^%d]]" % count, make_button("^", u"/%s/%s/up/eventref/%d" % (item, obj.handle, count)))
retval = retval.replace("[[v%d]]" % count, make_button("v", u"/%s/%s/down/eventref/%d" % (item, obj.handle, count)))
count += 1
if has_data:
retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
retval += u""" <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
return retval
def history_table(obj, user, act):
retval = ""
retval = u""
has_data = False
cssid = "tab-history"
table = Table("history_table")
@ -442,23 +442,23 @@ def history_table(obj, user, act):
object_id=obj.id,
object_type=obj_type):
table.row(
"%s on %s by %s" % (entry.log_type,
u"%s on %s by %s" % (entry.log_type,
entry.last_changed,
entry.last_changed_by),
entry.reason)
has_data = True
table.row(
"Latest on %s by %s" % (obj.last_changed,
u"Latest on %s by %s" % (obj.last_changed,
obj.last_changed_by),
"Current status")
retval += table.get_html()
retval += nbsp("") # to keep tabs same height
if has_data:
retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
retval += u""" <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
return retval
def name_table(obj, user, act, url=None, *args):
retval = ""
retval = u""
has_data = False
cssid = "tab-names"
table = Table("name_table")
@ -475,20 +475,20 @@ def name_table(obj, user, act, url=None, *args):
object_id=name.id).count() > 0
note_refs = dji.NoteRef.filter(object_type=obj_type,
object_id=name.id)
note = ""
note = u""
if note_refs.count() > 0:
try:
note = dji.Note.get(id=note_refs[0].object_id).text[:50]
except:
note = None
table.row(make_name(name, user),
str(name.name_type) + ["", " (preferred)"][int(name.preferred)],
unicode(name.name_type) + ["", " (preferred)"][int(name.preferred)],
name.group_as,
["No", "Yes"][citationq],
note)
links.append(('URL',
# url is "/person/%s/name"
(url % name.person.handle) + ("/%s" % name.order)))
(url % name.person.handle) + (u"/%s" % name.order)))
has_data = True
table.links(links)
retval += """<div style="background-color: lightgray; padding: 2px 0px 0px 2px">"""
@ -499,13 +499,13 @@ def name_table(obj, user, act, url=None, *args):
retval += """</div>"""
retval += table.get_html()
if has_data:
retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
retval += u""" <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
return retval
def surname_table(obj, user, act, url=None, *args):
person_handle = args[0]
order = args[1]
retval = ""
retval = u""
has_data = False
cssid = "tab-surnames"
table = Table("surname_table")
@ -523,19 +523,19 @@ def surname_table(obj, user, act, url=None, *args):
name = None
if name:
for surname in name.surname_set.all().order_by("order"):
table.row(str(surname.order), surname)
table.row(unicode(surname.order), surname)
has_data = True
retval += table.get_html()
else:
retval += "<p id='error'>No such name order = %s</p>" % order
retval += u"<p id='error'>No such name order = %s</p>" % order
if has_data:
retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
retval += u""" <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
return retval
def citation_table(obj, user, act, url=None, *args):
# FIXME: how can citation_table and source_table both be on same
# page? This causes problems with form names, tab names, etc.
retval = ""
retval = u""
has_data = False
cssid = "tab-sources"
table = Table("citation_table")
@ -556,8 +556,8 @@ def citation_table(obj, user, act, url=None, *args):
citation_ref.citation.handle)
table.row(Link("{{[[x%d]][[^%d]][[v%d]]}}" % (count, count, count)) if user.is_superuser and url and act == "view" else "",
citation.gramps_id,
str(citation.confidence),
str(citation.page),
unicode(citation.confidence),
unicode(citation.page),
)
links.append(('URL', citation_ref.get_url()))
has_data = True
@ -577,16 +577,16 @@ def citation_table(obj, user, act, url=None, *args):
count = 1
for citation_ref in citation_refs:
item = obj.__class__.__name__.lower()
retval = retval.replace("[[x%d]]" % count, make_button("x", "/%s/%s/remove/citationref/%d" % (item, obj.handle, count)))
retval = retval.replace("[[^%d]]" % count, make_button("^", "/%s/%s/up/citationref/%d" % (item, obj.handle, count)))
retval = retval.replace("[[v%d]]" % count, make_button("v", "/%s/%s/down/citationref/%d" % (item, obj.handle, count)))
retval = retval.replace("[[x%d]]" % count, make_button("x", u"/%s/%s/remove/citationref/%d" % (item, obj.handle, count)))
retval = retval.replace("[[^%d]]" % count, make_button("^", u"/%s/%s/up/citationref/%d" % (item, obj.handle, count)))
retval = retval.replace("[[v%d]]" % count, make_button("v", u"/%s/%s/down/citationref/%d" % (item, obj.handle, count)))
count += 1
if has_data:
retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
retval += u""" <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
return retval
def repository_table(obj, user, act, url=None, *args):
retval = ""
retval = u""
has_data = False
cssid = "tab-repositories"
table = Table("repository_table")
@ -617,7 +617,7 @@ def repository_table(obj, user, act, url=None, *args):
repository.gramps_id,
repository.name,
repo_ref.call_number,
str(repository.repository_type),
unicode(repository.repository_type),
)
has_data = True
count += 1
@ -627,17 +627,17 @@ def repository_table(obj, user, act, url=None, *args):
count = 1
for repo_ref in refs:
item = obj.__class__.__name__.lower()
text = text.replace("[[x%d]]" % count, make_button("x", "/%s/%s/remove/repositoryref/%d" % (item, obj.handle, count)))
text = text.replace("[[^%d]]" % count, make_button("^", "/%s/%s/up/repositoryref/%d" % (item, obj.handle, count)))
text = text.replace("[[v%d]]" % count, make_button("v", "/%s/%s/down/repositoryref/%d" % (item, obj.handle, count)))
text = text.replace("[[x%d]]" % count, make_button("x", u"/%s/%s/remove/repositoryref/%d" % (item, obj.handle, count)))
text = text.replace("[[^%d]]" % count, make_button("^", u"/%s/%s/up/repositoryref/%d" % (item, obj.handle, count)))
text = text.replace("[[v%d]]" % count, make_button("v", u"/%s/%s/down/repositoryref/%d" % (item, obj.handle, count)))
count += 1
retval += text
if has_data:
retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
retval += u""" <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
return retval
def note_table(obj, user, act, url=None, *args):
retval = ""
retval = u""
has_data = False
cssid = "tab-notes"
table = Table("note_table")
@ -657,7 +657,7 @@ def note_table(obj, user, act, url=None, *args):
note = note_ref.ref_object
table.row(Link("{{[[x%d]][[^%d]][[v%d]]}}" % (count, count, count)) if user.is_superuser else "",
note.gramps_id,
str(note.note_type),
unicode(note.note_type),
note.text[:50]
)
links.append(('URL', note_ref.get_url()))
@ -678,17 +678,17 @@ def note_table(obj, user, act, url=None, *args):
count = 1
for note_ref in note_refs:
item = obj.__class__.__name__.lower()
text = text.replace("[[x%d]]" % count, make_button("x", "/%s/%s/remove/noteref/%d" % (item, obj.handle, count)))
text = text.replace("[[^%d]]" % count, make_button("^", "/%s/%s/up/noteref/%d" % (item, obj.handle, count)))
text = text.replace("[[v%d]]" % count, make_button("v", "/%s/%s/down/noteref/%d" % (item, obj.handle, count)))
text = text.replace("[[x%d]]" % count, make_button("x", u"/%s/%s/remove/noteref/%d" % (item, obj.handle, count)))
text = text.replace("[[^%d]]" % count, make_button("^", u"/%s/%s/up/noteref/%d" % (item, obj.handle, count)))
text = text.replace("[[v%d]]" % count, make_button("v", u"/%s/%s/down/noteref/%d" % (item, obj.handle, count)))
count += 1
retval += text
if has_data:
retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
retval += u""" <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
return retval
def data_table(obj, user, act, url=None, *args):
retval = ""
retval = u""
has_data = False
cssid = "tab-data"
table = Table("data_table")
@ -729,9 +729,9 @@ def data_table(obj, user, act, url=None, *args):
text = text.replace("}}", """</div>""")
count = 1
for repo_ref in refs:
text = text.replace("[[x%d]]" % count, make_button("x", "/%s/%s/remove/attribute/%d" % (item_class, obj.handle, count)))
text = text.replace("[[^%d]]" % count, make_button("^", "/%s/%s/up/attribute/%d" % (item_class, obj.handle, count)))
text = text.replace("[[v%d]]" % count, make_button("v", "/%s/%s/down/attribute/%d" % (item_class, obj.handle, count)))
text = text.replace("[[x%d]]" % count, make_button("x", u"/%s/%s/remove/attribute/%d" % (item_class, obj.handle, count)))
text = text.replace("[[^%d]]" % count, make_button("^", u"/%s/%s/up/attribute/%d" % (item_class, obj.handle, count)))
text = text.replace("[[v%d]]" % count, make_button("v", u"/%s/%s/down/attribute/%d" % (item_class, obj.handle, count)))
count += 1
retval += text
if has_data:
@ -739,7 +739,7 @@ def data_table(obj, user, act, url=None, *args):
return retval
def attribute_table(obj, user, act, url=None, *args):
retval = ""
retval = u""
has_data = False
cssid = "tab-attributes"
table = Table("attribute_table")
@ -766,7 +766,7 @@ def attribute_table(obj, user, act, url=None, *args):
return retval
def address_table(obj, user, act, url=None, *args):
retval = ""
retval = u""
has_data = False
cssid = "tab-addresses"
table = Table("address_table")
@ -797,7 +797,7 @@ def address_table(obj, user, act, url=None, *args):
return retval
def media_table(obj, user, act, url=None, *args):
retval = ""
retval = u""
has_data = False
cssid = "tab-media"
table = Table("media_table")
@ -813,7 +813,7 @@ def media_table(obj, user, act, url=None, *args):
media = table.db.get_object_from_handle(
media_ref.ref_object.handle)
table.row(table.db.get_object_from_handle(media.handle),
str(media_ref.ref_object.desc),
unicode(media_ref.ref_object.desc),
media_ref.ref_object.path)
has_data = True
retval += """<div style="background-color: lightgray; padding: 2px 0px 0px 2px">"""
@ -829,7 +829,7 @@ def media_table(obj, user, act, url=None, *args):
return retval
def internet_table(obj, user, act, url=None, *args):
retval = ""
retval = u""
has_data = False
cssid = "tab-internet"
table = Table("internet_table")
@ -839,13 +839,13 @@ def internet_table(obj, user, act, url=None, *args):
if user.is_authenticated() or obj.public:
urls = dji.Url.filter(person=obj)
for url_obj in urls:
table.row(str(url_obj.url_type),
table.row(unicode(url_obj.url_type),
url_obj.path,
url_obj.desc)
has_data = True
retval += """<div style="background-color: lightgray; padding: 2px 0px 0px 2px">"""
if user.is_superuser and url and act == "view":
retval += make_button(_("+Add Internet"), (str(url) % args))
retval += make_button(_("+Add Internet"), (unicode(url) % args))
else:
retval += nbsp("") # to keep tabs same height
retval += """</div>"""
@ -855,7 +855,7 @@ def internet_table(obj, user, act, url=None, *args):
return retval
def association_table(obj, user, act, url=None, *args):
retval = ""
retval = u""
has_data = False
cssid = "tab-associations"
table = Table("association_table")
@ -899,7 +899,7 @@ def association_table(obj, user, act, url=None, *args):
def location_table(obj, user, act, url=None, *args):
# obj is Place or Address
retval = ""
retval = u""
has_data = False
cssid = "tab-alternatelocations"
table = Table("location_table")
@ -933,7 +933,7 @@ def location_table(obj, user, act, url=None, *args):
return retval
def lds_table(obj, user, act, url=None, *args):
retval = ""
retval = u""
has_data = False
cssid = "tab-lds"
table = Table("lds_table")
@ -946,9 +946,9 @@ def lds_table(obj, user, act, url=None, *args):
obj_type = ContentType.objects.get_for_model(obj)
ldss = obj.lds_set.all().order_by("order")
for lds in ldss:
table.row(str(lds.lds_type),
table.row(unicode(lds.lds_type),
display_date(lds),
str(lds.status),
unicode(lds.status),
lds.temple,
get_title(lds.place))
has_data = True
@ -964,11 +964,11 @@ def lds_table(obj, user, act, url=None, *args):
return retval
def person_reference_table(obj, user, act):
retval = ""
retval = u""
has_data = False
cssid = "tab-references"
text1 = ""
text2 = ""
text1 = u""
text2 = u""
table1 = Table("person_reference_table", style="background-color: #f4f0ec;")
table1.columns(
"As Spouse",
@ -1044,11 +1044,11 @@ def person_reference_table(obj, user, act):
retval += """<div style="overflow: auto; height:%spx;">""" % TAB_HEIGHT
retval += text1 + text2 + "</div>"
if has_data:
retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
retval += u""" <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
return retval
def note_reference_table(obj, user, act):
retval = ""
retval = u""
has_data = False
cssid = "tab-references"
table = Table("note_reference_table")
@ -1072,7 +1072,7 @@ def note_reference_table(obj, user, act):
return retval
def event_reference_table(obj, user, act):
retval = ""
retval = u""
has_data = False
cssid = "tab-references"
table = Table("event_reference_table")
@ -1096,11 +1096,11 @@ def event_reference_table(obj, user, act):
retval += table.get_html()
retval += nbsp("") # to keep tabs same height
if has_data:
retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
retval += u""" <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
return retval
def repository_reference_table(obj, user, act):
retval = ""
retval = u""
has_data = False
cssid = "tab-references"
table = Table("repository_reference_table")
@ -1120,11 +1120,11 @@ def repository_reference_table(obj, user, act):
retval += table.get_html()
retval += nbsp("") # to keep tabs same height
if has_data:
retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
retval += u""" <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
return retval
def citation_reference_table(obj, user, act):
retval = ""
retval = u""
has_data = False
cssid = "tab-references"
table = Table("citation_reference_table")
@ -1144,11 +1144,11 @@ def citation_reference_table(obj, user, act):
retval += table.get_html()
retval += nbsp("") # to keep tabs same height
if has_data:
retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
retval += u""" <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
return retval
def source_reference_table(obj, user, act):
retval = ""
retval = u""
has_data = False
cssid = "tab-references"
table = Table("source_reference_table")
@ -1166,11 +1166,11 @@ def source_reference_table(obj, user, act):
retval += table.get_html()
retval += nbsp("") # to keep tabs same height
if has_data:
retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
retval += u""" <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
return retval
def media_reference_table(obj, user, act):
retval = ""
retval = u""
has_data = False
cssid = "tab-references"
table = Table("media_reference_table")
@ -1190,11 +1190,11 @@ def media_reference_table(obj, user, act):
retval += table.get_html()
retval += nbsp("") # to keep tabs same height
if has_data:
retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
retval += u""" <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
return retval
def place_reference_table(obj, user, act):
retval = ""
retval = u""
has_data = False
cssid = "tab-references"
table = Table("place_reference_table")
@ -1213,11 +1213,11 @@ def place_reference_table(obj, user, act):
retval += table.get_html()
retval += nbsp("") # to keep tabs same height
if has_data:
retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
retval += u""" <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
return retval
def tag_reference_table(obj, user, act):
retval = ""
retval = u""
has_data = False
cssid = "tab-references"
table = Table("tag_reference_table")
@ -1237,7 +1237,7 @@ def tag_reference_table(obj, user, act):
retval += table.get_html()
retval += nbsp("") # to keep tabs same height
if has_data:
retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
retval += u""" <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
return retval
class Link(object):
@ -1250,7 +1250,7 @@ class Link(object):
return self.string
def children_table(obj, user, act, url=None, *args):
retval = ""
retval = u""
has_data = False
cssid = "tab-children"
table = Table("children_table")
@ -1276,8 +1276,8 @@ def children_table(obj, user, act, url=None, *args):
child = childref.ref_object
if user.is_authenticated() or obj.public:
table.row(Link("{{[[x%d]][[^%d]][[v%d]]}}" % (count, count, count)) if user.is_superuser and url and act == "view" else "",
str(count),
"[%s]" % child.gramps_id,
unicode(count),
u"[%s]" % child.gramps_id,
render_name(child, user),
child.gender_type,
childref.father_rel_type,
@ -1289,8 +1289,8 @@ def children_table(obj, user, act, url=None, *args):
count += 1
else:
table.row("",
str(count),
"[%s]" % child.gramps_id,
unicode(count),
u"[%s]" % child.gramps_id,
render_name(child, user) if not child.private else "[Private]",
child.gender_type if not child.private else "[Private]",
"[Private]",
@ -1311,9 +1311,9 @@ def children_table(obj, user, act, url=None, *args):
text = text.replace("}}", """</div>""")
count = 1
for childref in childrefs:
text = text.replace("[[x%d]]" % count, make_button("x", "/family/%s/remove/child/%d" % (family.handle, count)))
text = text.replace("[[^%d]]" % count, make_button("^", "/family/%s/up/child/%d" % (family.handle, count)))
text = text.replace("[[v%d]]" % count, make_button("v", "/family/%s/down/child/%d" % (family.handle, count)))
text = text.replace("[[x%d]]" % count, make_button("x", u"/family/%s/remove/child/%d" % (family.handle, count)))
text = text.replace("[[^%d]]" % count, make_button("^", u"/family/%s/up/child/%d" % (family.handle, count)))
text = text.replace("[[v%d]]" % count, make_button("v", u"/family/%s/down/child/%d" % (family.handle, count)))
count += 1
retval += make_button(_("+Add New Person as Child"), (url.replace("$act", "add") % args))
retval += make_button(_("$Add Existing Person as Child"), (url.replace("$act", "share") % args))
@ -1322,7 +1322,7 @@ def children_table(obj, user, act, url=None, *args):
retval += """</div>"""
retval += text
if has_data:
retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
retval += u""" <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
return retval
## FIXME: these dji function wrappers just use the functions
@ -1344,9 +1344,9 @@ def display_date(obj):
return ""
def media_link(handle, user, act):
retval = """<a href="%s"><img src="%s" /></a>""" % (
"/media/%s/full" % handle,
"/media/%s/thumbnail" % handle)
retval = u"""<a href="%s"><img src="%s" /></a>""" % (
u"/media/%s/full" % handle,
u"/media/%s/thumbnail" % handle)
return retval
def render(formfield, user, act, id=None, url=None, *args):
@ -1357,14 +1357,14 @@ def render(formfield, user, act, id=None, url=None, *args):
try:
item = getattr(formfield.form.model, fieldname)
if (item.__class__.__name__ == 'ManyRelatedManager'):
retval = ", ".join([i.get_link() for i in item.all()])
retval = u", ".join([i.get_link() for i in item.all()])
else:
if url:
retval = """<a href="%s">%s</a>""" % (url % args, item)
retval = u"""<a href="%s">%s</a>""" % (url % args, item)
elif hasattr(item, "get_link"):
retval = item.get_link()
else:
retval = str(item)
retval = unicode(item)
#### Some cleanup:
if fieldname == "private": # obj.private
if retval == "True":
@ -1379,7 +1379,7 @@ def render(formfield, user, act, id=None, url=None, *args):
except:
# name, "prefix"
try:
retval = str(formfield.form.data[fieldname])
retval = unicode(formfield.form.data[fieldname])
except:
retval = "[None]"
else: # show as widget
@ -1405,7 +1405,7 @@ def render_name(name, user, act=None):
surname = name.surname_set.get(primary=True)
except:
surname = "[No primary surname]"
return "%s, %s" % (surname, name.first_name)
return u"%s, %s" % (surname, name.first_name)
elif isinstance(name, forms.NameForm):
if not user.is_authenticated():
name.model.sanitize()
@ -1413,7 +1413,7 @@ def render_name(name, user, act=None):
surname = name.model.surname_set.get(primary=True)
except:
surname = "[No primary surname]"
return "%s, %s" % (surname,
return u"%s, %s" % (surname,
name.model.first_name)
elif isinstance(name, Person): # name is a Person
person = name
@ -1429,7 +1429,7 @@ def render_name(name, user, act=None):
surname = name.surname_set.get(primary=True)
except:
surname = "[No primary surname]"
return "%s, %s" % (surname, name.first_name)
return u"%s, %s" % (surname, name.first_name)
elif isinstance(name, models.Person): # django person
person = name
try:
@ -1524,7 +1524,7 @@ class StyledNoteFormatter(object):
return self.styled_note(note.get_styledtext())
def styled_note(self, styledtext):
text = str(styledtext)
text = unicode(styledtext)
if not text:
return ''
s_tags = styledtext.get_tags()
@ -1544,10 +1544,10 @@ class StyledNoteFormatter(object):
raise AttributeError("gramps_id '%s' not found in '%s'" %
handle, obj_class)
else:
raise AttributeError("invalid gramps_id lookup "
"in table name '%s'" % obj_class)
raise AttributeError(u"invalid gramps_id lookup "
u"in table name '%s'" % obj_class)
# handle, ppl
return "/%s/%s" % (obj_class.lower(), handle)
return u"/%s/%s" % (obj_class.lower(), handle)
class WebAppParser(HTMLParser):
BOLD = 0
@ -1657,7 +1657,7 @@ class WebAppParser(HTMLParser):
href = attrs["href"]
if href.startswith("/"):
parts = href.split("/")
arg = "gramps://%s/handle/%s" % (parts[-2].title(), parts[-1])
arg = u"gramps://%s/handle/%s" % (parts[-2].title(), parts[-1])
else:
arg = href
else: