Example #1
0
    def test_create_child(self):
        """Does parent creation product the correct result?"""

        testchild = create_child(fname="Johnny",
                                 lname="Williams",
                                 zipcode="94010",
                                 household_id=2,
                                 school_id=1,
                                 grade_id=2)
        self.assertEqual(testchild.fname, "Johnny")
        self.assertEqual(type(testchild), Child)
Example #2
0
def get_children():
    """Load children from dataset into database."""

    with open("data/finaldata.csv", encoding='utf-8-sig') as children_data:
        for r in enumerate(children_data):
            data = r[1].split(',')
            child_id, age_2021, date_missing, lname, fname, missing_age, city, county, state, gender, ethnicity, latitude, longitude = data

            child_instance = crud.create_child(fname=fname, lname=lname, ethnicity=ethnicity, date_missing=date_missing, missing_age=int(missing_age), age_2021=int(age_2021))
            
            location_instance = crud.create_location(child_id=child_instance.child_id, state=state, city=city, county=county)
Example #3
0
def create_child():
    print("In server.py create childfunction")

    query_str_data = request.get_json()

    print("In server.py - create child ", query_str_data)

    child_fname = query_str_data['childFname'],
    child_lname = query_str_data['childLname'],
    grade = query_str_data['grade'],
    school_id = query_str_data['schoolId'],
    parent_id = query_str_data['parentId'],

    try:
        result = crud.create_child(child_fname, child_lname, grade, school_id,
                                   parent_id)
        return jsonify([result.id, child_fname])

    except:
        result = "Error inserting child"
        return result
Example #4
0
def add_child():

    if 'loggedin' in session:
        user = crud.get_user_by_id(session['id'])

        if request.method == 'GET':
            interests = Interest.query.all()
            return render_template('add_child.html',
                                   user=user,
                                   interests=interests,
                                   name=session['name'])

        if request.method == 'POST':
            child_name = request.form['child_name']
            birthdate = request.form['birthdate']
            gender = request.form['gender']
            interests = request.form.getlist('interests[]')
            photo = request.form.get('child_photo')

            add_child = crud.create_child(child_name, birthdate, gender, photo)

            db.session.add(add_child)

            for i in interests:
                interest = db.session.query(Interest).filter_by(
                    interest_id=i).first()
                add_child.interests.append(interest)

            user.children.append(add_child)
            db.session.commit()

            flash("Child added")
            return redirect(url_for('profile'))

    flash('Please login')
    return redirect('/login')
Example #5
0
for user in user_data:
    first_name, last_name, email, username, password, zipcode, photo = (user['first_name'], user['last_name'], 
    user['email'], user['username'], user['password'], user['zipcode'], user['photo'])

    db_user = crud.create_user(first_name, last_name, email, username, password, zipcode, photo)
        
    users_in_db.append(db_user)

with open('data/child_data.json') as d:
    child_data = json.loads(d.read())

child_in_db = []
for child in child_data:
    child_name, birthdate, gender, photo = (child['child_name'], child['birthdate'], child['gender'], child['photo'])

    db_child = crud.create_child(child_name, birthdate, gender, photo)
        
    child_in_db.append(db_child)

with open('data/materials_info.json') as c:
    materials = json.loads(c.read())

materials_in_db = []

for material in materials:
    material_name, material_cost, material_url = (material['material_name'], material['material_cost'], material['material_url'])

    db_material = crud.create_material(material_name, material_cost, material_url)
    materials_in_db.append(db_material)

with open('data/time_period.json') as z:
    prefer_same_school_only = fake.boolean(chance_of_getting_true=50)
    prefer_same_grade_only = fake.boolean(chance_of_getting_true=50)
    prefer_outdoors_only = fake.boolean(chance_of_getting_true=50)
    prefer_periodic_covid_testing = fake.boolean(chance_of_getting_true=50)
    max_budget_per_hour = randrange(0, 5)

    if k < 12:
        new_child = crud.create_child(
            fname=fname,
            lname=lname,
            zipcode=zipcode,
            gender="Female",
            school_id=school_id,
            grade_id=grade_id,
            household_id=household_id,
            distance_willing_to_travel=distance_willing_to_travel,
            preferred_days_per_week=preferred_days_per_week,
            preferred_total_hours_per_day=preferred_total_hours_per_day,
            prefer_paid_teacher=prefer_paid_teacher,
            prefer_same_school_program_only=prefer_same_school_program_only,
            prefer_same_school_only=prefer_same_school_only,
            prefer_same_grade_only=prefer_same_grade_only,
            prefer_outdoors_only=prefer_outdoors_only,
            prefer_periodic_covid_testing=prefer_periodic_covid_testing,
            max_budget_per_hour=max_budget_per_hour)
    else:
        new_child = crud.create_child(
            fname=fname,
            lname=lname,
            zipcode='94010',
            gender="Male",
            school_id=school_id,
Example #7
0
                               parent[10],
                               parent[11],
                             )

    # Call create_parent function from crud.py
    db_parent = crud.create_parent(parent_fname, parent_lname, \
                                  email, phone, address1, address2, \
                                  city, state, zipcode, last_login, \
                                  created_on, password)

########### CHILDREN DATA
# Load children data from JSON file generated using Faker
with open('data/children.json') as f:
    children_info = json.loads(f.read())

# Create & load child

for child in children_info:

    # Unpack the values & send as a list to create a record in the backend db
    child_fname, child_lname, grade, \
    school_id, parent_id = (child[0],
                             child[1],
                             child[2],
                             child[3],
                             child[4]
                             )

    # Call create_child function from crud.py
    db_child = crud.create_child(child_fname, child_lname, \
                                  grade, school_id, parent_id)