diff --git a/gramps/webapp/grampsdb/models.py b/gramps/webapp/grampsdb/models.py index dec33bae5..e254529c9 100644 --- a/gramps/webapp/grampsdb/models.py +++ b/gramps/webapp/grampsdb/models.py @@ -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.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) def __unicode__(self): - return unicode(self.name) + return cuni(self.name) def get_default_type(self): """ return a tuple default (val,name) """ @@ -178,10 +179,10 @@ class EventType(mGrampsType): val = models.IntegerField('event type', choices=_DATAMAP, blank=False) 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): - return u"%s" % (self.get_url(), self.name) + return cuni("%s") % (self.get_url(), self.name) class FamilyRelType(mGrampsType): @@ -403,7 +404,7 @@ class Config(models.Model): value = models.TextField('value') def __unicode__(self): - return unicode(self.setting) + return cuni(self.setting) class Tag(models.Model): handle = models.CharField(max_length=19, unique=True) @@ -418,13 +419,13 @@ class Tag(models.Model): priority = models.IntegerField('priority', blank=True, null=True) def __unicode__(self): - return unicode(self.name) + return cuni(self.name) def get_url(self): - return u"/tag/%s" % self.handle + return cuni("/tag/%s") % self.handle def get_link(self): - return u"%s" % (self.get_url(), self.name) + return cuni("%s") % (self.get_url(), self.name) # Just the following have tag lists: # --------------------------------- @@ -454,11 +455,11 @@ class PrimaryObject(models.Model): cache = models.TextField(blank=True, null=True) def __unicode__(self): - return u"%s: %s" % (self.__class__.__name__, + return cuni("%s: %s") % (self.__class__.__name__, self.gramps_id) def get_url(self): - return u"/%s/%s" % (self.__class__.__name__.lower(), + return cuni("/%s/%s") % (self.__class__.__name__.lower(), self.handle) class MyFamilies(models.Model): @@ -510,7 +511,7 @@ class Person(PrimaryObject): return "" 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): return tuple() @@ -546,7 +547,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 u"%s and %s" % (father, mother) + return cuni("%s and %s") % (father, mother) class Citation(DateObject, PrimaryObject): confidence = models.IntegerField(blank=True, null=True) @@ -557,7 +558,7 @@ class Citation(DateObject, PrimaryObject): object_id_field="object_id") 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.page, self.source) @@ -572,7 +573,7 @@ class Source(PrimaryObject): abbrev = models.CharField("Abbreviation", max_length=50, blank=True, null=True) def __unicode__(self): - return u"[%s] %s" % (self.gramps_id, + return cuni("[%s] %s") % (self.gramps_id, self.title) # Other keys here: @@ -587,7 +588,7 @@ class Event(DateObject, PrimaryObject): object_id_field="object_id") def __unicode__(self): - return u"[%s] (%s) %s" % (self.gramps_id, + return cuni("[%s] (%s) %s") % (self.gramps_id, self.event_type, self.description) @@ -601,7 +602,7 @@ class Repository(PrimaryObject): #url_list = models.ManyToManyField('Url', null=True, blank=True) def __unicode__(self): - return u"[%s] %s" % (self.gramps_id, self.name) + return cuni("[%s] %s") % (self.gramps_id, self.name) # Others keys here: # .address_set @@ -615,10 +616,10 @@ class Place(PrimaryObject): #url_list = models.ManyToManyField('Url', null=True, blank=True) 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): - return unicode(self.title) + return cuni(self.title) # Others keys here: # .url_set @@ -638,7 +639,7 @@ class Media(DateObject, PrimaryObject): return tuple() def __unicode__(self): - return unicode(self.desc) + return cuni(self.desc) class Note(PrimaryObject): note_type = models.ForeignKey('NoteType', verbose_name="Type") @@ -653,7 +654,7 @@ class Note(PrimaryObject): return tuple() def __unicode__(self): - return unicode(self.gramps_id) + return cuni(self.gramps_id) #--------------------------------------------------------------------------- # @@ -691,11 +692,11 @@ class Surname(models.Model): order = models.PositiveIntegerField() def __unicode__(self): - return unicode(self.surname) + return cuni(self.surname) def get_url(self): # /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.order) @@ -726,14 +727,14 @@ class Name(DateObject, SecondaryObject): surname = self.surname_set.get(primary=True) except: 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): try: surname = self.surname_set.get(primary=True) except: 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 def get_dummy(): @@ -757,7 +758,7 @@ class Name(DateObject, SecondaryObject): def get_url(self): # /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): """ @@ -889,7 +890,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 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_to.__class__.__name__.lower(), self.order) @@ -899,7 +900,7 @@ class Log(BaseRef): cache = models.TextField(blank=True, null=True) 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.last_changed, self.last_changed_by) @@ -911,14 +912,14 @@ class NoteRef(BaseRef): return self.ref_object def __unicode__(self): - return u"NoteRef to " + unicode(self.ref_object) + return cuni("NoteRef to ") + cuni(self.ref_object) class EventRef(BaseRef): ref_object = models.ForeignKey('Event') role_type = models.ForeignKey('EventRoleType') def __unicode__(self): - return unicode(self.ref_object) + return cuni(self.ref_object) def get_reference_to(self): return self.ref_object @@ -927,7 +928,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 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_to.__class__.__name__.lower(), self.order) @@ -941,7 +942,7 @@ class RepositoryRef(BaseRef): return self.ref_object def __unicode__(self): - return u"RepositoryRef to " + unicode(self.ref_object) + return cuni("RepositoryRef to ") + cuni(self.ref_object) class PersonRef(BaseRef): ref_object = models.ForeignKey('Person') @@ -951,13 +952,13 @@ class PersonRef(BaseRef): return self.ref_object def __unicode__(self): - return u"PersonRef to " + unicode(self.ref_object) + return cuni("PersonRef to ") + cuni(self.ref_object) class CitationRef(BaseRef): citation = models.ForeignKey('Citation') def __unicode__(self): - return u"CitationRef to " + unicode(self.citation) + return cuni("CitationRef to ") + cuni(self.citation) def get_reference_to(self): return self.citation @@ -974,10 +975,10 @@ class ChildRef(BaseRef): def get_url(self): # FIXME: go to child reference - return u"/person/%s" % self.ref_object.handle + return cuni("/person/%s") % self.ref_object.handle def __unicode__(self): - return u"ChildRef to " + unicode(self.ref_object) + return cuni("ChildRef to ") + cuni(self.ref_object) class MediaRef(BaseRef): x1 = models.IntegerField() @@ -990,7 +991,7 @@ class MediaRef(BaseRef): return self.ref_object def __unicode__(self): - return u"MediaRef to " + unicode(self.ref_object) + return cuni("MediaRef to ") + cuni(self.ref_object) class Report(models.Model): gramps_id = models.TextField(blank=True, null=True) @@ -1000,7 +1001,7 @@ class Report(models.Model): options = models.TextField(blank=True, null=True) def __unicode__(self): - return unicode(self.name) + return cuni(self.name) class Result(models.Model): name = models.TextField(blank=True, null=True) @@ -1010,7 +1011,7 @@ class Result(models.Model): status = models.TextField(blank=True, null=True) def __unicode__(self): - return unicode(self.name) + return cuni(self.name) TABLES = [ ("abstract", mGrampsType), diff --git a/gramps/webapp/utils.py b/gramps/webapp/utils.py index c0fb87e77..d65c85aad 100644 --- a/gramps/webapp/utils.py +++ b/gramps/webapp/utils.py @@ -54,6 +54,7 @@ import gramps.webapp.grampsdb.models as models import gramps.webapp.grampsdb.forms as forms from gramps.webapp import libdjango 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) import sys, traceback 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() return None @@ -250,18 +251,18 @@ class Table(object): self.table.set_link_col(links) def get_html(self): - retval = u"" + retval = cuni("") # 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 += u"" % self.doc.doc.style_declaration + retval += cuni("") % self.doc.doc.style_declaration # We have a couple of HTML bits that we want to unescape: - return retval + unicode(self.doc.doc.htmllist[0]).replace(" ", " ") + return retval + cuni(self.doc.doc.htmllist[0]).replace(" ", " ") def build_args(**kwargs): - retval = u"" + retval = cuni("") first = True for key in kwargs: if kwargs[key] is not "": @@ -270,7 +271,7 @@ def build_args(**kwargs): first = False else: retval += "&" - retval += u"%s=%s" % (key, kwargs[key]) + retval += cuni("%s=%s") % (key, kwargs[key]) return retval def build_search(request): @@ -280,8 +281,8 @@ def build_search(request): def make_button(text, url, *args): newargs = [] - kwargs = u"" - last = u"" + kwargs = cuni("") + last = cuni("") for arg in args: if isinstance(arg, STRTYPE) and arg.startswith("?"): kwargs = arg @@ -296,7 +297,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(u"""""" % + return mark_safe(cuni("""""") % (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" elif button == "add spouse to new family": filename = "/images/scalable/gramps-parents.svg" - return u"""""" % (text, text, filename, url, kwargs, last) + return cuni("""""") % (text, text, filename, url, kwargs, last) def event_table(obj, user, act, url, args): - retval = u"" + retval = cuni("") has_data = False cssid = "tab-events" table = Table("event_table") @@ -400,18 +401,18 @@ def event_table(obj, user, act, url, args): djevent.gramps_id, display_date(djevent), get_title(djevent.place), - unicode(event_ref.role_type)) + cuni(event_ref.role_type)) links.append(('URL', event_ref.get_url())) has_data = True count += 1 table.links(links) - retval += u"""
No such name order = %s
" % order + retval += cuni("No such name order = %s
") % order if has_data: - retval += u""" \n""" % cssid + retval += cuni(""" \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 = u"" + retval = cuni("") has_data = False cssid = "tab-sources" table = Table("citation_table") @@ -556,8 +557,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, - unicode(citation.confidence), - unicode(citation.page), + cuni(citation.confidence), + cuni(citation.page), ) links.append(('URL', citation_ref.get_url())) has_data = True @@ -577,16 +578,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", 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))) + 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("^", cuni("/%s/%s/up/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 if has_data: - retval += u""" \n""" % cssid + retval += cuni(""" \n""") % cssid return retval def repository_table(obj, user, act, url=None, *args): - retval = u"" + retval = cuni("") has_data = False cssid = "tab-repositories" table = Table("repository_table") @@ -617,7 +618,7 @@ def repository_table(obj, user, act, url=None, *args): repository.gramps_id, repository.name, repo_ref.call_number, - unicode(repository.repository_type), + cuni(repository.repository_type), ) has_data = True count += 1 @@ -627,17 +628,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", 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))) + 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("^", cuni("/%s/%s/up/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 retval += text if has_data: - retval += u""" \n""" % cssid + retval += cuni(""" \n""") % cssid return retval def note_table(obj, user, act, url=None, *args): - retval = u"" + retval = cuni("") has_data = False cssid = "tab-notes" table = Table("note_table") @@ -657,7 +658,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, - unicode(note.note_type), + cuni(note.note_type), note.text[:50] ) links.append(('URL', note_ref.get_url())) @@ -678,17 +679,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", 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))) + 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("^", cuni("/%s/%s/up/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 retval += text if has_data: - retval += u""" \n""" % cssid + retval += cuni(""" \n""") % cssid return retval def data_table(obj, user, act, url=None, *args): - retval = u"" + retval = cuni("") has_data = False cssid = "tab-data" table = Table("data_table") @@ -729,9 +730,9 @@ def data_table(obj, user, act, url=None, *args): text = text.replace("}}", """""") count = 1 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("[[^%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))) + 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("^", cuni("/%s/%s/up/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 retval += text if has_data: @@ -739,7 +740,7 @@ def data_table(obj, user, act, url=None, *args): return retval def attribute_table(obj, user, act, url=None, *args): - retval = u"" + retval = cuni("") has_data = False cssid = "tab-attributes" table = Table("attribute_table") @@ -766,7 +767,7 @@ def attribute_table(obj, user, act, url=None, *args): return retval def address_table(obj, user, act, url=None, *args): - retval = u"" + retval = cuni("") has_data = False cssid = "tab-addresses" table = Table("address_table") @@ -797,7 +798,7 @@ def address_table(obj, user, act, url=None, *args): return retval def media_table(obj, user, act, url=None, *args): - retval = u"" + retval = cuni("") has_data = False cssid = "tab-media" 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_ref.ref_object.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) has_data = True retval += """