Ejemplo n.º 1
0
def add_new_family_record(families, family_id, parents, kid):
    if family_id in families:
        if kid:
            families[family_id].kids.append(kid)
    else:
        families[family_id] = Family(parents, [kid]) if kid else Family(
            parents, [])
Ejemplo n.º 2
0
    def setUp(self):
        self.ind_1 = Individual.Individual("01")
        self.ind_2 = Individual.Individual("02")
        self.ind_3 = Individual.Individual("03")

        self.fam_1 = Family.Family("01")
        self.fam_2 = Family.Family("02")
Ejemplo n.º 3
0
    def tearDown(self):
        self.ind_1 = Individual.Individual("01")
        self.ind_2 = Individual.Individual("02")
        self.ind_3 = Individual.Individual("03")

        self.fam_1 = Family.Family("01")
        self.fam_2 = Family.Family("02")
Ejemplo n.º 4
0
    def test_fewer_than_15_siblings(self):
        husband: Individual = Individual(_id="I0")
        wife: Individual = Individual(_id="I1")
        child1: Individual = Individual(_id="I2")
        child2: Individual = Individual(_id="I3")
        child3: Individual = Individual(_id="I4")
        child4: Individual = Individual(_id="I5")
        child5: Individual = Individual(_id="I6")
        child6: Individual = Individual(_id="I7")
        child7: Individual = Individual(_id="I8")
        child8: Individual = Individual(_id="I9")
        child9: Individual = Individual(_id="I10")
        child10: Individual = Individual(_id="I12")
        child11: Individual = Individual(_id="I13")
        child12: Individual = Individual(_id="I14")
        child13: Individual = Individual(_id="I15")
        child14: Individual = Individual(_id="I16")
        child15: Individual = Individual(_id="I17")
        family: Family = Family(husb=husband.id, wife=wife.id)
        family.chil.extend([
            child1.id, child2.id, child3.id, child4.id, child5.id, child6.id,
            child7.id, child8.id, child9.id, child10.id, child11.id,
            child12.id, child13.id, child14.id, child15.id
        ])
        self.assertFalse(us.fewer_than_15_siblings(family))

        family: Family = Family(husb=husband.id, wife=wife.id)
        family.chil.extend(
            [child1.id, child2.id, child3.id, child4.id, child5.id, child6.id])
        self.assertTrue(us.fewer_than_15_siblings(family))
Ejemplo n.º 5
0
def populate_crops():
    for common_name in CROPS:
        common_name = common_name
        family = CROPS[common_name][0]
        genus = CROPS[common_name][1]
        species = CROPS[common_name][2]

        existing_family = Family.objects.filter(name=family)
        if existing_family.count() > 0:
            print "    Family ", family, " already exists in database."
            existing_family = existing_family[0]
        else:
            f = Family(name=family)
            f.save()
            existing_family = f
            print "    Saved", family, "as Family."

        existing_genus = Genus.objects.filter(name=genus)
        if existing_genus.count() > 0:
            print "    Genus ", genus, " already exists in database."
            existing_genus = existing_genus[0]
        else:
            g = Genus(name=genus, family=existing_family)
            g.save()
            existing_genus = g
            print "    Saved", genus, "as Genus."

        existing_species = Species.objects.filter(species=species, genus=existing_genus)
        if existing_species.count() > 0:
            print "    Species ", species, " already exists in database."
            existing_species = existing_species[0]
        else:
            s = Species(species=species, genus=existing_genus)
            s.save()
            existing_species = s
            print "    Saved", species, "as Species."

        existing_crop = Crop.objects.filter(species=existing_species)
        if existing_crop.count() > 0:
            print "    Crop ", common_name, " already exists in database."
            existing_crop = existing_crop[0]
        else:
            c = Crop(species=existing_species)
            c.save()
            existing_crop = c
            print "    Saved", common_name, "as Crop."

        existing_common_name = CommonName.objects.filter(crop=existing_crop, name=common_name)
        if existing_common_name.count() > 0:
            print "    Common name for ", species, " already exists in database."
            existing_common_name = existing_common_name[0]
        else:
            cn = CommonName(crop=existing_crop, name=common_name, preferred=True)
            cn.save()
            existing_common_name = cn
            print "    Saved", common_name, " for ", species, "as CommonName."
Ejemplo n.º 6
0
def populate_families():
    for name in FAMILIES:
        existing_family = Family.objects.filter(name=name)

        if existing_family.count() > 0:
            print "    Family ", name, " already exists in database."
        else:
            f = Family(name=name)
            f.save()
            print "    Saved", name, "as Family."
Ejemplo n.º 7
0
    def test_were_parents_over_14(self):
        """ test were_parents_over_14 method """
        # husband is 20 and wife is 14 at the marriage date -> Both are over 14 -> True
        husband: Individual = Individual(_id="I0",
                                         birt={'date': "19 SEP 1995"})
        wife: Individual = Individual(_id="I1", birt={'date': "3 JAN 2000"})
        individuals: List[Individual] = [husband, wife]
        family: Family = Family(_id="F0",
                                husb=husband.id,
                                wife=wife.id,
                                marr={'date': "11 FEB 2015"})
        self.assertTrue(us.were_parents_over_14(family, individuals))

        # husband 11, wife 20 -> Only wife is over 14 -> False
        husband: Individual = Individual(_id="I2", birt={'date': "2 MAR 2007"})
        wife: Individual = Individual(_id="I3", birt={'date': "11 FEB 2000"})
        individuals: List[Individual] = [husband, wife]
        family: Family = Family(_id="F1",
                                husb=husband.id,
                                wife=wife.id,
                                marr={'date': "11 FEB 2019"})
        self.assertFalse(us.were_parents_over_14(family, individuals))

        # husband 17, wife 10 -> Only husband is over 14 -> False
        husband: Individual = Individual(_id="I4",
                                         birt={'date': "22 AUG 2000"})
        wife: Individual = Individual(_id="I5", birt={'date': "5 DEC 2007"})
        individuals: List[Individual] = [husband, wife]
        family: Family = Family(_id="F2",
                                husb=husband.id,
                                wife=wife.id,
                                marr={'date': "11 FEB 2018"})
        self.assertFalse(us.were_parents_over_14(family, individuals))

        # husband 12, wife 12 -> Both are under 14 -> False
        husband: Individual = Individual(_id="I6",
                                         birt={'date': "19 SEP 2007"})
        wife: Individual = Individual(_id="I7", birt={'date': "3 JAN 2008"})
        individuals: List[Individual] = [husband, wife]
        family: Family = Family(_id="F3",
                                husb=husband.id,
                                wife=wife.id,
                                marr={'date': "11 FEB 2020"})
        self.assertFalse(us.were_parents_over_14(family, individuals))

        # husband 18, wife 16 -> Both are over 14 -> True
        husband: Individual = Individual(_id="I8", birt={'date': "7 FEB 1980"})
        wife: Individual = Individual(_id="I9", birt={'date': "8 FEB 1982"})
        individuals: List[Individual] = [husband, wife]
        family: Family = Family(_id="F4",
                                husb=husband.id,
                                wife=wife.id,
                                marr={'date': "11 FEB 1998"})
        self.assertTrue(us.were_parents_over_14(family, individuals))
Ejemplo n.º 8
0
def getFamily():
    family = Family("Doe")
    familyMembers = family.get_all_members()
    luckyNumbers = []
    for member in familyMembers:
        luckyNumbers = luckyNumbers + member['lucky_numbers']
    response_body = {
        "family_name": family.last_name,
        "members": familyMembers,
        "lucky_numbers": luckyNumbers,
        "sum_of_lucky": sum(luckyNumbers)
    }
    return jsonify(response_body), 200
Ejemplo n.º 9
0
def add_family(teacher_id):
    if teacher_id == session[CURR_USER_KEY] and session[IS_TEACHER] == True:
        form = FamilyForm()
        if form.validate_on_submit():
            guardian = Guardian.query.filter_by(
                first_name=form.guardian_first_name.data,
                last_name=form.guardian_last_name.data,
                username=form.guardian_username.data).first()
            student = Student.query.filter_by(
                first_name=form.student_first_name.data,
                last_name=form.student_last_name.data).first()
            family = Family(guardian_id=guardian.id, student_id=student.id)

            db.session.add(family)
            db.session.commit()
            flash(
                f"Family created! Guardian: {guardian.first_name} {guardian.last_name}, Student: {student.first_name} {student.last_name}!",
                "good")
            return redirect(f'/teacher/{session[CURR_USER_KEY]}')
        students = Student.query.all()
        guardians = Guardian.query.all()
        return render_template('/teacher/add-family.html',
                               form=form,
                               students=students,
                               guardians=guardians)
Ejemplo n.º 10
0
    def test_birth_before_death_of_parents(self):
        """ test birth_before_death_of_parents method """
        # mother and father are alive (no death date)
        husband: Individual = Individual(_id="I0")
        wife: Individual = Individual(_id="I1")
        child: Individual = Individual(_id="I2", birt={'date': "4 OCT 2000"})
        individuals: List[Individual] = [husband, wife, child]
        family: Family = Family(_id="F0", husb=husband.id, wife=wife.id)
        family.chil.append(child.id)
        self.assertTrue(us.birth_before_death_of_parents(family, individuals))

        # child born on: mother death, 270 day after father death
        husband: Individual = Individual(_id="I0", deat={'date': "8 JAN 2000"})
        wife: Individual = Individual(_id="I1", deat={'date': "4 OCT 2000"})
        child: Individual = Individual(_id="I2", birt={'date': "4 OCT 2000"})
        individuals: List[Individual] = [husband, wife, child]
        family: Family = Family(_id="F1", husb=husband.id, wife=wife.id)
        family.chil.append(child.id)
        self.assertTrue(us.birth_before_death_of_parents(family, individuals))

        # child born on: 1 day before mother death, 1 day after father death
        husband: Individual = Individual(_id="I0", deat={'date': "3 OCT 2000"})
        wife: Individual = Individual(_id="I1", deat={'date': "5 OCT 2000"})
        child: Individual = Individual(_id="I2", birt={'date': "4 OCT 2000"})
        individuals: List[Individual] = [husband, wife, child]
        family: Family = Family(_id="F2", husb=husband.id, wife=wife.id)
        family.chil.append(child.id)
        self.assertTrue(us.birth_before_death_of_parents(family, individuals))

        # child born on: after mother death, 10 day after father death
        husband: Individual = Individual(_id="I0", deat={'date': "3 OCT 2000"})
        wife: Individual = Individual(_id="I1", deat={'date': "12 OCT 2000"})
        child: Individual = Individual(_id="I2", birt={'date': "13 OCT 2000"})
        individuals: List[Individual] = [husband, wife, child]
        family: Family = Family(_id="F3", husb=husband.id, wife=wife.id)
        family.chil.append(child.id)
        self.assertFalse(us.birth_before_death_of_parents(family, individuals))

        # child born on: before mother death, 1 year after father death
        husband: Individual = Individual(_id="I0",
                                         deat={'date': "11 OCT 1999"})
        wife: Individual = Individual(_id="I1", deat={'date': "12 OCT 2000"})
        child: Individual = Individual(_id="I2", birt={'date': "11 OCT 2000"})
        individuals: List[Individual] = [husband, wife, child]
        family: Family = Family(_id="F4", husb=husband.id, wife=wife.id)
        family.chil.append(child.id)
        self.assertFalse(us.birth_before_death_of_parents(family, individuals))
Ejemplo n.º 11
0
def members():
    body = request.get_json()

    if request.method == 'GET':
        family = Family('Doe')
        members = family.get_all_members()
        lucky_numbers = [member['lucky_numbers'] for member in members]
        sum_of_lucky = sum([number for sub in lucky_numbers for number in sub])

        response_body = {
            "family_name": family.last_name,
            "members": family.get_all_members(),
            "lucky_numbers": lucky_numbers,
            "sum_of_lucky": str(sum_of_lucky)
        }

        return jsonify(response_body), 200

    if request.method == 'POST':
        if body is not None:
            family = Family('Doe')
            body = request.get_json()
            response_body = family.add_member(body)

            return jsonify(response_body), 200
        else:
            raise APIException(
                'You need to specify the request body as a json object',
                status_code=404)
Ejemplo n.º 12
0
    def setUp(self):
        """
        Initialize needed resources.
        """
        self.d = datetime.datetime(2011, 10, 1, 15, 26)

        self.ff = Family()
        self.ff.sure_name = u"Father family's sure name"
        self.ff.leadership = Family.LEADERSHIP_PATRIARCHAL_CHOICE
        self.ff.save()

        self.father = Person()
        self.father.sex = Person.SEX_MALE_CHOICE
        self.father.name = u"Father's name"
        self.father.family = self.ff
        self.father.born_in = self.d
        self.father.save()

        self.mf = Family()
        self.mf.sure_name = u"Mother family's sure name"
        self.mf.leadership = Family.LEADERSHIP_MATRIARCHAL_CHOICE
        self.mf.save()

        self.mother = Person()
        self.mother.sex = Person.SEX_FEMALE_CHOICE
        self.mother.name = u"Mother's name"
        self.mother.family = self.mf
        self.mother.born_in = self.d
        self.mother.save()

        self.son = Person()
        self.son.name = u"Son's name"
        self.son.father = self.father
        self.son.mother = self.mother
        self.son.born_in = self.d
        self.son.family = self.ff
        self.son.save()

        self.other_son = Person()
        self.other_son.name = u"Other son's name"
        self.other_son.father = self.father
        self.other_son.mother = self.mother
        self.other_son.born_in = self.d
        self.other_son.family = self.ff
        self.other_son.save()
Ejemplo n.º 13
0
    def setUp(self):
        self.school = School(name='Minnesota')
        db.session.add(self.school)
        db.session.commit()

        self.tch = Teacher(first_name='Jess',
                           last_name='Christensen',
                           title='K4-2nd Sped',
                           school_id=self.school.id,
                           username='******',
                           password='******')
        db.session.add(self.tch)
        db.session.commit()

        self.stu = Student(first_name='Fake',
                           last_name='Kid',
                           dob=date(2012, 1, 24),
                           grade=1,
                           teacher_id=self.tch.id,
                           dis_area='OHI')
        db.session.add(self.stu)
        db.session.commit()

        self.guardian = Guardian(first_name='Fake',
                                 last_name='Dad',
                                 relation='Dad',
                                 username='******',
                                 password='******')
        self.guardian2 = Guardian(first_name='Fake',
                                  last_name='Mom',
                                  relation='Mom',
                                  username='******',
                                  password='******')
        db.session.add(self.guardian)
        db.session.add(self.guardian2)
        db.session.commit()

        self.family = Family(guardian_id=self.guardian.id,
                             student_id=self.stu.id)
        self.family2 = Family(guardian_id=self.guardian2.id,
                              student_id=self.stu.id)

        db.session.add(self.family)
        db.session.add(self.family2)
        db.session.commit()
Ejemplo n.º 14
0
def parse_single_family(gedlist, index, xref):
    """
    Parses a single family from a GEDCOM giving the starting index of a
    'FAM' tag. Returns an Family class
    """
    family = Family(xref)

    date_type = None
    for gedline in gedlist[index + 1:]:
        if gedline.level == 0:
            break
        if gedline.tag == "MARR":
            date_type = "MARR"
        if gedline.tag == "DIV":
            date_type = "DIV"

        if gedline.tag == "HUSB":
            family.husband = gedline.args[0]
        if gedline.tag == "WIFE":
            family.wife = gedline.args[0]
        if gedline.tag == "CHIL":
            family.children.append(gedline.args[0])

        # This assumes the following date tag corresponds to prev tag
        if gedline.tag == "DATE":
            if date_type == "MARR":
                # Store marriage date as datetime
                family.marriage = datetime(
                    int(gedline.args[2]),
                    datetime.strptime(gedline.args[1], '%b').month,
                    int(gedline.args[0]))
                date_type = None

            elif date_type == "DIV":
                # Store divorce date as datetime
                family.divorce = datetime(
                    int(gedline.args[2]),
                    datetime.strptime(gedline.args[1], '%b').month,
                    int(gedline.args[0]))
                date_type = None
            else:
                print "ERROR"

    return family
Ejemplo n.º 15
0
def create_new_member():
    data = request.get_json()
    new_member = Family(public_id=str(uuid.uuid4()),
                        first_name=data["first_name"],
                        last_name=data["last_name"],
                        age=data["age"],
                        lucky_numbers=data["lucky_numbers"])
    db.session.add(new_member)
    db.session.commit()
    return jsonify({"message": "New User Created!"})
Ejemplo n.º 16
0
    def test_divorce_before_death(self):

        husband: Individual = Individual(_id="I0", deat={'date': "1 JAN 2020"})
        wife: Individual = Individual(_id="I1", deat={'date': "2 JAN 2019"})
        individuals: List[Individual] = [husband, wife]
        family: Family = Family(husb=husband.id,
                                wife=wife.id,
                                div={'date': "11 FEB 1999"})
        self.assertTrue(us.divorce_before_death(family, individuals))
        """Husband and wife they both die before their divorce so False (not possible)"""
        husband: Individual = Individual(_id="I2", deat={'date': "1 JAN 2000"})
        wife: Individual = Individual(_id="I3", deat={'date': "2 JAN 2000"})
        individuals: List[Individual] = [husband, wife]
        family: Family = Family(husb=husband.id,
                                wife=wife.id,
                                div={'date': "11 FEB 2001"})
        self.assertFalse(us.divorce_before_death(family, individuals))
        """ Husband dies before divorce wife is alive so False (not possible)"""
        husband: Individual = Individual(_id="I4", deat={'date': "1 JAN 2000"})
        wife: Individual = Individual(_id="I5")
        individuals: List[Individual] = [husband, wife]
        family: Family = Family(husb=husband.id,
                                wife=wife.id,
                                div={'date': "11 FEB 2001"})
        self.assertFalse(us.divorce_before_death(family, individuals))
        """ Husband dies after divorce and  wife is alive so true"""
        husband: Individual = Individual(_id="I4", deat={'date': "1 JAN 2002"})
        wife: Individual = Individual(_id="I5")
        individuals: List[Individual] = [husband, wife]
        family: Family = Family(husb=husband.id,
                                wife=wife.id,
                                div={'date': "11 FEB 2001"})
        self.assertTrue(us.divorce_before_death(family, individuals))
        """Wife dies before divorce and Husband is alive so False (not possible)"""
        husband: Individual = Individual(_id="I6")
        wife: Individual = Individual(_id="I7", deat={'date': "1 JAN 2000"})
        individuals: List[Individual] = [husband, wife]
        family: Family = Family(husb=husband.id,
                                wife=wife.id,
                                div={'date': "11 FEB 2001"})
        self.assertFalse(us.divorce_before_death(family, individuals))
        """Wife dies after divorce and Husband is alive so true"""
        husband: Individual = Individual(_id="I8")
        wife: Individual = Individual(_id="I9", deat={'date': "1 JAN 2002"})
        individuals: List[Individual] = [husband, wife]
        family: Family = Family(husb=husband.id,
                                wife=wife.id,
                                div={'date': "11 FEB 2001"})
        self.assertTrue(us.divorce_before_death(family, individuals))
        """ Husband and wife they both are alive no divorce date is found so false"""
        husband: Individual = Individual(_id="I10")
        wife: Individual = Individual(_id="I11")
        individuals: List[Individual] = [husband, wife]
        family: Family = Family(husb=husband.id,
                                wife=wife.id,
                                div={'date': "11 FEB 2002"})
        self.assertFalse(us.divorce_before_death(family, individuals))
Ejemplo n.º 17
0
Archivo: tests.py Proyecto: jsphyin/idb
    def test_add_Family1(self):

        with app.test_request_context():
            family1 = Family(id=1000000, name="family1")
            db.session.add(family1)
            db.session.commit()

            gamequery = db.session.query(Family).filter_by(
                id="1000000").first()
            self.assertEqual(gamequery.id, 1000000)
            self.assertEqual(gamequery.name, "family1")

            db.session.delete(family1)
            db.session.commit()
Ejemplo n.º 18
0
def family_list():
    def _sort_key(item):
        # This is a very naïve sorting method.
        # We sort families by father's birth year; if it's missing, then
        # by mother's.  This does not take into account actual marriage dates,
        # so if the second wife was older than the first one, the second family
        # goes first.  The general idea is to roughly sort the families and
        # have older people appear before younger ones.
        if item.father and item.father.birth:
            return str(item.father.birth.year)
        if item.mother and item.mother.birth:
            return str(item.mother.birth.year)
        return ''
    object_list = sorted(Family.find(), key=_sort_key)
    return render_template('family_list.html', object_list=object_list)
Ejemplo n.º 19
0
Archivo: tests.py Proyecto: jsphyin/idb
    def test_add_Family2(self):

        with app.test_request_context():
            family2 = Family()
            init_len = len(Family.query.all())
            db.session.add(family2)
            db.session.commit()
            changed_len = len(Family.query.all())
            self.assertEqual(init_len + 1, changed_len)

            init_len = changed_len
            db.session.delete(family2)
            db.session.commit()
            changed_len = len(Family.query.all())
            self.assertEqual(init_len - 1, changed_len)
Ejemplo n.º 20
0
def family_list():
    def _sort_key(item):
        # This is a very naïve sorting method.
        # We sort families by father's birth year; if it's missing, then
        # by mother's.  This does not take into account actual marriage dates,
        # so if the second wife was older than the first one, the second family
        # goes first.  The general idea is to roughly sort the families and
        # have older people appear before younger ones.
        if item.father and item.father.birth:
            return str(item.father.birth.year)
        if item.mother and item.mother.birth:
            return str(item.mother.birth.year)
        return ''

    object_list = sorted(Family.find(), key=_sort_key)
    return render_template('family_list.html', object_list=object_list)
Ejemplo n.º 21
0
def single_member(member_id=None):

    body = request.get_json()

    if request.method == 'GET':
        family = Family('Doe')
        response_body = family.get_member(member_id)

        return jsonify(response_body), 200

    if request.method == 'DELETE':
        family = Family('Doe')
        family.delete_member(member_id)
        response_body = {"msg": "member was successfully deleted"}
        return jsonify(response_body), 200

    return "Invalid Method", 404
Ejemplo n.º 22
0
def generate_classes(
        lines: List[str]) -> Tuple[List[Individual], List[Family]]:
    """ get lines read from a .ged file """
    individuals: List[Individual] = []
    families: List[Family] = []
    current_record: Optional[Individual, Family] = None
    current_tag: Optional[str] = None

    for line in lines:
        row_fields: List[str] = line.rstrip("\n").split(' ', 2)
        pattern_type = pattern_finder(line)
        if pattern_type == 'ZERO_1':
            current_record = Individual(
            ) if row_fields[2] == 'INDI' else Family()
            (individuals if isinstance(current_record, Individual) else families) \
                .append(current_record)
            current_record.id = row_fields[1]
        elif pattern_type == 'ZERO_2':
            pass  # nothing to do with this
        elif pattern_type == 'NO_ARGUMENT':
            if row_fields[0] == '1':
                setattr(current_record, row_fields[1].lower(), {})
                current_tag = row_fields[1].lower()
        elif pattern_type == 'ARGUMENT':
            if row_fields[0] == '1':
                if isinstance(getattr(current_record, row_fields[1].lower()),
                              list):
                    current_list = getattr(
                        current_record,
                        row_fields[1].lower()) + [row_fields[2]]
                    setattr(current_record, row_fields[1].lower(),
                            current_list)
                else:
                    setattr(current_record, row_fields[1].lower(),
                            row_fields[2])
            elif row_fields[0] == '2':
                setattr(current_record, current_tag,
                        {row_fields[1].lower(): row_fields[2]})

    return individuals, families
Ejemplo n.º 23
0
 def setUp(self):
     db.create_all()
     # Adding Users
     user = User(name='user1', email="*****@*****.**")
     user2 = User(name='user2',  email="*****@*****.**")
     user3 = User(name='user3',  email="*****@*****.**")
     db.session.add_all([user, user2, user3])
     # Adding Families
     family = Family(name='Family-name-1', members=[user, user2])
     family2 = Family(name='Family-name-2', members=[user, user3])
     db.session.add_all([family, family2, user3])
     # Adding Fridges
     fridge = Fridge()
     fridge2 = Fridge()
     db.session.add_all([fridge, fridge2])
     family.fridge = fridge
     family2.fridge = fridge2
     # Adding Grocery Lists
     grocery_list = GroceryList(name="listname1")
     grocery_list2 = GroceryList(name="listname2")
     grocery_list3 = GroceryList(name="listname3")
     db.session.add_all([grocery_list, grocery_list2, grocery_list3])
     family.grocery_lists.append(grocery_list)
     family.grocery_lists.append(grocery_list2)
     family2.grocery_lists.append(grocery_list3)
     db.session.commit()
     # Adding items
     item1 = Item(name="item1", family_pk=family.pk)
     item2 = Item(name="item2", family_pk=family.pk)
     item3 = Item(name="item3", family_pk=family.pk)
     item4 = Item(name="item4", family_pk=family2.pk)
     item5 = Item(name="item5", family_pk=family2.pk)
     db.session.add_all([item1, item2, item3, item4, item5])
     # Adding items to fridge
     fridge.items.append(item1)
     fridge2.items.append(item2)
     # Adding items to grocery lists
     grocery_list.items.append(item3)
     grocery_list3.items.append(item4)
     grocery_list3.items.append(item5)
     db.session.commit()
Ejemplo n.º 24
0
def newMember():
    if not request.is_json:
        return jsonify({"msg": "Missing JSON in request"}), 400
    family = Family('Doe')
    name = request.json.get('name', None)
    if not name:
        return({"msg": "Missing name parameter"})
    age = request.json.get('age', None)
    if not age: 
        return({"msg": "Missing age parameter"})
    lucky_numbers = request.json.get('lucky_numbers', None)
    if not lucky_numbers:
        return({"msg": "Missing lucky numbers"})
    new_member = {
        "id": family._generateId(),
        "first_name": name,
        "age": age,
        "lucky_numbers": lucky_numbers
    }
    family.add_member(new_member)
    return jsonify(family.get_all_members())
Ejemplo n.º 25
0
def run():
    F = Family()
    F.create_pollyanna()
Ejemplo n.º 26
0
def getMember(member_id = None):
    family = Family('Doe')
    member_id = request.view_args['member_id']
    member = family.get_member(member_id)
    return jsonify(member)
Ejemplo n.º 27
0
                         last_name='Dad',
                         relation='Father',
                         username='******',
                         password='******')
par3 = Guardian.register(first_name='Fake',
                         last_name='Aunt',
                         relation='Aunt',
                         username='******',
                         password='******')
par4 = Guardian.register(first_name='Fake',
                         last_name='Brother',
                         relation='Brother',
                         username='******',
                         password='******')

fam1 = Family(student_id=1, guardian_id=1)
fam2 = Family(student_id=2, guardian_id=1)
fam5 = Family(student_id=1, guardian_id=2)
fam6 = Family(student_id=2, guardian_id=2)

fam3 = Family(student_id=2, guardian_id=3)
fam4 = Family(student_id=3, guardian_id=4)

db.session.add(fam1)
db.session.add(fam2)
db.session.add(fam3)
db.session.add(fam4)
db.session.add(fam5)
db.session.add(fam6)

db.session.commit()
Ejemplo n.º 28
0
from flask import Flask, render_template, request, jsonify
from models import Family
import json

app = Flask(__name__)

fam = Family("Jackson")


@app.route("/")
def main():
    return render_template("index.html")


@app.route("/members/", methods=["GET", "POST"])
@app.route("/members/member/<int:id>", methods=["GET", "PUT", "DELETE"])
def members(id=None):

    ####### G E T - M I E M B R O S ########
    if request.method == "GET":

        if id == None:
            miembros = fam.get_all_members()
            return jsonify(miembros), 201

####### G E T - M I E M B R O ########
        if id:
            member = fam.get_member(id)
            if member:
                return jsonify(member), 200
            else:
Ejemplo n.º 29
0
def deleteMember(member_id = None):
    family = Family('Doe')
    member_id = request.view_args['member_id']
    family.delete_member(member_id)
    return jsonify(family.get_all_members())
Ejemplo n.º 30
0
    i = 1
    for key in err_list:
        err_chart.add_row([i, err_list[key]])
        i += 1

    write_file.write("Individual\n")
    write_file.write(indi_chart.get_string() + "\n")
    write_file.write("Family\n")
    write_file.write(fam_chart.get_string() + "\n")
    write_file.write("Error\n")
    if (i == 1): write_file.write("\nNo Errors found!")
    else: write_file.write(err_chart.get_string())

    write_file.close()


if __name__ == "__main__":
    from models import Individual
    from models import Family
    indi_1 = Individual.Individual("01")
    indi_2 = Individual.Individual("02")
    fam_1 = Family.Family("10")
    fam_2 = Family.Family("20")
    indi_1.add_to_family(fam_1)
    indi_2.add_to_family(fam_2)
    fam_1.set_husband(indi_1)
    fam_1.set_wife(indi_2)
    fam_2.set_husband(indi_2)
    fam_2.set_wife(indi_1)
    print_pretty_table([indi_1, indi_2], [fam_1, fam_2], [])
Ejemplo n.º 31
0
def family_detail(obj_id):
    obj = Family.get(obj_id)
    if not obj:
        abort(404)
    return render_template('family_detail.html', obj=obj)
Ejemplo n.º 32
0
def parse_taxonomy(Document):
    f = csv.reader(Document, delimiter='\t')
    f.next()

    for line in f:
        subbed = re.sub(r'(\(.*?\)|k__|p__|c__|o__|f__|g__|s__)', '', line[2])
        taxon = subbed.split(';')

        if not Kingdom.objects.filter(kingdomName=taxon[0]).exists():
            kid = uuid4().hex
            record = Kingdom(kingdomid=kid, kingdomName=taxon[0])
            record.save()
        k = Kingdom.objects.get(kingdomName=taxon[0]).kingdomid

        if not Phyla.objects.filter(kingdomid_id=k,
                                    phylaName=taxon[1]).exists():
            pid = uuid4().hex
            record = Phyla(kingdomid_id=k, phylaid=pid, phylaName=taxon[1])
            record.save()
        p = Phyla.objects.get(kingdomid_id=k, phylaName=taxon[1]).phylaid

        if not Class.objects.filter(
                kingdomid_id=k, phylaid_id=p, className=taxon[2]).exists():
            cid = uuid4().hex
            record = Class(kingdomid_id=k,
                           phylaid_id=p,
                           classid=cid,
                           className=taxon[2])
            record.save()
        c = Class.objects.get(kingdomid_id=k, phylaid_id=p,
                              className=taxon[2]).classid

        if not Order.objects.filter(
                kingdomid_id=k, phylaid_id=p, classid_id=c,
                orderName=taxon[3]).exists():
            oid = uuid4().hex
            record = Order(kingdomid_id=k,
                           phylaid_id=p,
                           classid_id=c,
                           orderid=oid,
                           orderName=taxon[3])
            record.save()
        o = Order.objects.get(kingdomid_id=k,
                              phylaid_id=p,
                              classid_id=c,
                              orderName=taxon[3]).orderid

        if not Family.objects.filter(kingdomid_id=k,
                                     phylaid_id=p,
                                     classid_id=c,
                                     orderid_id=o,
                                     familyName=taxon[4]).exists():
            fid = uuid4().hex
            record = Family(kingdomid_id=k,
                            phylaid_id=p,
                            classid_id=c,
                            orderid_id=o,
                            familyid=fid,
                            familyName=taxon[4])
            record.save()
        f = Family.objects.get(kingdomid_id=k,
                               phylaid_id=p,
                               classid_id=c,
                               orderid_id=o,
                               familyName=taxon[4]).familyid

        if not Genus.objects.filter(kingdomid_id=k,
                                    phylaid_id=p,
                                    classid_id=c,
                                    orderid_id=o,
                                    familyid_id=f,
                                    genusName=taxon[5]).exists():
            gid = uuid4().hex
            record = Genus(kingdomid_id=k,
                           phylaid_id=p,
                           classid_id=c,
                           orderid_id=o,
                           familyid_id=f,
                           genusid=gid,
                           genusName=taxon[5])
            record.save()
        g = Genus.objects.get(kingdomid_id=k,
                              phylaid_id=p,
                              classid_id=c,
                              orderid_id=o,
                              familyid_id=f,
                              genusName=taxon[5]).genusid

        if not Species.objects.filter(kingdomid_id=k,
                                      phylaid_id=p,
                                      classid_id=c,
                                      orderid_id=o,
                                      familyid_id=f,
                                      genusid_id=g,
                                      speciesName=taxon[6]).exists():
            sid = uuid4().hex
            record = Species(kingdomid_id=k,
                             phylaid_id=p,
                             classid_id=c,
                             orderid_id=o,
                             familyid_id=f,
                             genusid_id=g,
                             speciesid=sid,
                             speciesName=taxon[6])
            record.save()
Ejemplo n.º 33
0
"""
This module takes care of starting the API Server, Loading the DB and Adding the endpoints
"""
import os
from flask import Flask, request, jsonify, url_for
from utils import APIException, generate_sitemap
from models import Family

app = Flask(__name__)
app.url_map.strict_slashes = False

doe = Family("Londono")

john = {
    "age": "33 Years old",
    "gender": "Male",
    "Lucky Numbers": [7, 13, 22],
    "member_id": 1
}
jane = {
    "age": "35 Years old",
    "gender": "Female",
    "Lucky Numbers": [10, 14, 3],
    "member_id": 2
}
jimmy = {
    "age": "5 Years old",
    "gender": "Male",
    "Lucky Numbers": [1],
    "member_id": 3
}
Ejemplo n.º 34
0
class PersonTest(TestCase):
    """
    Tests the behaviour of class Person.
    """

    def setUp(self):
        """
        Initialize needed resources.
        """
        self.d = datetime.datetime(2011, 10, 1, 15, 26)

        self.ff = Family()
        self.ff.sure_name = u"Father family's sure name"
        self.ff.leadership = Family.LEADERSHIP_PATRIARCHAL_CHOICE
        self.ff.save()

        self.father = Person()
        self.father.sex = Person.SEX_MALE_CHOICE
        self.father.name = u"Father's name"
        self.father.family = self.ff
        self.father.born_in = self.d
        self.father.save()

        self.mf = Family()
        self.mf.sure_name = u"Mother family's sure name"
        self.mf.leadership = Family.LEADERSHIP_MATRIARCHAL_CHOICE
        self.mf.save()

        self.mother = Person()
        self.mother.sex = Person.SEX_FEMALE_CHOICE
        self.mother.name = u"Mother's name"
        self.mother.family = self.mf
        self.mother.born_in = self.d
        self.mother.save()

        self.son = Person()
        self.son.name = u"Son's name"
        self.son.father = self.father
        self.son.mother = self.mother
        self.son.born_in = self.d
        self.son.family = self.ff
        self.son.save()

        self.other_son = Person()
        self.other_son.name = u"Other son's name"
        self.other_son.father = self.father
        self.other_son.mother = self.mother
        self.other_son.born_in = self.d
        self.other_son.family = self.ff
        self.other_son.save()

    def test_family_leader_patriarchal(self):
        """
        Must return the correct family leader based patriarchal configured
        leadership.
        """
        self.son.family = self.ff
        self.assertEqual(self.son.family_leader(), self.father)

    def test_family_leader_matriarchal(self):
        """
        Must return the correct family leader based matriarchal configured
        leadership.
        """
        self.son.family = self.mf
        self.assertEqual(self.son.family_leader(), self.mother)

    def test_family_leader_not_defined(self):
        """
        Must return a None object when the leadership is not defined.
        """
        self.son.family = self.mf
        self.son.family.leadership = None
        self.assertIsNone(self.son.family_leader())

    def test_is_alive_not_defined(self):
        """
        Tests the return value when a Person hasn't defined a born date nor a
        deceased date.
        """
        self.son.born_in = None
        self.assertIsNone(self.son.is_alive())

    def test_is_alive_not_alive(self):
        """
        Tests the return value when a Person is dead, based on the object
        dates.
        """
        self.son.born_in = self.d
        self.son.deceased_in = self.d
        self.assertFalse(self.son.is_alive())

    def test_is_alive_alive(self):
        """
        Tests the return value when a Person is dead, based on the object
        dates.
        """
        self.son.born_in = self.d
        self.assertTrue(self.son.is_alive())

    def test_brothers(self):
        """
        Tests the ``brothers()`` method to validate that returns other
        :model:`family.Person` instances related by parents, but not the
        current object.
        """
        self.assertTrue(self not in self.son.brothers())

    def test_parents(self):
        """
        Tests the ``parents()`` method to validate that returns other
        :model:`family.Person` instances related to the current one as parents.
        """
        parents = self.son.parents()
        self.assertEqual(2, len(parents))
        self.assertTrue(self.son.father in parents)
        self.assertTrue(self.son.mother in parents)

    def test_descendence_invalid(self):
        """
        Tests the ``descendence()`` method to validate that raises an exception
        if current instance has not sex value defined.
        """
        self.father.sex = None
        self.assertRaises(ValueError, self.father.descendence)

    def test_father_descendence(self):
        """
        Tests the ``descendence()`` method to validate that returns other
        :model:`family.Person` instances related to the current one as
        father's descendence.
        """
        d = self.father.descendence()
        self.assertEqual(2, len(d))
        self.assertTrue(self.son in d)
        self.assertTrue(self.other_son in d)

    def test_mother_descendence(self):
        """
        Tests the ``descendence()`` method to validate that returns other
        :model:`family.Person` instances related to the current one as
        mother's descendence.
        """
        d = self.mother.descendence()
        self.assertEqual(2, len(d))
        self.assertTrue(self.son in d)
        self.assertTrue(self.other_son in d)
Ejemplo n.º 35
0
def family_detail(obj_id):
    obj = Family.get(obj_id)
    if not obj:
        abort(404)
    return render_template('family_detail.html', obj=obj)
Ejemplo n.º 36
0
 def fam_stmt(self, *ts):
     (args, ) = ts
     family = Family.from_args(args)
     self.families[family.id_] = family
     return family
Ejemplo n.º 37
0
"""
This module takes care of starting the API Server, Loading the DB and Adding the endpoints
"""
import os
from flask import Flask, request, jsonify, url_for
from flask_migrate import Migrate
from flask_swagger import swagger
from flask_cors import CORS
from utils import APIException, generate_sitemap
from models import db
from models import Family

myFamily = Family("Doe")

app = Flask(__name__)
app.url_map.strict_slashes = False
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DB_CONNECTION_STRING')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
MIGRATE = Migrate(app, db)
db.init_app(app)
CORS(app)


# Handle/serialize errors like a JSON object
@app.errorhandler(APIException)
def handle_invalid_usage(error):
    return jsonify(error.to_dict()), error.status_code


# generate sitemap with all your endpoints
@app.route('/')
Ejemplo n.º 38
0
def run():
    F = Family()
    F.create_pollyanna()