Exemple #1
0
def child_update(child_id):
    guest = Child.query.get_or_404(child_id)
    # if current_user.role == 'Admin' or current_user == guest.user:
    form = ChildForm()
    child = Child.query.get_or_404(child_id)
    if form.validate_on_submit():
        child.FirstName = form.firstname.data
        child.LastName = form.lastname.data
        child.Age = form.age.data
        child.Year = form.year.data
        child.Mark = form.mark.data.upper()
        child.Disability_Type = form.disability_type.data
        child.ClassRoom = form.class_room.data.upper()
        db.session.commit()
        flash('Child has been Updated!', 'success')
        #  if current_user.role == 'Admin':
        #      return redirect(url_for('reservation_list'))
        #  else:
        return redirect(url_for('child_list'))
    elif request.method == 'GET':
        form.firstname.data = child.FirstName
        form.lastname.data = child.LastName
        form.age.data = child.Age
        form.year.data = child.Year
        form.mark.data = child.Mark
        form.disability_type.data = child.Disability_Type
        form.class_room.data = child.ClassRoom
    return render_template('child_update.html',
                           title="Reservation Update",
                           form=form)
    """
Exemple #2
0
def add_child():
    form = ChildForm()
    if form.validate_on_submit():
        print("Form submitted", current_user.id)
        myclient = pymongo.MongoClient("mongodb://localhost:27017/")
        mydb = myclient["mydatabase"]
        mycol = mydb["last_child_id"]
        mydoc = mycol.find_one()
        print(mydoc)
        cid = int(mydoc["last_child_id"]) + 1
        myquery = {"last_child_id": mydoc["last_child_id"]}
        newvalue = {"$set": {"last_child_id": cid, "datetime": datetime.now()}}
        #print ("Cid: ", cid, "Newvalue: ", newvalue)
        mycol.update_one(myquery, newvalue)
        mycol = mydb["child_db"]
        mydict = {
            "cid": cid,
            "pid": current_user.id,
            "cfirst": form.cfirst.data,
            "clast": form.clast.data,
            "cgender": form.cgender.data,
            "cgrade": form.cgrade.data
        }
        #, "email":form.email.data, "temail1":form.temail1.data}
        #"temail2":form.temail2.data, "tuemail1":form.tuemail1.data, "tuemail2":form.tuemail2.data, "oemail1":form.oemail1.data,
        #"oemail2":form.oemail2.data, "oemail3":form.oemail3.data, "oemail4":form.oemail4.data}
        print(mydict)
        mycol.insert_one(mydict)
        flash('Child data has been added.', 'success')
        return redirect(url_for('home'))
    elif request.method == 'GET':
        return render_template("public/add_child.html", form=form)
Exemple #3
0
def register_child():
    form = ChildForm()
    if form.validate_on_submit():
        child = Child().create(form.first_name.data.title(), form.last_name.data.title(),
                               str(form.date_of_birth.data), [current_user.id])
        flash('{0} {1} has been registered'.format(child["first_name"], child["last_name"]), 'success')
        return redirect(url_for('view_children'))
    return render_template('register_child.html', title='Register a child', form=form)
Exemple #4
0
def add_profile():

    """add a child profile"""
    form = ChildForm(request.form)
    app.logger.debug(form.validate())
    app.logger.debug(form.errors)
    if request.method == 'POST' and form.validate(): 
        # get all new data
        # Upload image 
        # import pdb; pdb.set_trace()
        file = request.files['file']
        imgroot = ''
        if file and allowed_file(file.filename):
            print "This should be the file: ", file
            filename = secure_filename(file.filename)
            file.save(os.path.join("app/", app.config['UPLOAD_FOLDER'], filename))
            # Save the image path to send to the database
            imgroot = os.path.join("/", app.config['UPLOAD_FOLDER'], filename)

        # Get all the other contents
        first_name = form.data['first_name']
        last_name = form.data['last_name']
        birth_date = form.data['birth_date']
        guardian_type = form.data['guardian_type']
        guardian_fname = form.data['guardian_fname']
        guardian_lname = form.data['guardian_lname']
        godparent_prefix = form.data['godparent_prefix']
        godparent_fname = form.data['godparent_fname']
        godparent_lname = form.data['godparent_lname']
        godparent_email = form.data['godparent_email']
        medical_condition = form.data['medical_condition']
        doctor_appt = form.data['doctor_appt']
        situation = form.data['situation']
        home_visit = form.data['home_visit']
        latitude = form.data['latitude']
        longitude = form.data['longitude']
        activity = True


        # seed into database
        child_entry = Child(pic_url=imgroot, first_name=first_name, last_name=last_name,
                            birth_date=birth_date, guardian_type=guardian_type, guardian_fname=guardian_fname,
                            guardian_lname=guardian_lname, godparent_prefix=godparent_prefix, godparent_fname=godparent_fname, 
                            godparent_lname=godparent_lname, godparent_email=godparent_email, medical_condition=medical_condition, 
                            doctor_appt=doctor_appt, situation=situation, home_visit=home_visit, latitude=latitude, 
                            longitude=longitude, activity=activity)
        
        db.session.add(child_entry)
        db.session.commit()

        child = db.session.query(Child).order_by(Child.id.desc()).first()

        return redirect('/child/%d' % child.id)
    else:
        return render_template('add_profile.html', form=form)
Exemple #5
0
def edit_profile(id):
    """ Edit child profile """

    child = db.session.query(Child).filter_by(id=id).first()
    if child is None:
        abort(404)
    form = ChildForm(request.form)
    if request.method == 'POST' and form.validate():  # update child info from edit_profile.html form
        
        # Set pic_url to empty string to keep original path in case no changes are made.
        pic_url = ""
        file = request.files['file']
        # print "This should be the file: ", file
        if file and allowed_file(file.filename):
            # If no image is uploaded, this never passes.
            filename = secure_filename(file.filename)
            file.save(os.path.join("app/", app.config['UPLOAD_FOLDER'], filename))
            # Save the image path to send to the database
            pic_url = os.path.join("/", app.config['UPLOAD_FOLDER'], filename)
        # get all new data
        # pic_url = request.form.get("file")

        app.logger.debug("inside this code")
        # seed into database
        if pic_url != "":
            child.pic_url = pic_url
        # print "This should be a pic path: ", pic_url
        child.first_name = form.data['first_name']
        child.last_name = form.data['last_name']
        child.birth_date = form.data['birth_date']
        child.guardian_type = form.data['guardian_type']
        child.guardian_fname = form.data['guardian_fname']
        child.guardian_lname = form.data['guardian_lname']
        child.godparent_prefix = form.data['godparent_prefix']
        child.godparent_fname = form.data['godparent_fname']
        child.godparent_lname = form.data['godparent_lname']
        child.godparent_email = form.data['godparent_email']
        child.medical_condition = form.data['medical_condition']
        child.doctor_appt = form.data['doctor_appt']
        child.situation = form.data['situation']
        child.home_visit = form.data['home_visit']
        child.latitude = form.data['latitude']
        child.longitude = form.data['longitude']

        db.session.commit()

        return redirect('/child/%d' % child.id)

    return render_template('edit_profile.html', form=form, child=child)
Exemple #6
0
def child_create():
    form = ChildForm()
    if form.validate_on_submit():
        child = Child(FirstName=form.firstname.data,
                      LastName=form.lastname.data,
                      Password=randomString(8),
                      Age=form.age.data,
                      Grade=form.grade.data,
                      Degree=form.degree.data.upper(),
                      Disability_Type=form.disability_type.data,
                      ClassRoom=form.class_room.data.upper())
        db.session.add(child)
        db.session.commit()
        return redirect(url_for('child_list'))
    return render_template('child_create.html', form=form)
Exemple #7
0
def update_child(id):
    if str(id) not in current_user.children:
        raise Forbidden()

    child = Child().get(id)
    form = ChildForm()

    if form.validate_on_submit():
        Child().update(str(id), form.first_name.data.title(), form.last_name.data.title(), str(form.date_of_birth.data), child["users"])
        flash('Child has been updated', 'success')
        return redirect(url_for('get_child', id=str(id)))
    elif request.method == 'GET':
        form.first_name.data = child["first_name"]
        form.last_name.data = child["last_name"]
        form.date_of_birth.data = date.fromisoformat(child["date_of_birth"])
    return render_template('update_child.html', title='Update child', form=form)
Exemple #8
0
def child_create():
    form = ChildForm()
    if form.validate_on_submit():
        child = Child(id=str(uuid4()),
                      FirstName=form.firstname.data,
                      LastName=form.lastname.data,
                      Password=randomString(8),
                      Age=form.age.data,
                      Year=form.year.data,
                      Mark=form.mark.data.upper(),
                      Disability_Type=form.disability_type.data,
                      ClassRoom=form.class_room.data.upper())
        print(child.id)
        parent = Parent(id=str(uuid4()), child_id=child.id)
        db.session.add(child)
        db.session.add(parent)
        db.session.commit()
        return redirect(url_for('child_list'))
    return render_template('child_create.html', form=form)