예제 #1
0
def internet_table(form, user, action):
    retval = ""
    has_data = False
    cssid = "tab-internet"
    table = Table(form)
    table.set_columns(
        ("", 11),
        (form._("Type"), 19),
        (form._("Path"), 35),
        (form._("Description"), 35),
    )
    s = Struct.wrap(form.instance, form.database)
    count = 1
    for url in s.urls:
        table.append_row(url.type.string,
                         url.path,
                         url.desc,
                         link="/%s/%s/url/%s" %
                         (form.view, form.instance.handle, count))
        has_data = True
        count += 1
    retval += """<div style="background-color: lightgray; padding: 2px 0px 0px 2px">"""
    if user and action == "view":
        retval += make_icon_button(form._("Add Internet"), "FIXME", icon="+")
    else:
        retval += nbsp("")  # to keep tabs same height
    retval += """</div>"""
    retval += table.get_html(action)
    if has_data:
        retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
    return retval
예제 #2
0
def event_table(form, user, action):
    retval = ""
    has_data = False
    cssid = "tab-events"
    table = Table(form, "eventref", "event")
    event = Event()
    eventref = EventRef()
    table.set_columns(
        ("", 11),
        (event.get_label("description", form._), 19),
        (event.get_label("type", form._), 10),
        (event.get_label("gid", form._), 11),
        (event.get_label("date", form._), 20),
        (event.get_label("place", form._), 19),
        (eventref.get_label("role", form._), 10),
    )
    s = Struct.wrap(form.instance, form.database)
    count = 0
    for event_ref in s.event_ref_list:  # eventrefs
        event = event_ref.ref
        table.append_row(event.description,
                         event.type.string,
                         event.gid,
                         event.date.text,
                         event.place.name.value,
                         event_ref.role.string,
                         link="/event/%s" % event.instance.handle)
        has_data = True
        count += 1
    retval += """<div style="background-color: lightgray; padding: 2px 0px 0px 2px"/>"""
    if action == "view":
        retval += make_icon_button(form._("Add New Event to %s" % form.table),
                                   "/%s/%s/eventref/add" %
                                   (form.view, form.instance.handle),
                                   icon="+")  # )
        retval += make_icon_button(
            form._("Add Existing Event to %s" % form.table),
            "/%s/%s/eventref/share" % (form.view, form.instance.handle),
            icon="p")  # )
    else:
        retval += """&nbsp;"""  # to keep tabs same height
    retval += """</div>"""
    retval += table.get_html(action)
    #if act == "view":
    #count = 1
    #retval = retval.replace("{{", """<div style="background-color: lightgray; padding: 2px 0px 0px 2px">""")
    #retval = retval.replace("}}", """</div>""")
    #for (djevent, event_ref) in event_list:
    #    item = form.instance.__class__.__name__.lower()
    #    retval = retval.replace("[[x%d]]" % count, make_icon_button("x", "/%s/%s/remove/eventref/%d" % (item, form.instance.handle, count)))
    #    retval = retval.replace("[[^%d]]" % count, make_icon_button("^", "/%s/%s/up/eventref/%d" % (item, form.instance.handle, count)))
    #    retval = retval.replace("[[v%d]]" % count, make_icon_button("v", "/%s/%s/down/eventref/%d" % (item, form.instance.handle, count)))
    #    count += 1
    if has_data:
        retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
    return retval
예제 #3
0
 def test(self):
     family = db.get_family_from_gid("F0001")
     s = Struct(family.to_struct(), db)
     self.assertEqual(s["gid"], "F0001")
     s["gid"] = "TEST"
     self.assertEqual(s["gid"], "TEST")
     self.assertEqual(s.father_handle.primary_name.first_name,
                      "Allen Carl")
     s["father_handle.primary_name.first_name"] = "Edward"
     self.assertEqual(s["father_handle.primary_name.first_name"],
                      "Edward")
예제 #4
0
def event_table(form, user, action):
    retval = ""
    has_data = False
    cssid = "tab-events"
    table = Table(form)  # form, link-name
    event = Event()
    eventref = EventRef()
    table.set_columns(
        ("", 11),
        (event.get_label("description", form._), 19),
        (event.get_label("type", form._), 10),
        (event.get_label("gid", form._), 11),
        (event.get_label("date", form._), 20),
        (event.get_label("place", form._), 19),
        (eventref.get_label("role", form._), 10),
    )
    s = Struct.wrap(form.instance, form.database)
    count = 1
    for event_ref in s.event_ref_list:  # eventrefs
        event = event_ref.ref
        table.append_row(event.description,
                         event.type.string,
                         event.gid,
                         event.date.text,
                         event.place.name.value,
                         event_ref.role.string,
                         edit="event_ref_list/%s" % (count),
                         goto=form.make_url("event_ref_list", count))
        has_data = True
        count += 1
    retval += """<div style="background-color: lightgray; padding: 2px 0px 0px 2px"/>"""
    if action == "view":
        if form.handler.app.can_add(user):
            retval += form.make_icon_button(form._("Add New Event"),
                                            "/%s/%s/event_ref_list/add" %
                                            (form.view, form.instance.handle),
                                            icon="+")
        else:
            retval += """&nbsp;"""  # to keep tabs same height
        if form.handler.app.can_edit(user):
            retval += form.make_icon_button(form._("Share Existing Event"),
                                            "/%s/%s/event_ref_list/share" %
                                            (form.view, form.instance.handle),
                                            icon="p")
        else:
            retval += """&nbsp;"""  # to keep tabs same height
    else:
        retval += """&nbsp;"""  # to keep tabs same height
    retval += """</div>"""
    retval += table.get_html(action)
    if has_data:
        retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
    return retval
예제 #5
0
def note_table(form, user, action):
    retval = ""
    has_data = False
    cssid = "tab-notes"
    table = Table(form)
    table.set_columns(
        ("", 11),
        (form._("ID"), 10),
        (form._("Type"), 20),
        (form._("Note"), 59),
    )
    if user or form.instance.public:
        notes = Struct.wrap(form.instance, form.database).note_list
        links = []
        count = 1
        for note in notes:
            table.append_row(note.gid,
                             str(note.type.string),
                             note.text.string[:50],
                             link="/note/%s" % note.instance.handle)
            has_data = True
            count += 1
    retval += """<div style="background-color: lightgray; padding: 2px 0px 0px 2px">"""
    if user and action == "view":
        retval += make_icon_button(form._("Add New Note"), "FIXME", icon="+")
        retval += make_icon_button(form._("Add Existing Note"),
                                   "FIXME",
                                   icon="p")
    else:
        retval += nbsp("")  # to keep tabs same height
    retval += """</div>"""
    text = table.get_html(action)
    text = text.replace(
        "{{",
        """<div style="background-color: lightgray; padding: 2px 0px 0px 2px">"""
    )
    text = text.replace("}}", """</div>""")
    retval += text
    if has_data:
        retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
    return retval
예제 #6
0
def association_table(form, user, action):
    retval = ""
    has_data = False
    cssid = "tab-association"
    table = Table(form)
    table.set_columns(
        ("", 11),
        (form._("Name"), 40),
        (form._("ID"), 10),
        (form._("Association"), 39),
    )
    retval += """<div style="background-color: lightgray; padding: 2px 0px 0px 2px">"""
    if user and action == "view":
        if form.handler.app.can_add(user):
            retval += form.make_icon_button(form._("Add Association"),
                                            "/%s/%s/person_ref_list/add" %
                                            (form.view, form.instance.handle),
                                            icon="+")
        else:
            retval += """&nbsp;"""  # to keep tabs same height
    else:
        retval += nbsp("")  # to keep tabs same height
    retval += """</div>"""
    if user or form.instance.public:
        s = Struct.wrap(form.instance, form.database)
        count = 1
        for personref in s.person_ref_list:
            table.append_row(name_display(personref.ref.instance),
                             personref.ref.gid,
                             personref.rel,
                             edit="person_ref_list/%s" % count,
                             goto=form.make_url("person_ref_list", count))
            has_data = True
            count += 1
        text = """<div style="background-color: lightgray; padding: 2px 0px 0px 2px">"""
        text += """</div>"""
        text += table.get_html(action)
        retval += text
    if has_data:
        retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
    return retval
예제 #7
0
def lds_table(form, user, action):
    retval = ""
    has_data = False
    cssid = "tab-lds"
    table = Table(form)
    table.set_columns(
        ("", 11),
        (form._("Type"), 10),
        (form._("Date"), 19),
        (form._("Status"), 10),
        (form._("Temple"), 20),
        (form._("Place"), 30),
    )
    s = Struct.wrap(form.instance, form.database)
    count = 1
    if user or form.instance.public:
        for lds in s.lds_ord_list:
            date = lds.date.instantiate()
            table.append_row(lds.type,
                             date_display(date) if date else "",
                             lds.status,
                             lds.temple,
                             lds.place.title,
                             link="/person/%s/lds/%s" %
                             (form.instance.handle, count))
            has_data = True
            count += 1
    retval += """<div style="background-color: lightgray; padding: 2px 0px 0px 2px">"""
    if user and action == "view":
        retval += make_icon_button(form._("Add LDS"), "FIXME", icon="+")
    else:
        retval += nbsp("")  # to keep tabs same height
    retval += """</div>"""
    retval += table.get_html(action)
    if has_data:
        retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
    return retval
예제 #8
0
def address_table(
    form, user, action
):  #TODO: Make table customizable (For instance, if user desires to display counties or lat/long)
    retval = ""
    has_data = False
    cssid = "tab-addresses"
    table = Table(form)
    table.set_columns(
        ("", 11),
        (form._("Date"), 15),
        (form._("Address"), 29),
        (form._("City"), 15),
        (form._("State"), 15),
        (form._("Country"), 15),
    )
    s = Struct.wrap(form.instance, form.database)
    count = 1
    for address in s.address_list:
        table.append_row(address.date.text,
                         address.location.street,
                         address.location.city,
                         address.location.state,
                         address.location.country,
                         link="/%s/%s/address/%s" %
                         (form.view, form.instance.handle, count))
        has_data = True
        count += 1
    retval += """<div style="background-color: lightgray; padding: 2px 0px 0px 2px">"""
    if user and action == "view":
        retval += make_icon_button(form._("Add Address"), "FIXME", icon="+")
    else:
        retval += nbsp("")  # to keep tabs same height
    retval += """</div>"""
    retval += table.get_html(action)
    if has_data:
        retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
    return retval
예제 #9
0
def person_reference_table(form, user, action):
    from gprime.simple import SimpleAccess
    sa = SimpleAccess(form.database)
    retval = ""
    has_data = False
    cssid = "tab-references"
    text1 = ""
    text2 = ""
    table1 = Table(form, style="background-color: #f4f0ec;")
    table1.set_columns(
        (form._("As Spouse"), 11),
        (form._("ID"), 10),
        (form._("Reference"), 79),
    )
    table2 = Table(form, style="background-color: #f4f0ec;")
    table2.set_columns(
        (form._("As Child"), 11),
        (form._("ID"), 10),
        (form._("Reference"), 79),
    )
    if (user or form.instance.public) and action != "add":
        s = Struct.wrap(form.instance, form.database)
        count = 1
        for family in s.family_list:
            table1.append_row(family.gid,
                              sa.describe(family.instance),
                              goto=form.handler.app.make_url(
                                  family.instance.make_url()),
                              edit="family_list/%s" % count)
            has_data = True
            count += 1
        count = 1
        for family in s.parent_family_list:
            table2.append_row(family.gid,
                              sa.describe(family.instance),
                              goto=form.handler.app.make_url(
                                  family.instance.make_url()),
                              edit="parent_family_list/%s" % count)
            has_data = True
            count += 1
        text1 = """<div style="background-color: lightgray; padding: 2px 0px 0px 2px">"""
        if user and action == "view":
            text1 += form.make_icon_button(
                form._("Add as Spouse to New Family"),
                "/family/%s/parent_family_list/add" % (form.instance.handle),
                icon="+")
            text1 += form.make_icon_button(
                form._("Add as Spouse to Existing Family"),
                "/family/%s/parent_family_list/share" % (form.instance.handle),
                icon="p")
        else:
            text1 += nbsp("")  # to keep tabs same height
        text1 += """</div>"""
        text1 += table1.get_html(action, tab_height="100%")
        text2 = """<div style="background-color: lightgray; padding: 2px 0px 0px 2px">"""
        if user and action == "view":
            text2 += form.make_icon_button(
                form._("Add as Child to New Family"),
                "/family/%s/family_list/add" % (form.instance.handle),
                icon="+")
            text2 += form.make_icon_button(
                form._("Add as Child to Existing Family"),
                "/family/%s/family_list/share" % (form.instance.handle),
                icon="p")
        else:
            text2 += nbsp("")  # to keep tabs same height
        text2 += """</div>"""
        text2 += table2.get_html(action, tab_height="100%")

    retval += """<div style="overflow: auto; height:%spx;">""" % TAB_HEIGHT
    retval += text1 + text2
    retval += "</div>"
    if has_data:
        retval += """ <SCRIPT LANGUAGE="JavaScript">setHasData("%s", 1)</SCRIPT>\n""" % cssid
    return retval
예제 #10
0
 def render(self, field, user, action, js=None, _class=None, link=None, **kwargs):
     from gprime.lib.handle import HandleClass
     from gprime.lib.struct import Struct
     from gprime.lib.grampstype import GrampsType
     from gprime.lib.date import Date
     from gprime.lib.gendertype import GenderType
     # Handle any special field by name:
     if field == "gender":
         data = GenderType(self.instance.get_field(field, self.database))
     else:
         data = self.instance.get_field(field, self.database)
     field_name = field
     if action == "edit" and field not in self.edit_fields:
         self.log.warning("You are trying to edit field '%s', but it is NOT in the edit_fields list: %s" % (field, self.edit_fields))
     if isinstance(data, HandleClass):
         ## We have a handle
         if data.classname == "Person":
             return self.describe_person_from_handle(data, {})
     elif isinstance(data, (list, tuple)): ## Tags or rect
         if len(data) == 4 and all([isinstance(item, int) for item in data]): # rect
             return str(data)
         s = Struct.wrap(self.instance, self.database)
         data = s.getitem_from_path(field.split("."))
         ## a list of handles
         _class = """class ="%s" """ % _class if _class else ""
         if action == "edit":
             retval = """<select multiple="multiple" name="%s" id="id_%s" style="width: 100%%; height: 100%%" %s>""" % (field_name, field, _class)
         else:
             url = self.handler.app.make_url("/tag/")
             retval = """<select multiple="multiple" name="%s" id="id_%s" style="width: 100%%; height: 100%%" onclick="location = &quot;%s&quot; + this.value;" %s>""" % (field_name, field, url, _class)
         tags = set()
         for item in data:
             ## Tags:
             name = item.name
             handle = item.instance.handle
             retval += """<option value="%s" selected>%s</option>""" % (handle, name)
             tags.add(handle)
         if action == "edit":
             for tag in self.database.Tag.select():
                 if tag.handle not in tags:
                     retval += """<option value="%s">%s</option>""" % (tag.handle, tag.name)
         retval += "</select>"
     elif isinstance(data, bool): # Booleans (private, probably alive)
         env = {
             "field": field,
             "field_name": field_name,
             "checked": "checked" if data else "",
             "disabled": "" if action == "edit" else "disabled",
             "_class": """class ="%s" """ % _class if _class else "",
         }
         return """<input type="checkbox" %(checked)s id="id_%(field)s" %(disabled)s name="%(field_name)s" %(_class)s></input>""" % env
     elif isinstance(data, Date):
         if action == "edit":
             env = {
                 "field": field,
                 "field_name": field_name,
                 "value": dd(data),
                 "disabled": "" if action == "edit" else "disabled",
                 "_class": """class ="%s" """ % _class if _class else "",
             }
             return """<input type="text" id="id_%(field)s" %(disabled)s name="%(field_name)s" value="%(value)s" %(_class)s></input>""" % env
         else:
             return dd(data)
     elif isinstance(data, GrampsType):
         env = {
             "field": field,
             "field_name": field_name,
             "disabled": "" if action == "edit" else "disabled",
             "_class": """class ="%s" """ % _class if _class else "",
         }
         retval = """<select name="%(field_name)s" %(disabled)s id="id_%(field)s" style="width: 100%%" %(_class)s>""" % env
         for option in data._DATAMAP:
             env["selected"] = "selected" if option[0] == data.value else ""
             env["value"] = option[0] # number
             env["string"] = option[1] # translated
             retval += """<option value="%(value)s" %(selected)s>%(string)s</option>""" % env
         retval += "</select>"
     else: # text field
         retval = data
         if action in ["edit", "add"]:
             id = js if js else "id_" + field
             dict = {"id": id,
                     "name": field,
                     "field_name": field_name,
                     "value": retval,
                     "_class": """class ="%s" """ % _class if _class else "",
             }
             retval = """<input id="%(id)s" type="text" name="%(field_name)s" value="%(value)s" style="display:table-cell; width:100%%" %(_class)s></input>""" % dict
     if link and action == "view":
         # First, make sure all kwargs are strings:
         if kwargs:
             for key in kwargs:
                 kwargs[key] = str(kwargs[key])
             # Render the link:
             retval = '''<a href="''' +  (self.handler.app.make_url(link % kwargs)) + '''">''' + str(retval) + """</a>"""
     return str(retval)