Webapp: use cuni for python3 compatibility

svn: r22989
This commit is contained in:
Doug Blank 2013-09-01 11:42:09 +00:00
parent 653cb3882b
commit 8e8a2b7c6a
2 changed files with 153 additions and 151 deletions

View File

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

View File

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