def kid(): form = AddKidForm(request.form) if form.validate_on_submit() and request.method == 'POST': if 'bus' in request.form: rand_pass = utils.rand(6) # store parent and get its unique id to store it in Kid table # BUT BUT ,if parent already register then don't re-register instead add this kid to previously added parent p = Parent(name=form.parent_name.data, password=rand_pass, email=form.email.data) p_id = p.add_or_get() k = Kid(name=form.kid_name.data, section=form.kid_section.data, bus_id=request.form['bus'], parent_id=p_id) from sqlite3 import IntegrityError k.add() # clear form field form.parent_name.data = form.email.data = form.kid_name.data = form.kid_section.data = form.parent_name.data = '' # TODO: Send this generated password to Parent email else: all_parent_kid = Parent.get_all_parent_kid_with_bus() all_bus = Bus().get_all() return render_template('admin/kid.html', form=form, bus_data=all_bus, bus_error='Must Select a Bus', all_parent_kid=all_parent_kid) all_parent_kid = Parent.get_all_parent_kid_with_bus() all_bus = Bus().get_all() return render_template('admin/kid.html', form=form, bus_data=all_bus, all_parent_kid=all_parent_kid)
def pick_attendance(): js = request.json if 'kid_ids' in js and 'lat' in js and 'lon' in js: ids = js['kid_ids'] lat = js['lat'] lon = js['lon'] gps = Gps.tuple_to_str(lat, lon) time = utils.get_date_full() token = request.args['token'] j_id = Driver.get_active_ride(token) if j_id is None or j_id is '': return jsonify(status='error', message='Cant add,as not active ride') else: # filter valid ids id_from_db = Kid.get_kid_ids(j_id) ids_set = set(ids) ids_db_set = set(id_from_db) ids_valid = list(ids_set & ids_db_set) # intersection of kid ids for id in ids_valid: atten = Attendance(pick_present=1, kid_id=id, journey_id=j_id, pick_gps=gps, pick_time=time) atten.add() return jsonify(status='ok', message='Attendance taken') else: return jsonify(status='error', message='incorrect request')
def to_kid_list(cursor): if cursor is None: return None kids = [] for c in cursor: id = c[0] name = c[1] section = c[2] photo = c[3] kid = Kid(id=id, name=name, section=section, photo=photo) kids.append(kid) return kids
def get_kid_photo(): if 'kid_id' in request.args: k_id = request.args['kid_id'] token = request.args['token'] img_name = Kid.get_image_for_driver(token, k_id) if img_name is None: abort(404) else: from BusTrack import app final_image = app.config['IMAGE_KID'] + img_name try: return send_file(final_image, mimetype='image/jpeg') except: abort(404) else: abort(404)
def drop_attendance(): js = request.json if 'kid_ids' in js and 'lat' in js and 'lon' in js: ids = js['kid_ids'] lat = js['lat'] lon = js['lon'] gps = Gps.tuple_to_str(lat, lon) time = utils.get_date_full() token = request.args['token'] j_id = Driver.get_active_ride(token) if j_id is None or j_id is '': return jsonify(status='error', message='Cant add,since not active ride') else: # filter valid ids id_from_db = Kid.get_kid_drop_not_present(j_id) ids_set = set(ids) ids_db_set = set(id_from_db) ids_valid = list(ids_set & ids_db_set) # intersection of kid ids for id in ids_valid: Attendance.update_drop_attendance(id, gps, time, j_id) return jsonify(status='ok', message='Attendance taken') else: return jsonify(status='error', message='incorrect request')