def view_add_comment(environ, start_response): if environ['REQUEST_METHOD'].lower() == 'post': params = parse_qs(environ['wsgi.input'].read( int(environ.get('CONTENT_LENGTH', 0))).decode('utf-8')) surname = escape(params.get('surname', [''])[0]) name = escape(params.get('name', [''])[0]) patronymic = escape(params.get('patronymic', [''])[0]) city_id = int(escape(params.get('cityId', ['0'])[0])) phone = escape(params.get('phone', [''])[0]) email = escape(params.get('email', [''])[0]) comment_text = escape(params.get('comment', [''])[0]) with connection(DB_NAME) as conn: city = City.get_by_id(id=city_id, db_conn=conn) Comment(name=name, surname=surname, comment=comment_text, db_conn=conn, patronymic=patronymic, city=city, phone=phone, email=email).save() with connection(DB_NAME) as conn: with open('html/region_option.html', 'rt') as region_template: region_template_str = region_template.read() regions = '\n'.join((region_template_str.replace( '{id}', str(region.id)).replace('{name}', region.name) for region in Region.get_all(conn))) with open('html/add_comment.html', 'rt') as response: start_response('200 OK,', [('Content-Type', 'text/html; charset=UTF-8')]) return response.read().replace('{regions}', regions)
def register(): form = RegisterForm() # form.city.choices = [(city.uuid, city.name) for city in City.find_by_state('Kerala')] if current_user.is_authenticated: return redirect(url_for('index')) print(form.validate_on_submit()) print(form.errors) print(form.city.data) if form.is_submitted(): uname = form.uname.data mail = form.mail.data passw = form.passw.data conf_passw = form.conf_passw.data name = form.name.data sex = form.sex.data dob = form.dob.data bld_grp = form.bld_grp.data addr = form.addr.data state = form.state.data city = City.get_by_id(form.city.data) print(city, form.city.data) po_num = form.pincode.data mobile = form.mobile.data aadhar = form.aadhar.data donor = form.donor.data organ_donation = False bld_donation = False if donor != 'none': if donor == 'blood': bld_donation = True elif donor == 'organ': organ_donation = True elif donor == 'both': organ_donation = True bld_donation = True # organ_donation = bool(strtobool(form.organ_donation.data)) # bld_donation = bool(strtobool(form.bld_donation.data)) user_role = 'ef7bbd83-6bac-4700-9e26-4d33491aa8ea' print('selected role id is ', user_role) r = Role.find_by_id(user_role) print('selected role name is ', r.name) existing_user = User.query.filter_by(mobile=mobile, email=mail, username=uname, aadhar=aadhar).first() if existing_user is None: if conf_passw == passw: new_user = User(username=uname, email=mail, password=generate_password_hash(passw, method='sha256'), city=city.name, age=get_age(dob), name=name, sex=sex, dob=dob, pan='null', bld_grp=bld_grp, addr=addr, state=state, po_num=po_num, mobile=mobile, aadhar=aadhar, organ_donation=bool(organ_donation), bld_donaton=bool(bld_donation), role=user_role) new_user.save_to_db() return redirect(url_for("login")) print("Password don't match") flash(message="Passwords don't match!!") return render_template("register.html", form=form) print('user existing') flash(message='A user with same details already exists') return render_template("register.html", form=form) return render_template("register.html", form=form)
def search_blood_donor(): form = FindBloodDonorForm() form.city.choices = [(city.id, city.name) for city in City.find_by_state('Kerala')] if form.is_submitted(): city = City.get_by_id(form.city.data) state_name = form.state.data bld_grp = form.bld_grp.data city_name = city.name donors = User.find_blood_donor(location=city_name, blood_type=bld_grp) len_of_donors = len(donors) if current_user in donors: print('found ', current_user.username, ' in donors list. removing it!') len_of_donors = len_of_donors - 1 if len_of_donors > 0: return render_template('donor_search_result.html', data=donors, current_user=current_user, bld_grp=bld_grp, auth=is_auth()) flash(message="No donors found!!") render_template("search_blood_donor.html", current_user=current_user, form=form, auth=is_auth()) return render_template("search_blood_donor.html", current_user=current_user, form=form, auth=is_auth())
def update_profile(): user = User.find_by_username(username=current_user.username) city = City.get_id_by_name(_name=current_user.city) form = ProfileUpdateForm(city=city.uuid, bld_grp=user.bld_grp, sex=user.sex, pan=user.pan, organ_donation=bool(user.organ_donation), bld_donation=bool(user.bld_donation)) form.city.choices = [(city.uuid, city.name) for city in City.find_by_state('Kerala')] role = Role.find_by_id(current_user.role) print('user role is ', role.name) print(form.validate_on_submit()) print(form.errors) if 'pan' in form.errors: flash("PAN is a mandatory field \n PAN will always be a of 10 characters length") return render_template("update_profile.html", form=form, role=role.name) print('log') if form.validate_on_submit(): user.uname = form.uname.data user.mail = form.mail.data user.dob = form.dob.data user.age = get_age(form.dob.data) user.pan = form.pan.data user.name = form.name.data user.sex = form.sex.data user.bld_grp = form.bld_grp.data user.addr = form.addr.data user.state = form.state.data curr_city = City.get_by_id(form.city.data) user.city = curr_city.name user.po_num = form.pincode.data user.mobile = form.mobile.data user.aadhar = form.aadhar.data # user_role = form.role.data user.organ_donation = bool(strtobool(form.organ_donation.data)) user.bld_donation = bool(strtobool(form.bld_donation.data)) # role = Role.find_by_id(user_role) user.role = role.uuid user.save_to_db() print('user_id=', user.uuid, 'selected_role_id=', role.uuid, 'selected_role_name=', role.name) print('user_id=', user.uuid, 'role_id_db=', user.role, ) return redirect(url_for("view_profile")) return render_template("update_profile.html", form=form, role=role.name, auth=is_auth())
def search_hospital(): form = SearchHospitalForm() if form.state != "None": form.city.choices = [(city.uuid, city.name) for city in City.find_by_state(form.city.data)] if form.is_submitted(): if form.city != "None" or form.state != "None": city = City.get_by_id(form.city.data) state_name = city.name spec = form.spec.data scheme_id = form.scheme.data if spec != "None" and state_name != "" and not state_name.isspace(): hosps = Hospital.find_by_spec_and_state(_spec=spec, _state=state_name) print("scheme id is ", scheme_id) if scheme_id != '0': filtered = [] scheme = Scheme.find_by_scheme_id(scheme_id) print(scheme.name) print(scheme.partner_hospitals) for a_hosp in hosps: if a_hosp in scheme.partner_hospitals.all(): filtered.append(a_hosp) print(filtered) if len(filtered) <= 0: flash("No Hospitals found, why don't you try without the Scheme filter!!") return render_template("search_hospital.html", current_user=current_user, form=form) return render_template('searchResult.html', data=filtered, current_user=current_user, auth=is_auth(), searchterm=state_name) print("results form spec for ", decodeSpecialties(spec)[0]) if len(hosps.all()) > 0: return render_template('searchResult.html', data=hosps, current_user=current_user, auth=is_auth(), searchterm=state_name) else: print('no hospitals with ', spec) flash("No Hospitals found, why don't you try without the Speciality filter!!") return render_template("search_hospital.html", current_user=current_user, form=form, auth=is_auth()) elif state_name != '' and not state_name.isspace(): hosp = Hospital.find_by_state(state_name) if len(hosp.all()) > 0: print("scheme id is ", scheme_id) if scheme_id != '0': scheme = Scheme.find_by_scheme_id(scheme_id) print(scheme.name) filtered = [] for a_hosp in hosp: if a_hosp in scheme.partner_hospitals.all(): filtered.append(a_hosp) if len(filtered) <= 0: flash("No Hospitals found, why don't you try without the Scheme filter!!") return render_template("search_hospital.html", current_user=current_user, form=form, auth=is_auth()) return render_template('searchResult.html', data=filtered, current_user=current_user, auth=is_auth(), searchterm=state_name) return render_template('searchResult.html', data=hosp, current_user=current_user, searchterm=state_name, auth=is_auth()) else: flash('No Hospitals found!!') return render_template("search_hospital.html", current_user=current_user, form=form, auth=is_auth()) else: flash("Enter a valid query") return render_template("search_hospital.html", current_user=current_user, form=form, auth=is_auth()) flash("State and City are Mandatory Fields") return render_template("search_hospital.html", current_user=current_user, form=form, auth=is_auth()) return render_template("search_hospital.html", current_user=current_user, form=form, auth=is_auth())