Exemplo n.º 1
0
    def test_gen_individual(self):
        birth_date = datetime.datetime(1980, 1, 1)
        death_date = datetime.datetime(2040, 1, 1)
        legal_name = LegalName(first_name="David", last_name="Schmidt")
        legal_name.save()
        birth_location = Location(city='New York', state='NY', country='US')
        birth_location.save()
        death_location = Location(city='Boston', state='MA', country='US')
        death_location.save()
        person = Person(
            legal_name=legal_name,
            gender="Male",
            birth_date=birth_date,
            birth_location=birth_location,
            death_date=death_date,
            death_location=death_location,
        )
        person.save()
        alternate_name = AlternateName(first_name='Lance',
                                       last_name='Springer',
                                       person=person)
        alternate_name.save()

        partner_partnership = Partnership()
        partner_partnership.save()

        person_partnership = PersonPartnership(person=person,
                                               partnership=partner_partnership)
        person_partnership.save()

        child_partnership = Partnership()
        child_partnership.save()
        child_partnership.children.add(person)

        ptr, individual = gedcom_generator.gen_individual(person)
        expected = gedcom_helpers.create_individual(
            f"@PERSON_{person.id}@",
            name="David Schmidt",
            sex='M',
            birth_place='New York, NY, US',
            birth_date=birth_date.strftime("%d %b %Y").upper(),
            death_place='Boston, MA, US',
            death_date=death_date.strftime("%d %b %Y").upper())
        expected.add_child_element(
            Element(1, '', tags.GEDCOM_TAG_NAME, 'Lance Springer'))
        expected.add_child_element(
            Element(1, '', tags.GEDCOM_TAG_GIVEN_NAME, 'David'))
        expected.add_child_element(
            Element(1, '', tags.GEDCOM_TAG_SURNAME, 'Schmidt'))
        expected.add_child_element(
            Element(1, '', tags.GEDCOM_TAG_FAMILY_SPOUSE,
                    f'@PARTNERSHIP_{partner_partnership.id}@'))
        expected.add_child_element(
            Element(1, '', tags.GEDCOM_TAG_FAMILY_CHILD,
                    f'@PARTNERSHIP_{child_partnership.id}@'))

        self.assertTrue(gedcom_helpers.element_equals(individual, expected))
Exemplo n.º 2
0
    def test_gen_same_sex_family(self):
        spouse_1_legal_name = LegalName(first_name="Betty")
        spouse_1_legal_name.save()
        spouse_1 = Person(legal_name=spouse_1_legal_name, gender='Female')
        spouse_1.save()
        spouse_2_legal_name = LegalName(first_name="Sally")
        spouse_2_legal_name.save()
        spouse_2 = Person(legal_name=spouse_2_legal_name, gender='Female')
        spouse_2.save()
        marriage_date = datetime.datetime(2000, 12, 1)
        divorce_date = datetime.datetime(2100, 12, 2)
        partnership = Partnership(
            marriage_date=marriage_date,
            divorce_date=divorce_date,
            marital_status=Partnership.MaritalStatus.MARRIED)
        partnership.save()
        person_partnership_1 = PersonPartnership(person=spouse_1,
                                                 partnership=partnership)
        person_partnership_1.save()
        person_partnership_2 = PersonPartnership(person=spouse_2,
                                                 partnership=partnership)
        person_partnership_2.save()

        ptr, family_element = gedcom_generator.gen_family(partnership)

        expected = gedcom_helpers.create_family(
            gedcom_helpers.gen_ptr(partnership),
            wife_ptrs=(gedcom_helpers.gen_ptr(spouse_1),
                       gedcom_helpers.gen_ptr(spouse_2)),
            marriage_date=gedcom_helpers.gedcom_date(marriage_date),
            divorce_date=gedcom_helpers.gedcom_date(divorce_date))

        self.assertTrue(gedcom_helpers.element_equals(family_element,
                                                      expected))
Exemplo n.º 3
0
    def test_gen_pointer(self):
        legal_name = LegalName(first_name="Chris")
        legal_name.save()
        legal_name_ptr = gedcom_helpers.gen_ptr(legal_name)
        self.assertEqual(legal_name_ptr, f"@LEGALNAME_{legal_name.pk}@")

        person = Person(legal_name=legal_name)
        person.save()
        person_ptr = gedcom_helpers.gen_ptr(person)
        self.assertEqual(person_ptr, f"@PERSON_{person.pk}@")

        partnership = Partnership()
        partnership.save()
        partnership_ptr = gedcom_helpers.gen_ptr(partnership)
        self.assertEqual(partnership_ptr, f"@PARTNERSHIP_{partnership.pk}@")
# Imports the supplied names into the Person table in the DB 
# supplied in the config
from webapp.models import Person

# CSV text
names = """DOE, JOHN
BESS, CHRISTOPHER
DOE, JANE"""

import_count = 0
skip_count = 0
# iterate names to import
for name in names.split('\n'):
    # normalize the name
    parts = name.split(',')
    name = parts[0].strip().title()
    if len(parts) >= 2:
        name = '%s %s' % (parts[1].strip().title(), name)
    # prevent duplicates
    if Person.objects(name=name).count():
        skip_count += 1
        continue
    person = Person(name=name)
    person.save()
    import_count += 1
    
print 'Imported %d persons, %d skipped. Total: %d' % \
    (import_count, skip_count, Person.objects.count())
    
Exemplo n.º 5
0
    def test_gen_file(self):
        user = User(username="******")
        user.save()
        tree = Tree(title="Test", creator=user)
        tree.save()
        spouse_1_legal_name = LegalName(first_name="Betty", tree=tree)
        spouse_1_legal_name.save()
        spouse_1 = Person(legal_name=spouse_1_legal_name,
                          gender='Female',
                          tree=tree)
        spouse_1.save()
        spouse_2_legal_name = LegalName(first_name="Kyle", tree=tree)
        spouse_2_legal_name.save()
        spouse_2 = Person(legal_name=spouse_2_legal_name,
                          gender='Male',
                          tree=tree)
        spouse_2.save()
        child_legal_name = LegalName(first_name="Symphony", tree=tree)
        child_legal_name.save()
        child = Person(legal_name=child_legal_name,
                       gender="Unknown",
                       tree=tree)
        child.save()
        marriage_date = datetime.datetime(2000, 12, 1)
        divorce_date = datetime.datetime(2100, 12, 2)
        partnership = Partnership(
            marriage_date=marriage_date,
            divorce_date=divorce_date,
            marital_status=Partnership.MaritalStatus.MARRIED,
            tree=tree)
        partnership.save()
        partnership.children.add(child)
        partnership.save()
        person_partnership_1 = PersonPartnership(person=spouse_1,
                                                 partnership=partnership)
        person_partnership_1.save()
        person_partnership_2 = PersonPartnership(person=spouse_2,
                                                 partnership=partnership)
        person_partnership_2.save()

        root = gedcom_generator.generate_file(tree)

        parser = Parser()
        parser.parse([])
        expected = parser.get_root_element()
        head_element, submitter_element = gedcom_generator.gen_head_and_submitter(
            tree)
        expected.add_child_element(head_element)
        expected.add_child_element(submitter_element)
        ptr, spouse_1_element = gedcom_generator.gen_individual(spouse_1)
        expected.add_child_element(spouse_1_element)
        ptr, spouse_2_element = gedcom_generator.gen_individual(spouse_2)
        expected.add_child_element(spouse_2_element)
        ptr, child_element = gedcom_generator.gen_individual(child)
        expected.add_child_element(child_element)
        ptr, family = gedcom_generator.gen_family(partnership)
        expected.add_child_element(family)

        self.assertTrue(gedcom_helpers.element_equals(root, expected))
Exemplo n.º 6
0
    def test_parse_family(self):
        legal_name_1 = LegalName(first_name='Spouse', last_name='1')
        legal_name_1.save()
        person_1 = Person(legal_name=legal_name_1)
        person_1.save()
        legal_name_2 = LegalName(first_name='Spouse', last_name='2')
        legal_name_2.save()
        person_2 = Person(legal_name=legal_name_2)
        person_2.save()
        legal_name_3 = LegalName(first_name='Child', last_name='1')
        legal_name_3.save()
        person_3 = Person(legal_name=legal_name_3)
        person_3.save()
        persons = {'@P1@': person_1, '@P2@': person_2, '@P3@': person_3}
        family_element = gedcom_helpers.create_family(
            '@F1@',
            husb_ptrs=('@P1@', ),
            wife_ptrs=('@P2@', ),
            child_ptrs=('@P3@', ),
            marriage_place="city, state, US",
            marriage_date='13 JAN 1900',
            divorce_date='14 JAN 1911')

        partnership = gedcom_parsing.parse_family(family_element, persons,
                                                  self.tree)
        partners = tuple(p for p in partnership.partners())
        self.assertEqual(partners, (person_1, person_2))
        children = tuple(c for c in partnership.children.all())
        self.assertEqual(children, (person_3, ))
        self.assertEqual(partnership.marriage_date, datetime.date(1900, 1, 13))
        self.assertEqual(partnership.divorce_date, datetime.date(1911, 1, 14))
Exemplo n.º 7
0
def save_person(request,
                current_tree,
                template_name,
                current_person: Person = None):
    if current_tree.creator == request.user:
        name_form = None
        person_form = None
        alt_name_formset = None

        if request.method == 'POST':
            # if this is a POST request we need to process the form data
            name_form = AddNameForm(
                request.POST,
                instance=current_person.legal_name if current_person else None)
            person_form = AddPersonForm(request.POST, instance=current_person)

            # Tuple that contains validation status of each filled form
            form_validations = (
                person_form.is_valid(),
                name_form.is_valid(),
            )

            # Create/Save instances if all forms are valid.
            if all(form_validations):
                # Create a Legal Name instance from name form's data

                created_legal_name = name_form.save(commit=False)
                created_legal_name.tree = current_tree
                created_legal_name.save()

                if not current_person:
                    # Create a Person instance from person form's data
                    # Person instance's Legal Name attribute will be a foreign key
                    current_person = person_form.save(commit=False)
                    current_person.tree = current_tree
                    current_person.legal_name = created_legal_name
                    current_person.save()

                # Create Alternate Name for person
                alt_name_formset = AlternateNameFormSet(
                    request.POST, instance=current_person)
                if alt_name_formset.is_valid():
                    alt_names = alt_name_formset.save(commit=False)
                    for alt_name in alt_names:
                        alt_name.tree = current_tree
                        alt_name.save()

                # Check each location form's data and query for existing Location
                # instances.
                # If location exists, stores it in the corresponding location
                # variable and sets location_created boolean to false
                # If it doesn't exist, create a new instance from form's data and
                # set location_created boolean to true
                birth_location, birth_loc_was_created = Location.objects.get_or_create(
                    city=person_form.cleaned_data['birth_city'],
                    state=person_form.cleaned_data['birth_state'],
                    country=person_form.cleaned_data['birth_country'])

                death_location, death_loc_was_created = Location.objects.get_or_create(
                    city=person_form.cleaned_data['death_city'],
                    state=person_form.cleaned_data['death_state'],
                    country=person_form.cleaned_data['death_country'])

                # if new location instances were created, save them in the DB
                if birth_loc_was_created:
                    birth_location.save()

                if death_loc_was_created:
                    death_location.save()

                # Assign the location instances as keys in Person instance
                current_person.birth_location = birth_location
                current_person.death_location = death_location

                current_person.save()

                # redirect to back to the Tree detail page that
                # Person was created in
                return redirect('tree_detail', pk=current_person.tree.id)

        # if a GET (or any other method) we'll create a blank form
        if current_person:
            name_form = name_form or AddNameForm(
                instance=current_person.legal_name)
            initial_data = dict()
            if current_person.birth_location:
                initial_data.update({
                    'birth_city':
                    current_person.birth_location.city,
                    'birth_state':
                    current_person.birth_location.state,
                    'birth_country':
                    current_person.birth_location.country,
                })
            if current_person.death_location:
                initial_data.update({
                    'death_city':
                    current_person.death_location.city,
                    'death_state':
                    current_person.death_location.state,
                    'death_country':
                    current_person.death_location.country
                })
            person_form = person_form or AddPersonForm(instance=current_person,
                                                       initial=initial_data)
            alt_name_formset = alt_name_formset or AlternateNameFormSet()
        else:
            name_form = name_form or AddNameForm()
            person_form = person_form or AddPersonForm()
            alt_name_formset = alt_name_formset or AlternateNameFormSet()

        context = {
            'name_form': name_form,
            'person_form': person_form,
            'alt_name_formset': alt_name_formset,
        }

        return render(request, template_name, context)

    else:
        raise Http404
Exemplo n.º 8
0
    email = CharField()
    is_admin = IntegerField()
    name = CharField()
    password = CharField()

    class Meta:
        db_table = 'user'


sqlite_db.connect()

## Ad-hoc migration

# move all persons
for person in LegacyPerson.select():
    if Person.objects(name=person.name).count():
        continue
    Person(name=person.name).save()
    print 'Migrated Person: '+person.name

# move all users
for user in LegacyUser.select():
    if User.objects(name=user.name).count():
        continue
    # transfer user data
    User(
        name=user.name,
        email=user.email,
        password=user.password,
        is_admin=bool(user.is_admin)
    ).save()
Exemplo n.º 9
0
def parse_individual(element: IndividualElement, tree):
    child = Person()

    # get names from element
    names = list(get_names(element))

    # save legal name
    # assumes first name in list is primary name
    legal_name = LegalName()
    parse_name_dict(names[0], legal_name)
    legal_name.tree = tree
    legal_name.save()
    child.legal_name = legal_name

    # save alternate names
    for name_dict in names[1:]:
        alternate_name = AlternateName()
        parse_name_dict(name_dict, alternate_name)
        alternate_name.person = child
        alternate_name.tree = tree
        alternate_name.save()

    child.gender = parse_gender(get_value(element, tags.GEDCOM_TAG_SEX))

    # Is saving related models necessary, or will it cascade?
    birth_event_element = get_next_child_element(element,
                                                 tags.GEDCOM_TAG_BIRTH)
    if birth_event_element:
        child.birth_date = parse_event_date(birth_event_element)
        child.birth_location = parse_event_location(birth_event_element)

    death_event_element = get_next_child_element(element,
                                                 tags.GEDCOM_TAG_DEATH)
    if death_event_element:
        child.death_date = parse_event_date(death_event_element)
        child.death_location = parse_event_location(death_event_element)
        child.living = 'Dead'

    # living defaults to Unknown; change to living = has birth year and not has death year?

    child.tree = tree

    child.save()

    return element.get_pointer(), child
Exemplo n.º 10
0
# Imports the supplied names into the Person table in the DB
# supplied in the config
from webapp.models import Person

# CSV text
names = """DOE, JOHN
BESS, CHRISTOPHER
DOE, JANE"""

import_count = 0
skip_count = 0
# iterate names to import
for name in names.split('\n'):
    # normalize the name
    parts = name.split(',')
    name = parts[0].strip().title()
    if len(parts) >= 2:
        name = '%s %s' % (parts[1].strip().title(), name)
    # prevent duplicates
    if Person.objects(name=name).count():
        skip_count += 1
        continue
    person = Person(name=name)
    person.save()
    import_count += 1

print 'Imported %d persons, %d skipped. Total: %d' % \
    (import_count, skip_count, Person.objects.count())