Пример #1
0
def _load_event(loader: _Loader, element: ElementTree.Element):
    handle = element.get('handle')
    event_id = element.get('id')
    gramps_type = _xpath1(element, './ns:type')

    try:
        event_type = _EVENT_TYPE_MAP[gramps_type.text]
    except KeyError:
        event_type = UnknownEventType()
        logging.getLogger().warning(
            'Betty is unfamiliar with Gramps event "%s"\'s type of "%s". The event was imported, but its type was set to "%s".' % (event_id, gramps_type.text, event_type.label))

    event = IdentifiableEvent(event_id, event_type)

    event.date = _load_date(element)

    # Load the event place.
    place_handle_element = _xpath1(element, './ns:place')
    if place_handle_element is not None:
        event.place = loader._places[place_handle_element.get('hlink')]

    # Load the description.
    description_element = _xpath1(element, './ns:description')
    if description_element is not None:
        event.description = description_element.text

    _load_objref(loader, event, element)
    _load_citationref(loader, event, element)
    _load_attribute_privacy(event, element, 'attribute')
    loader._events[handle] = event
Пример #2
0
def _parse_event(ancestry: _IntermediateAncestry, element: Element):
    handle = str(_xpath1(element, './@handle'))
    event_id = _xpath1(element, './@id')
    gramps_type = _xpath1(element, './ns:type')

    try:
        event_type = _EVENT_TYPE_MAP[gramps_type.text]
    except KeyError:
        event_type = UnknownEventType()
        logging.getLogger().warning(
            'Betty is unfamiliar with Gramps event "%s"\'s type of "%s". The event was imported, but its type was set to "%s".'
            % (event_id, gramps_type.text, event_type.label))

    event = IdentifiableEvent(event_id, event_type)

    event.date = _parse_date(element)

    # Parse the event place.
    place_handle = _xpath1(element, './ns:place/@hlink')
    if place_handle:
        event.place = ancestry.places[place_handle]

    # Parse the description.
    description_element = _xpath1(element, './ns:description')
    if description_element is not None:
        event.description = description_element.text

    _parse_objref(ancestry, event, element)
    _parse_citationref(ancestry, event, element)
    _parse_attribute_privacy(event, element, 'attribute')
    ancestry.events[handle] = event
Пример #3
0
 def test_event_should_encode_full(self):
     event = IdentifiableEvent('the_event', Birth())
     event.date = DateRange(Date(2000, 1, 1), Date(2019, 12, 31))
     event.place = Place('the_place', [PlaceName('The Place')])
     Presence(Person('the_person'), Subject(), event)
     event.citations.append(
         IdentifiableCitation('the_citation', Source('The Source')))
     expected = {
         '$schema': '/schema.json#/definitions/event',
         '@context': {
             'place': 'https://schema.org/location',
         },
         '@type': 'https://schema.org/Event',
         'id': 'the_event',
         'type': 'birth',
         'presences': [
             {
                 '@context': {
                     'person': 'https://schema.org/actor',
                 },
                 'role': 'subject',
                 'person': '/en/person/the_person/index.json',
             },
         ],
         'citations': [
             '/en/citation/the_citation/index.json',
         ],
         'date': {
             'start': {
                 'year': 2000,
                 'month': 1,
                 'day': 1,
             },
             'end': {
                 'year': 2019,
                 'month': 12,
                 'day': 31,
             },
         },
         'place': '/en/place/the_place/index.json',
         'links': [
             {
                 'url': '/en/event/the_event/index.json',
                 'relationship': 'canonical',
                 'mediaType': 'application/json',
             },
             {
                 'url': '/nl/event/the_event/index.json',
                 'relationship': 'alternate',
                 'locale': 'nl-NL',
             },
             {
                 'url': '/en/event/the_event/index.html',
                 'relationship': 'alternate',
                 'mediaType': 'text/html',
             },
         ],
     }
     self.assert_encodes(expected, event, 'event')
Пример #4
0
 def test_event_should_encode_full(self):
     event = IdentifiableEvent('the_event', Event.Type.BIRTH)
     event.date = DateRange(Date(2000, 1, 1), Date(2019, 12, 31))
     event.place = Place('the_place', [LocalizedName('The Place')])
     Presence(Person('the_person'), Presence.Role.SUBJECT, event)
     event.citations.append(
         Citation('the_citation', Source('the_source', 'The Source')))
     expected = {
         '$schema':
         '/schema.json#/definitions/event',
         '@context': {
             'place': 'https://schema.org/location',
         },
         '@type':
         'https://schema.org/Event',
         'id':
         'the_event',
         'type':
         Event.Type.BIRTH.value,
         'presences': [
             {
                 '@context': {
                     'person': 'https://schema.org/actor',
                 },
                 'role': Presence.Role.SUBJECT.value,
                 'person': '/person/the_person/index.json',
             },
         ],
         'citations': [
             '/citation/the_citation/index.json',
         ],
         'date': {
             'start': {
                 'year': 2000,
                 'month': 1,
                 'day': 1,
             },
             'end': {
                 'year': 2019,
                 'month': 12,
                 'day': 31,
             },
         },
         'place':
         '/place/the_place/index.json',
     }
     self.assert_encodes(expected, event, 'event')
Пример #5
0
def _parse_event(ancestry: _IntermediateAncestry, element: Element):
    handle = str(_xpath1(element, './@handle'))
    gramps_type = _xpath1(element, './ns:type')

    event = IdentifiableEvent(_xpath1(element, './@id'), _EVENT_TYPE_MAP[gramps_type.text])

    event.date = _parse_date(element)

    # Parse the event place.
    place_handle = _xpath1(element, './ns:place/@hlink')
    if place_handle:
        event.place = ancestry.places[place_handle]

    # Parse the description.
    description_element = _xpath1(element, './ns:description')
    if description_element is not None:
        event.description = description_element.text

    _parse_objref(ancestry, event, element)
    _parse_citationref(ancestry, event, element)
    _parse_attribute_privacy(event, element)
    ancestry.events[handle] = event
Пример #6
0
 def test_date(self):
     sut = IdentifiableEvent('1', Birth())
     self.assertIsNone(sut.date)
     date = Mock(Date)
     sut.date = date
     self.assertEquals(date, sut.date)
Пример #7
0
 def test_date(self):
     sut = IdentifiableEvent('1', Event.Type.BIRTH)
     self.assertIsNone(sut.date)
     date = Mock(Date)
     sut.date = date
     self.assertEquals(date, sut.date)