Ejemplo n.º 1
0
def error413(e):
	users = db.users
	all_races_messages = calculate_races_messages()
	all_races = all_races_messages[0]
	all_messages = all_races_messages[1]
	len_all_races = all_races_messages[2]
	len_all_messages = all_races_messages[3]
	user = users.find_one({"Email":session["email"]})
	session["facebook_name"] = user.get("facebook_name","")
	get_image = user.get("image",None)
	if get_image != None:
		session["profile_pic"] = "static/img/profile_images/" + get_image + "?r=" + str(randint(1,10000000))
		var = session["profile_pic"]
		if "?" in var : 
			var = var.split("?")[0]
		var = ROOT_DIR + "/" + var
		(width, height) = get_size(var)
	else:
		(width, height) = (0,100)
	get_html = print_html(session["profile_pic"],session["facebook_name"],height,session["email"])
	return render_template(
    	'413.html',
    	get_html = Markup(get_html),
    	profile_pic = session["profile_pic"], 
		facebook_name = session["facebook_name"], 
		email = session["email"], 
		all_races = all_races,
		len_all_races = len_all_races,
		all_messages = all_messages,
		len_all_messages = len_all_messages,
    	), 413
Ejemplo n.º 2
0
def form_race_profile():
	all_races_messages = calculate_races_messages()
	all_races = all_races_messages[0]
	all_messages = all_races_messages[1]
	len_all_races = all_races_messages[2]
	len_all_messages = all_races_messages[3]
	users = db.users
	if request.method == "POST":
		podiums = str(request.form["podiums"]).strip()
		participation = str(request.form["participation"]).strip()
		users.update_one(
			{"Email":session["email"]},
			{ "$set" : {
					"podiums" : podiums,
					"participation" : participation,
					"form_race_profile" : True
					}
				}
			)
	user = users.find_one({"Email":session["email"]})
	session["facebook_name"] = user.get("facebook_name","")
	podiums = user.get("podiums","")
	participation = user.get("participation","")
	get_image = user.get("image",None)
	if get_image != None:
		session["profile_pic"] = "static/img/profile_images/" + get_image + "?r=" + str(randint(1,10000000))
		var = session["profile_pic"]
		if "?" in var : 
			var = var.split("?")[0]
		var = ROOT_DIR + "/" + var
		(width, height) = get_size(var)
	else:
		(width, height) = (0,100)
	get_html = print_html(session["profile_pic"],session["facebook_name"],height,session["email"])
	return render_template(
		"form_race_profile.html",
		profile_pic = session["profile_pic"], 
		facebook_name = session["facebook_name"], 
		email = session["email"], 
		all_races = all_races,
		len_all_races = len_all_races,
		all_messages = all_messages,
		len_all_messages = len_all_messages,
		width = width,
		height = height,
		podiums = podiums,
		participation = participation,
		get_html = Markup(get_html)
		)
Ejemplo n.º 3
0
def update_race_rankings():
    all_races_messages = calculate_races_messages()
    all_races = all_races_messages[0]
    all_messages = all_races_messages[1]
    len_all_races = all_races_messages[2]
    len_all_messages = all_races_messages[3]
    check = check_admin(session["email"])
    Email = ""
    profile_pic = ""
    facebook_name = ""
    logged_in = False
    if "email" in session:
        logged_in = True
        Email = session["email"]
    if "profile_pic" in session:
        profile_pic = session["profile_pic"]
    if "facebook_name" in session:
        facebook_name = session["facebook_name"]
    try:
        user = users.find_one({"Email": session["email"]})
        get_image = user.get("image", None)
        session["facebook_name"] = user.get("facebook_name", "")
        if get_image != None:
            session[
                "profile_pic"] = "static/img/profile_images/" + get_image + "?r=" + str(
                    randint(1, 10000000))
            var = session["profile_pic"]
            if "?" in var:
                var = var.split("?")[0]
            var = ROOT_DIR + "/" + var
            (width, height) = get_size(var)
        else:
            (width, height) = (0, 100)
    except:
        (width, height) = (0, 100)
    get_html = print_html(profile_pic, facebook_name, height, Email)
    if check == True:
        results = db.results
        users = db.users
        race_name = request.args.get("race_name", "")
        if race_name != "":
            result = results.find_one({"race_name": race_name})
            if result != None and result["active"] != "no" and result[
                    "active"] != "no":
                update_advantage_points(race_name)
                # Update the final score for the race
                difficulty = result.get("difficulty", 1)
                if difficulty == 0:
                    difficulty = 1
                for diff in range(difficulty):
                    score_dic = []
                    max_total_time = float("-inf")
                    min_total_time = float("inf")
                    prev_ratings = {}
                    for ser_num in result["race_result"]:
                        cur_score = {}
                        cur_score[ser_num] = {
                            "adv_point":
                            result["race_result"][ser_num]["advantage_point"],
                            "total_time":
                            result["race_result"][ser_num]["total_race_time"],
                        }
                        rider_tag = result["race_result"][ser_num]["rider_tag"]
                        if rider_tag != "":
                            user = users.find_one({"_id": ObjectId(rider_tag)})
                            try:
                                prev_ratings[ser_num] = user["elo_rating"]
                            except:
                                pass
                        if result["race_result"][ser_num][
                                "total_race_time"] != "DNF" and result[
                                    "race_result"][ser_num][
                                        "total_race_time"] != "" and result[
                                            "race_result"][ser_num][
                                                "total_race_time"] != "dnf":
                            max_total_time = max(
                                result["race_result"][ser_num]
                                ["total_race_time"], max_total_time)
                            min_total_time = min(
                                result["race_result"][ser_num]
                                ["total_race_time"], min_total_time)
                        score_dic.append(cur_score)
                    final_scores = {}
                    div_factor = 100.0 / (max_total_time - min_total_time)
                    dnf_riders = []
                    for scores in score_dic:
                        adv_point = 0
                        for score in scores:
                            ser_num = score
                            cur_serial_num = "race_result.{ser_num}.final_score".format(
                                ser_num=ser_num)
                            cur_score = scores[score]["total_time"]
                            adv_point = scores[score]["adv_point"]
                        try:
                            final_scores[ser_num] = "%.3f" % (
                                (int(max_total_time) - int(cur_score)) *
                                div_factor + adv_point)
                            results.update_one({"race_name": race_name}, {
                                "$set": {
                                    str(cur_serial_num):
                                    float(final_scores[ser_num])
                                }
                            })
                        except:
                            dnf_riders.append(ser_num)
                            results.update_one(
                                {"race_name": race_name},
                                {"$set": {
                                    str(cur_serial_num): adv_point
                                }})
                    final_scores = sorted(final_scores.items(),
                                          key=operator.itemgetter(1))
                    ct = 0
                    # Calculate the elo rating for every rider
                    final_ratings = elo_match()
                    ser_num_list = []
                    for i in final_scores:
                        try:
                            rating = float(prev_ratings[i[0]])
                            ser_num_list.append(i[0])
                            ct += 1
                            final_ratings.add_rider(i[0], ct, rating)
                        except:
                            pass
                    final_ratings.calculate_elo_rating()
                    #update elo_rating for every rider
                    for i in ser_num_list:
                        cur_rating = float("%.3f" % final_ratings.get_elo(i))
                        rider_tag = result["race_result"][i]["rider_tag"]
                        if rider_tag != "":
                            users.update_one(
                                {"_id": ObjectId(rider_tag)},
                                {"$set": {
                                    "elo_rating": cur_rating,
                                }})
                # Update CGPA rating for every rider
                update_cgpa_ratings_with_name(race_name)

                return render_template(
                    "update_rank.html",
                    get_html=Markup(get_html),
                    logged_in=logged_in,
                    profile_pic=profile_pic,
                    facebook_name=facebook_name,
                    email=Email,
                    all_races=all_races,
                    len_all_races=len_all_races,
                    all_messages=all_messages,
                    len_all_messages=len_all_messages,
                    race_name=race_name,
                )
            else:
                return render_template(
                    "error.html",
                    error=
                    "No Race Found , pass race name as argument -- /update_rankings?race_name={name of existing race}",
                    get_html=Markup(get_html),
                    logged_in=logged_in,
                    profile_pic=profile_pic,
                    facebook_name=facebook_name,
                    email=Email,
                    all_races=all_races,
                    len_all_races=len_all_races,
                    all_messages=all_messages,
                    len_all_messages=len_all_messages,
                )
        else:
            return render_template(
                "error.html",
                error=
                "No Race Found , pass race name as argument -- /update_rankings?race_name={name of existing race}",
                get_html=Markup(get_html),
                profile_pic=profile_pic,
                facebook_name=facebook_name,
                logged_in=logged_in,
                email=Email,
                all_races=all_races,
                len_all_races=len_all_races,
                all_messages=all_messages,
                len_all_messages=len_all_messages,
            )
    else:
        return render_template(
            "error.html",
            error="You Are Not Admin",
            get_html=Markup(get_html),
            profile_pic=profile_pic,
            facebook_name=facebook_name,
            logged_in=logged_in,
            email=Email,
            all_races=all_races,
            len_all_races=len_all_races,
            all_messages=all_messages,
            len_all_messages=len_all_messages,
        )
Ejemplo n.º 4
0
def rankings():
    all_races_messages = calculate_races_messages()
    all_races = all_races_messages[0]
    all_messages = all_races_messages[1]
    len_all_races = all_races_messages[2]
    len_all_messages = all_races_messages[3]
    users = db.users
    Email = ""
    profile_pic = ""
    facebook_name = ""
    logged_in = False
    if "email" in session:
        Email = session["email"]
        logged_in = True
    if "profile_pic" in session:
        profile_pic = session["profile_pic"]
    if "facebook_name" in session:
        facebook_name = session["facebook_name"]
    try:
        user = users.find_one({"Email": session["email"]})
        get_image = user.get("image", None)
        session["facebook_name"] = user.get("facebook_name", "")
        if get_image != None:
            session[
                "profile_pic"] = "static/img/profile_images/" + get_image + "?r=" + str(
                    randint(1, 10000000))
            var = session["profile_pic"]
            if "?" in var:
                var = var.split("?")[0]
            var = ROOT_DIR + "/" + var
            (width, height) = get_size(var)
        else:
            (width, height) = (0, 100)
    except:
        (width, height) = (0, 100)
    get_html = print_html(profile_pic, facebook_name, height, Email)
    # Retrieve the sorted data to calculate ranks
    full_data = users.find({}, {
        "Name": 1,
        "DOB": 1,
        "elo_rating": 1,
        "cgpa_rating": 1
    }).sort("elo_rating", pymongo.DESCENDING)
    all_data = []
    ct = 0
    for user in full_data:
        ct += 1
        cur_data = {}
        rating = user.get("elo_rating", 1000)
        cgpa_rating = user.get("cgpa_rating", 0)
        name = user.get("Name", "")
        full_name = ""
        if name == "":
            name = False
        else:
            name_prefix = name.get("prefix", "")
            name_first = name.get("first_name", "")
            name_middle = name.get("middle_name", "")
            name_last = name.get("last_name", "")
            if name_prefix == "" and name_last == "" and name_middle == "" and name_first == "":
                name = False
            else:
                full_name = name_prefix + " " + name_first + " " + name_middle + " " + name_last
                full_name = full_name.split()
                full_name = " ".join(full_name)
                name = True
        dob = user.get("DOB", False)
        age = 0
        if dob != False:
            date_of_birth = {}
            date_of_birth["date"] = dob.get("date", "")
            date_of_birth["month"] = dob.get("month", "")
            date_of_birth["year"] = dob.get("year", "")
            if date_of_birth["date"] == "" or date_of_birth[
                    "month"] == "" or date_of_birth["year"] == "":
                dob = "Enter your Date of Birth"
            else:
                age = calculate_age(date_of_birth)
        # Update all the data for showing
        cur_data["name"] = full_name
        cur_data["age"] = age
        cur_data["rating"] = rating
        cur_data["cgpa_rating"] = cgpa_rating
        cur_data["rank"] = ct
        all_data.append(cur_data)
    return render_template("ranking.html",
                           get_html=Markup(get_html),
                           profile_pic=profile_pic,
                           facebook_name=facebook_name,
                           email=Email,
                           all_races=all_races,
                           len_all_races=len_all_races,
                           all_messages=all_messages,
                           len_all_messages=len_all_messages,
                           all_data=all_data,
                           logged_in=logged_in)
Ejemplo n.º 5
0
def userhome():
	users = db.users
	all_races_messages = calculate_races_messages()
	all_races = all_races_messages[0]
	all_messages = all_races_messages[1]
	len_all_races = all_races_messages[2]
	len_all_messages = all_races_messages[3]
	user = users.find_one({"Email":session["email"]})
	check_registered = "Unregistered"
	if "DOB" in user:
		check_registered = "Registered"
	profile_pic = user.get("profile_pic",None)
	facebook_name = user.get("facebook_name",None)
	image = user.get("image","")
	if image == "":
		session["profile_pic"] = profile_pic
		(width, height) = (0,100)
	else:
		session["profile_pic"] = "static/img/profile_images/" + image + "?r=" + str(randint(1,10000000))
		var = session["profile_pic"]
		if "?" in var : 
			var = var.split("?")[0]
		var = ROOT_DIR + "/" + var
		(width, height) = (0,100)
	session["facebook_name"] = facebook_name
	get_html = print_html(session["profile_pic"],session["facebook_name"],height,session["email"])
	participation = user.get("participation",False)
	if participation != False:
		participation = participation.split(",")
	podiums = user.get("podiums",False)
	if podiums != False:
		podiums = podiums.split(",")
	name = user.get("Name","")
	full_name = ""
	if name == "":
		name = False
	else:
		name_prefix = name.get("prefix","")
		name_first = name.get("first_name","")
		name_middle = name.get("middle_name","")
		name_last = name.get("last_name","") 
		if name_prefix == "" and name_last == "" and name_middle == "" and name_first == "":
			name = False
		else:
			full_name = name_prefix + " " + name_first + " " + name_middle + " " + name_last
			full_name = full_name.split()
			full_name = " ".join(full_name)
			name = True
	name_alias = user.get("name_alias","Enter your Alias")
	Mobile = user.get("Mobile","Enter your Mobile Number")
	address = user.get("address","Enter your Address")
	full_address = ""
	map_address = ""
	if address != "Enter your Address":
		address_part_one = address.get("address1","")
		address_part_two = address.get("address2","")
		address_part_three = address.get("state","")
		address_part_four = address.get("country","")
		full_address = address_part_one + ", " + address_part_two + ", " + address_part_three + ", " + address_part_four
		map_address = address_part_two + ", " + address_part_three + ", " + address_part_four
	emergency_contact = user.get("emergency_contact","Enter your Emergency Contact")
	relation = ""
	relation_name = ""
	relation_contact = ""
	if emergency_contact != "Enter your Emergency Contact":
		relation = emergency_contact.get("relation","")
		relation_name = emergency_contact.get("relation_name","")
		relation_contact = emergency_contact.get("relation_contact_number","")
		emergency_contact = True
	else:
		emergency_contact = False
	dob = user.get("DOB",False)
	age = 0
	if dob != False:
		date_of_birth = {}
		date_of_birth["date"] = dob.get("date","")
		date_of_birth["month"] = dob.get("month","")
		date_of_birth["year"] = dob.get("year","")
		if date_of_birth["date"] == "" or date_of_birth["month"] == "" or date_of_birth["year"] == "":
			dob = "Enter your Date of Birth"
		else:
			age = calculate_age(date_of_birth)
	blood_group = user.get("Blood Group",False)
	nationality = user.get("Nationality",False)
	reg_id = str(user.get("_id",""))
	path_id_proof = user.get("id_proof","")
	download_id_proof = ""
	download_rider_insurance = ""
	download_rider_id_proof = ""
	if path_id_proof != "":
		download_id_proof = "id_proof." + path_id_proof.split(".")[1]
		path_id_proof = "/static/id_proof/" + path_id_proof
	path_rider_insurance = user.get("rider_insurance_certificate","")
	if path_rider_insurance != "":
		download_rider_insurance = "medical_insurance_certificate." + path_rider_insurance.split(".")[1]
		path_rider_insurance = "/static/rider_insurance_certificate/" + path_rider_insurance
 	path_rider_id_proof = user.get("rider_id_proof","")
 	if path_rider_id_proof != "":
 		download_rider_id_proof = "rider_id_proof." + path_rider_id_proof.split(".")[1]
 		path_rider_id_proof = "/static/rider_id_proof/" + path_rider_id_proof
 	allergy = user.get("Allergy",False)
 	if allergy != False:
 		allergy = allergy.split(",")
 	bike_details = user.get("bike_details",False)
 	bike_brand = ""
 	bike_size = ""
 	bike_style = []
 	bike_brand_other_input = ""
 	if bike_details != False:
 		bike_brand = bike_details.get("bike_brand","")
 		bike_size = bike_details.get("bike_size","")
 		bike_style = bike_details.get("bike_style",[])
 		if bike_style != []:
 			bike_style = ",".join(bike_style)
 		bike_brand_other_input = bike_details.get("bike_brand_other_input","")
 	riding_style = user.get("riding_style",[])
 	if riding_style == []:
 		check_riding_style = False
 	else:
 		check_riding_style = True
 	sponsors = user.get("sponsors",False)
 	if sponsors != False:
	 	sponsors = sponsors.split(",")
	team_name = user.get("team_name",False)
	rider_type = user.get("rider_type",False)
	uci_status = user.get("uci_status",False)
	uci_id = ""
	if uci_status != False:
		if uci_status == "yes":
			uci_id = user.get("uci_id","")
	jersey_size = user.get("Jerseey size",False)
	# check for fully registered or not
	form_personal_profile = user.get("form_personal_profile",False)
	form_rider_profile = user.get("form_rider_profile",False)
	form_medical_profile = user.get("form_medical_profile",False)
	form_bike_profile = user.get("form_bike_profile",False)
	form_race_profile = user.get("form_race_profile",False)
	forms_not_completed = []
	if form_personal_profile == False:
		form_not_completed = {}
		form_not_completed["name"] = "Form Personal Profile"
		form_not_completed["url"] = "/form_personal_profile"
		forms_not_completed.append(form_not_completed)
	if form_race_profile == False:
		form_not_completed = {}
		form_not_completed["name"] = "Form Race Profile"
		form_not_completed["url"] = "/form_race_profile"
		forms_not_completed.append(form_not_completed)
	if form_bike_profile == False:
		form_not_completed = {}
		form_not_completed["name"] = "Form Bike Profile"
		form_not_completed["url"] = "/form_bike_profile"
		forms_not_completed.append(form_not_completed)
	if form_rider_profile == False:
		form_not_completed = {}
		form_not_completed["name"] = "Form Rider Profile"
		form_not_completed["url"] = "/form_rider_profile"
		forms_not_completed.append(form_not_completed)
	if form_medical_profile == False:
		form_not_completed = {}
		form_not_completed["name"] = "Form Medical Profile"
		form_not_completed["url"] = "/form_medical_profile"
		forms_not_completed.append(form_not_completed)
	dream_bike = user.get("dream_bike","Complete the form")
	dream_bike_brand = user.get("dream_bike_brand","Complete the form")
	first_bike = user.get("first_bike","Complete the form")
	often_rides = user.get("often_rides","Complete the form")
	fav_trail = user.get("fav_trail","Complete the form")
	dream_trail = user.get("dream_trail","Complete the form")
	best_exp = user.get("best_exp","Complete the form")
	return render_template(
		"dashboard.html", 
		profile_pic = session["profile_pic"], 
		facebook_name = facebook_name, 
		email = session["email"], 
		check_registered = check_registered,
		all_races = all_races,
		len_all_races = len_all_races,
		all_messages = all_messages,
		len_all_messages = len_all_messages,
		width = width,
		height = height,
		get_html = Markup(get_html),
		participation = participation,
		podiums = podiums,
		full_name = full_name,
		name_alias = name_alias,
		Mobile = Mobile,
		full_address = full_address,
		relation = relation,
		relation_name = relation_name,
		relation_contact = relation_contact,
		name = name,
		emergency_contact = emergency_contact,
		age = age,
		reg_id = reg_id,
		nationality = nationality,
		blood_group = blood_group,
		path_id_proof = path_id_proof,
		path_rider_insurance = path_rider_insurance,
		download_rider_insurance = download_rider_insurance,
		download_id_proof = download_id_proof,
		allergy = allergy,
		bike_brand = bike_brand,
		bike_style = bike_style,
		bike_size = bike_size,
		map_address = map_address,
		bike_brand_other_input = bike_brand_other_input,
		bike_details = bike_details,
		riding_style = riding_style,
		check_riding_style = check_riding_style,
		sponsors = sponsors,
		team_name = team_name,
		rider_type = rider_type,
		jersey_size = jersey_size,
		uci_status = uci_status,
		uci_id = uci_id,
		path_rider_id_proof = path_rider_id_proof,
		download_rider_id_proof = download_rider_id_proof,
		forms_not_completed = forms_not_completed,
		total_forms_completed = 5 - len(forms_not_completed),
		percentage_completion = (5 - len(forms_not_completed))*20,
		dream_bike = dream_bike,
		dream_bike_brand = dream_bike_brand,
		first_bike = first_bike,
		often_rides = often_rides,
		fav_trail = fav_trail,
		dream_trail = dream_trail,
		best_exp = best_exp
		)
Ejemplo n.º 6
0
def form_bike_profile():
	all_races_messages = calculate_races_messages()
	all_races = all_races_messages[0]
	all_messages = all_races_messages[1]
	len_all_races = all_races_messages[2]
	len_all_messages = all_races_messages[3]
	error = ""
	users = db.users
	if request.method == "POST":
		bike_brand = str(request.form["bike_brand"]).strip()
		bike_brand_other_input = ""
		if bike_brand == "other":
			bike_brand_other_input = request.form["bike_brand_other_input"]
		bike_style = request.form.getlist("bike_style")
		bike_size = str(request.form["bike_size"]).strip()	
		dream_bike = str(request.form["dream_bike"]).strip()
		dream_bike_brand = str(request.form["dream_bike_brand"]).strip()
		error = ""
		if bike_brand == "other":
			if bike_brand_other_input == "":
				error = "Enter bike brand"
		if bike_brand == "" or bike_style == "" or bike_size == "" or dream_bike == "" or dream_bike_brand == "": 
			error = "Enter required details"
		if error == "":
			users.update_one(
				{"Email":session["email"]},
				{ "$set" : {
						"bike_details" : {
							"bike_brand" : bike_brand,
							"bike_style" : bike_style,
							"bike_size" : bike_size,
							"bike_brand_other_input" : bike_brand_other_input
							},
						"form_bike_profile" : True,
						"dream_bike" : dream_bike,
						"dream_bike_brand" : dream_bike_brand
						}
					}
				)
	user = users.find_one({"Email":session["email"]})
	dream_bike = user.get("dream_bike","")
	dream_bike_brand = user.get("dream_bike_brand","")
	bike_details = user.get("bike_details",None)
	if bike_details is None:
		bike_brand = ""
		bike_size = ""
		bike_style = []
		bike_brand_other_input = ""
	else:
		bike_size = bike_details.get("bike_size","")
		bike_brand = bike_details.get("bike_brand","")
		bike_style = bike_details.get("bike_style","")
		bike_brand_other_input = bike_details.get("bike_brand_other_input",[])
	get_image = user.get("image",None)
	if get_image != None:
		session["profile_pic"] = "static/img/profile_images/" + get_image + "?r=" + str(randint(1,10000000))
		var = session["profile_pic"]
		if "?" in var : 
			var = var.split("?")[0]
		var = ROOT_DIR + "/" + var
		(width, height) = get_size(var)
	else:
		(width, height) = (0,100)
	get_html = print_html(session["profile_pic"],session["facebook_name"],height,session["email"])
	return render_template(
		"form_bike_profile.html",
		profile_pic = session["profile_pic"], 
		facebook_name = session["facebook_name"], 
		email = session["email"], 
		all_races = all_races,
		len_all_races = len_all_races,
		all_messages = all_messages,
		len_all_messages = len_all_messages,
		bike_brand = bike_brand,
		bike_brand_other_input = bike_brand_other_input,
		bike_size = bike_size,
		bike_style = bike_style,
		width = width,
		height = height,
		error = error,
		get_html = Markup(get_html),
		dream_bike_brand = dream_bike_brand,
		dream_bike = dream_bike,
		)
Ejemplo n.º 7
0
def form_medical_profile():
	all_races_messages = calculate_races_messages()
	all_races = all_races_messages[0]
	all_messages = all_races_messages[1]
	len_all_races = all_races_messages[2]
	len_all_messages = all_races_messages[3]
	users = db.users
	error = ""
	if request.method == "POST":
		blood_group = str(request.form["blood_group"]).strip()
		allergies = str(request.form["allergies"]).strip()
		rider_insurance_certificate = request.files["rider_insurance_certificate"]
		emg_name = str(request.form["emg_name"]).strip()
		emg_number = str(request.form["emg_number"]).strip()
		emg_relation = str(request.form["emg_relation"]).strip()
		error = ""
		if validate_name_prefix(emg_name) == False:
			error = "Correct the emergency person's name"
		if blood_group == "" or emg_name == "" or emg_relation == "" or emg_number == "": 
			error = "Fill all the required details"
		user = users.find_one({"Email":session["email"]})
		check_for_file = user.get("rider_insurance_certificate", None)
		if error == "":
			if rider_insurance_certificate:
				if check_for_file is not None:
					os.remove(app.config['UPLOAD_FOLDER_ID_RIDER_INSURANCE'] + check_for_file)
				file_name = secure_filename(rider_insurance_certificate.filename)
				filetype = file_name.split(".")[1]
				if filetype == "jpg" or filetype == "png" or filetype == "bmp" or filetype == "doc" or filetype == "docx" or filetype == "pdf":
					actual_filename = str(user.get("_id")) + "." + filetype
					rider_insurance_certificate.save(os.path.join(app.config['UPLOAD_FOLDER_ID_RIDER_INSURANCE'], file_name))
					os.rename(os.path.join(app.config['UPLOAD_FOLDER_ID_RIDER_INSURANCE'], file_name),os.path.join(app.config['UPLOAD_FOLDER_ID_RIDER_INSURANCE'], actual_filename))
					users.update_one(
						{"Email":session["email"]},
							{ "$set" : {
							"rider_insurance_certificate": actual_filename
					}})
			users.update_one(
				{"Email":session["email"]},
				{ "$set" : {
						"emergency_contact" : {
							"relation_contact_number" : emg_number,
							"relation_name" : emg_name,
							"relation" : emg_relation
							},	
						"Blood Group" : blood_group,
						"Allergy" : allergies,
						"form_medical_profile" : True
						}
					}
				)
	user = users.find_one({"Email":session["email"]})
	emergency_contact = user.get("emergency_contact",None)
	if emergency_contact is None:
		emg_name = ""
		emg_relation = ""
		emg_number = ""
	else:
		emg_name = emergency_contact.get("relation_name","")
		emg_number = emergency_contact.get("relation_contact_number","")
		emg_relation = emergency_contact.get("relation","")
	blood_group = user.get("Blood Group","")
	allergies = user.get("Allergy","")
	get_image = user.get("image",None)
	get_rider_insurance_certificate = user.get("rider_insurance_certificate",None)
	# check for uploaded image 
	if get_image != None:
		session["profile_pic"] = "static/img/profile_images/" + get_image + "?r=" + str(randint(1,10000000))
		var = session["profile_pic"]
		if "?" in var : 
			var = var.split("?")[0]
		var = ROOT_DIR + "/" + var
		(width, height) = get_size(var)
	else:
		(width, height) = (0,100)
	rider_insurance_uploaded = user.get("rider_insurance_certificate","")
	if rider_insurance_uploaded != "":
		rider_insurance_uploaded = "Already Uploaded"
	else:
		rider_insurance_uploaded = "Upload file"
	get_html = print_html(session["profile_pic"],session["facebook_name"],height,session["email"])
	return render_template(
		"form_medical_profile.html",
		profile_pic = session["profile_pic"], 
		facebook_name = session["facebook_name"], 
		email = session["email"], 
		all_races = all_races,
		len_all_races = len_all_races,
		all_messages = all_messages,
		len_all_messages = len_all_messages,
		allergies = allergies,
		blood_group = blood_group,
		get_rider_insurance_certificate = get_rider_insurance_certificate,
		emg_name = emg_name,
		emg_number = emg_number,
		emg_relation = emg_relation,
		width = width,
		height = height,
		error = error,
		rider_insurance_uploaded = rider_insurance_uploaded,
		get_html = Markup(get_html)
		)
Ejemplo n.º 8
0
def form_rider_profile():
	error = ""
	all_races_messages = calculate_races_messages()
	all_races = all_races_messages[0]
	all_messages = all_races_messages[1]
	len_all_races = all_races_messages[2]
	len_all_messages = all_races_messages[3]
	users = db.users
	if request.method == "POST":
		name_alias = str(request.form["name_alias"]).strip()
		rider_type = str(request.form["rider_type"]).strip()
		rider_type_other_input = ""
		if rider_type == "other":
			rider_type_other_input = str(request.form["rider_type_other_input"]).strip()
			rider_type = rider_type_other_input
		
		riding_style = request.form.getlist("riding_style")
		rider_id_file = request.files["rider_id"]
		uci_status = str(request.form["uci_status"]).strip()
		uci_id = ""
		if uci_status == "yes":
			uci_id = str(request.form["uci_id"]).strip()
		team_name = str(request.form["team_name"]).strip()
		sponsors = str(request.form["sponsors"]).strip()
		jersey_size = str(request.form["jersey_size"]).strip()
		first_bike = str(request.form["first_bike"]).strip()
		often_rides = int(request.form["often_rides"])
		fav_trail = str(request.form["fav_trail"]).strip()
		dream_trail = str(request.form["dream_trail"]).strip()
		best_exp = str(request.form["best_exp"]).strip()
		
		user = users.find_one({"Email":session["email"]})
		check_for_file = user.get("rider_id_proof", None)
		error = ""
		if team_name == "" or rider_type == "" or name_alias == "" or first_bike == "" or often_rides == "" or fav_trail == "" or dream_trail == "" or best_exp == "":
			error = "Fill all the details"
		if uci_status == "yes":
			if uci_id == "":
				error = "Fill uci id"
		if rider_type == "other":
			if rider_type_other_input == "":
				error = "Enter other rider type"
		if error == "":
			if rider_id_file:
				if check_for_file is not None:
					os.remove(app.config['UPLOAD_FOLDER_ID_RIDER'] + check_for_file)
				file_name = secure_filename(rider_id_file.filename)
				filetype = file_name.split(".")[1]
				if filetype == "jpg" or filetype == "png" or filetype == "bmp" or filetype == "doc" or filetype == "docx" or filetype == "pdf":
					actual_filename = str(user.get("_id")) + "." + filetype
					rider_id_file.save(os.path.join(app.config['UPLOAD_FOLDER_ID_RIDER'], file_name))
					os.rename(os.path.join(app.config['UPLOAD_FOLDER_ID_RIDER'], file_name),os.path.join(app.config['UPLOAD_FOLDER_ID_RIDER'], actual_filename))
					users.update_one(
						{"Email":session["email"]},
							{ "$set" : {
							"rider_id_proof": actual_filename
					}})
			users.update_one(
				{"Email":session["email"]},
				{ "$set" : {
						"name_alias" : name_alias,	
						"rider_type" : rider_type,
						"riding_style" : riding_style,
						"sponsors" : sponsors,
						"uci_status" : uci_status,
						"uci_id" : uci_id,
						"team_name" : team_name,
						"Jerseey size" : jersey_size,
						"form_rider_profile" : True,
						"first_bike" : first_bike,
						"often_rides" : often_rides,
						"fav_trail" : fav_trail,
						"dream_trail" : dream_trail,
						"best_exp" : best_exp
						}
					}
				)
	user = users.find_one({"Email":session["email"]})
	name_alias = user.get("name_alias","")
	rider_type = user.get("rider_type","")
	riding_style = user.get("riding_style",[])
	get_rider_id_proof = user.get("rider_id_proof",None)
	sponsors = user.get("sponsors","")
	uci_status = user.get("uci_status","")
	uci_id = user.get("uci_id","")
	team_name = user.get("team_name","")
	jersey_size = user.get("Jerseey size","")
	first_bike = user.get("first_bike","")
	often_rides = user.get("often_rides","")
	fav_trail = user.get("fav_trail","")
	dream_trail = user.get("dream_trail","")
	best_exp = user.get("best_exp","")
	get_image = user.get("image",None)
	if get_image != None:
		session["profile_pic"] = "static/img/profile_images/" + get_image + "?r=" + str(randint(1,10000000))
		var = session["profile_pic"]
		if "?" in var : 
			var = var.split("?")[0]
		var = ROOT_DIR + "/" + var
		(width, height) = get_size(var)
	else:
		(width, height) = (0,100)
	rider_id_proof_uploaded = user.get("rider_id_proof","")
	if rider_id_proof_uploaded != "":
		rider_id_proof_uploaded = "Already Uploaded"
	else:
		rider_id_proof_uploaded = "Upload file"
	get_html = print_html(session["profile_pic"],session["facebook_name"],height,session["email"])
	return render_template(
		"form_rider_profile.html",
		profile_pic = session["profile_pic"], 
		facebook_name = session["facebook_name"], 
		email = session["email"], 
		all_races = all_races,
		len_all_races = len_all_races,
		all_messages = all_messages,
		len_all_messages = len_all_messages,
		name_alias = name_alias,
		rider_type = rider_type,
		riding_style = riding_style,
		get_rider_id_proof = get_rider_id_proof,
		sponsors = sponsors,
		uci_status = uci_status,
		uci_id = uci_id,
		team_name = team_name,
		jersey_size = jersey_size,
		width = width,
		height = height,
		error = error,
		rider_id_proof_uploaded = rider_id_proof_uploaded,
		get_html = Markup(get_html),
		first_bike = first_bike,
		often_rides = often_rides,
		fav_trail = fav_trail,
		dream_trail = dream_trail,
		best_exp = best_exp,
		)
Ejemplo n.º 9
0
def form_personal_profile():
	users = db.users
	all_races_messages = calculate_races_messages()
	all_races = all_races_messages[0]
	all_messages = all_races_messages[1]
	len_all_races = all_races_messages[2]
	len_all_messages = all_races_messages[3]
	error = ""
	if request.method == "POST":
		name_prefix = str(request.form["name_prefix"]).strip()
		name_first = str(request.form["name_first"]).strip()
		name_middle = str(request.form["name_middle"]).strip()
		mobile_number = str(request.form["mobile"]).strip()
		name_last = str(request.form["name_last"]).strip()
		gender = str(request.form["gender"]).strip()
		name_father = str(request.form["name_father"]).strip()
		address_part_one = str(request.form["address_part_one"]).strip()
		address_part_two = str(request.form["address_part_two"]).strip()
		address_part_three = str(request.form["address_part_three"]).strip()
		address_part_four = str(request.form["address_part_four"]).strip()
		nationality = str(request.form["nation"]).strip()
		dob = str(request.form["dob"]).strip()
		dob = dob.split("-")[::-1]
		flag = 0
		for i in dob:
			try:
				check_int = int(i)
			except:
				flag = 1
				error = "Correct the date"
		if flag == 0 and datetime.datetime(year=int(dob[2]),month=int(dob[1]),day=int(dob[0])) > datetime.datetime.now():
			error = "Date exceeds today"
		try:
			file = request.files["file"]
		except RequestEntityTooLarge:
			flash('File size too large.  Limit is 1 MB.')
			error = "File size too large.  Limit is 1 MB."
		try:
			id_file = request.files["filename"]
		except RequestEntityTooLarge:
			flash('File size too large.  Limit is 1 MB.')
			error = "File size too large.  Limit is 1 MB."
		user = users.find_one({"Email":session["email"]})
		check_for_image = user.get("image", None)
		new_mobile_number = "+"
		for i in mobile_number:
			if i in number_list:
				new_mobile_number += i
		mobile_number = new_mobile_number 
		error = ""
		# Backend Validation 

		if validate_name_prefix(name_prefix) == False:
			error = "Enter Correct name prefix (only characters accepted)"
		if validate_name(name_first) == False:
			error = "Enter Correct first name (only characters accepted)"
		if validate_name(name_middle) == False:
			error = "Enter Correct middle name (only characters accepted)"
		if validate_name(name_last) == False:
			error = "Enter Correct last name (only characters accepted)"
		if validate_name(name_father) == False:
			error = "Enter Correct father name (only characters accepted)"
		if name_middle != "":
			if name_last == "":
				error = "Enter Last Name Also"
		if name_first == "" or name_last == "" or name_father == "" or address_part_four == "" or address_part_three == "" or address_part_two == "" or address_part_one == "" or mobile_number == "" or nationality == "" or dob == "":
			error = "Please enter all the details"
		if error == "":
			# Saving and uploading the file 
			if file:
				file_name = secure_filename(file.filename)
				filetype = file_name.split(".")[1]
				if filetype == "jpg" or filetype == "png" or filetype == "bmp":
					actual_filename = str(user.get("_id")) + "." + filetype
					file.save(os.path.join(app.config['UPLOAD_FOLDER'], file_name))
					os.rename(os.path.join(app.config['UPLOAD_FOLDER'], file_name),os.path.join(app.config['UPLOAD_FOLDER'], actual_filename))
					users.update_one(
						{"Email":session["email"]},
							{ "$set" : {
							"image": actual_filename
					}})
			check_for_file = user.get("id_proof", None)
			if id_file:
				if check_for_file is not None:
					os.remove(app.config['UPLOAD_FOLDER_ID'] + check_for_file)
				file_name = secure_filename(id_file.filename)
				filetype = file_name.split(".")[1]
				if filetype == "jpg" or filetype == "png" or filetype == "bmp" or filetype == "doc" or filetype == "docx" or filetype == "pdf":
					actual_filename = str(user.get("_id")) + "." + filetype			
					id_file.save(os.path.join(app.config['UPLOAD_FOLDER_ID'], file_name))
					os.rename(os.path.join(app.config['UPLOAD_FOLDER_ID'], file_name),os.path.join(app.config['UPLOAD_FOLDER_ID'], actual_filename))
					users.update_one(
						{"Email":session["email"]},
							{ "$set" : {
							"id_proof": actual_filename
					}})
			# update the details
			users.update_one(
				{"Email":session["email"]},
				{ "$set" : {
						"Name" : {
									"prefix" : name_prefix,
									"first_name" : name_first,
									"middle_name" : name_middle,
									"last_name" : name_last
								},	
						"address" : {
									"address1" : address_part_one,
									"address2" : address_part_two,
									"state" : address_part_three,
									"country" : address_part_four
								},
						"Nationality" : nationality,
						"Gender" : gender,
						"father_name" : name_father,
						"DOB" : {
									"date" : int(dob[0]),
									"month" : int(dob[1]),
									"year" : int(dob[2])
								},
						"Mobile" : mobile_number,
						"form_personal_profile" : True
						}
					}
				)
	# get the details
	user = users.find_one({"Email":session["email"]})
	mobile_number = user.get("Mobile","")
	name = user.get("Name",None)
	if name is None:
		name_prefix = ""
		name_first = ""
		name_last = ""
		name_middle = ""
	else:
		name_prefix = name.get("prefix","")
		name_middle = name.get("middle_name","")
		name_last = name.get("last_name","")
		name_first = name.get("first_name","")
	address = user.get("address",None)
	if address is None:
		address_part_one = ""
		address_part_four = ""
		address_part_three = ""
		address_part_two = ""
	else:
		address_part_one = address.get("address1","")
		address_part_four = address.get("country","")
		address_part_three = address.get("state","")
		address_part_two = address.get("address2","")
	get_id_proof = user.get("id_proof",None)
	get_image = user.get("image",None)
	if get_image != None and get_image != "":
		session["profile_pic"] = "static/img/profile_images/" + get_image + "?r=" + str(randint(1,10000000))
		var = session["profile_pic"]
		if "?" in var : 
			var = var.split("?")[0]
		var = ROOT_DIR + "/" + var
		(width, height) = get_size(var)
	else:
		(width, height) = (0,100)
	get_html = print_html(session["profile_pic"],session["facebook_name"],height,session["email"])
	gender = user.get("Gender","")
	nationality = user.get("Nationality","")
	name_father = user.get("father_name","")
	dob = user.get("DOB",None)
	if dob is None:
		date = 03
		month = 06
		year = 1995
	else:
		date = dob.get("date",03)
		month = dob.get("month",06)
		year = dob.get("year",1995)
	date_of_birth = str(year) + "-" + str(month) + "-" + str(date)
	image_uploaded = user.get("image","")
	if image_uploaded != "":
		image_uploaded = "Already Uploaded"
	else:
		image_uploaded = "Upload file"
	id_proof_uploaded = user.get("id_proof","")
	if id_proof_uploaded != "":
		id_proof_uploaded = "Already Uploaded"
	else:
		id_proof_uploaded = "Upload file"
	return render_template(
		"form_personal_profile.html",
		profile_pic = session["profile_pic"], 
		facebook_name = session["facebook_name"], 
		email = session["email"], 
		all_races = all_races,
		len_all_races = len_all_races,
		all_messages = all_messages,
		len_all_messages = len_all_messages,
		name_prefix = name_prefix,
		name_first = name_first,
		name_middle = name_middle,
		get_id_proof = get_id_proof,
		name_last = name_last,
		address_part_one = address_part_one,
		address_part_four = address_part_four,
		address_part_three = address_part_three,
		address_part_two = address_part_two,
		gender = gender,
		nationality = nationality,
		name_father = name_father,
		date_of_birth = date_of_birth,
		width = width,
		height = height,
		mobile_number = mobile_number,
		error = error,
		image_uploaded = image_uploaded,
		id_proof_uploaded = id_proof_uploaded,
		get_html = Markup(get_html)
		)
Ejemplo n.º 10
0
def external_signup():
  if request.method == 'GET':
    user = request.args.get('user')

    if user:
      return render_template('signup.html', user=user)
    else:
      return render_template('signup.html')

  elif request.method == 'POST':
    try:
      start_time = time.time()
      
      if request.form['account_type'] == 'Residential':
        utils.send_email(['*****@*****.**'], request.form['first_name'] + ' ' + request.form['last_name'], utils.print_html(request.form.to_dict()))
        logger.info('New residential signup submitted: ' + request.form['first_name'] + ' '\
         + request.form['last_name'])
      else:
        logger.info('New business signup submitted: ' + request.form['account_name'])

      db['web_signups'].insert(request.form.to_dict())



      r = requests.post(
        'http://www.bravoweb.ca/receive_signup', data=request.form.to_dict())



      body = "Thanks for signing up with Empties to Winn. \
      We will send a confirmation of your Dropoff date within a few business \
      days. We can be reached at 1-888-YOU-WINN"
       
      requests.post(
        'https://api.mailgun.net/v3/' + MAILGUN_DOMAIN + '/messages',
        auth=('api', MAILGUN_API_KEY),
        data={
          'from': FROM_EMAIL,
          'to': [request.form['email']],
          'subject': 'Empties to Winn Signup Confirmation',
          'html': body
        }
      )

      #elapsed = str(round(time.time() - start_time,1))
      #logger.info('Time elapsed: ' + elapsed + 's')

      return body
    
    except Exception as e:
      logger.info(str(e), exc_info=True)
      return str(e)