def sluzby_upload(): services = DBAccess.ExecuteSQL("select * from services") form = regFormBuilder( services ) # put all services to form, but I need to display it - by for cycle below form.checkBoxes.clear() # not to have duplicates on website for index in form.checkBoxIndexes: form.checkBoxes.append( getattr(form, "checkbox%d" % index) ) # displaying checkboxes on website if form.validate_on_submit(): # if validated, save in db nextId = session["id_user"] services_checked = [] for index in form.checkBoxIndexes: checkbox = getattr(form, "checkbox%d" % index) if checkbox.data: # for every checked services in form, save.. existing_combination = DBAccess.ExecuteScalar( "select count(*) from users_services where id_users=%s and " "id_services=%s and id_demand_offer=%s", (nextId, checkbox.id, form.demandOffer.data), ) text = DictionaryDemandOffer.get( form.demandOffer.data, "unknown" ).lower() if existing_combination > 0: flash( f'Zadaná kombinace {session["user"]}, {text} a {checkbox.label.text} již existuje.', FlashStyle.Danger ) else: DBAccess.ExecuteInsert( "insert into users_services " "(id_users, id_services, id_demand_offer) values (%s, %s, %s)", (nextId, checkbox.id, form.demandOffer.data), ) services_checked.append(checkbox.label) kwargs = { "demand_offer": DictionaryDemandOffer.get(form.demandOffer.data, "unknown"), "category": services_checked, } return render_template("sluzby_success.html", **kwargs) return render_template("sluzby.html", form=form)
def feedback(): range_evaluation = range(1, 6) form = FeedbackFormular() rid = request.args.get("id", type=int) dbUser = DBUser.LoadFromSession('dbUser') id_user_review = dbUser.id id_users = DBAccess.ExecuteSQL( """select id_users_demand, id_users_offer from requests where id =%s""", (rid, )) if id_users[0][0] == id_user_review: id_user_evaluated = id_users[0][1] else: id_user_evaluated = id_users[0][0] if form.validate_on_submit(): comment = form.comment.data number_evaluation = request.form["number_evaluation"] DBAccess.ExecuteInsert( """insert into feedback (id_requests, id_user, id_user_review, comment, evaluation) values (%s, %s, %s, %s, %s)""", (rid, id_user_evaluated, id_user_review, comment, number_evaluation)) DBAccess.ExecuteUpdate( """update requests set id_requests_status = 5 where id =%s""", (rid, )) return render_template("feedback_thanks.html") return render_template("feedback.html", form=form, range_evaluation=range_evaluation)
def email_sent(): # kdo oslovuje user = session["user"] id_users_services = request.form.get("id", type=int) dbUser = DBUser.LoadFromSession('dbUser') email_oslovujici = dbUser.email name_oslovujici = dbUser.first_name surname_oslovujici = dbUser.surname # date = request.form.get("date", type=str) # time = request.form.get("time", type=str) # strDateTime = f"{date} {time}" # dt = datetime.strptime(strDateTime, "%Y-%m-%d %H:%M") info = request.form.get("info", type=str) email_user_long = DBAccess.ExecuteSQL( """ SELECT u.email, u.id, s.id, d.id FROM users u LEFT JOIN users_services us on us.id_users = u.id LEFT JOIN services s on s.id = us.id_services LEFT JOIN demand_offer d on d.id = us.id_demand_offer WHERE us.id = %s """, (id_users_services, )) email_user = email_user_long[0][0] # for testing emails are sent to admin services_id = email_user_long[0][2] id_demand_offer = email_user_long[0][3] offeringUserId = email_user_long[0][ 1] if id_demand_offer == 2 else session["id_user"] demandingUserId = email_user_long[0][ 1] if id_demand_offer == 1 else session["id_user"] id_request = DBAccess.GetSequencerNextVal("requests_id_seq") DBAccess.ExecuteInsert( "INSERT INTO requests (id, id_users_demand, id_users_offer, id_services, " "timestamp, date_time, add_information, id_requests_status, id_users_creator)" " values (%s, %s,%s,%s,now(),now(),%s,%s, %s)", (id_request, demandingUserId, offeringUserId, services_id, info, 1, session["id_user"])) # protistrana, kdo je osloven - email_user dbUser_protistrana = DBAccess.GetDBUserByEmail(email_user) name_protistrana = dbUser_protistrana.first_name surname_protistrana = dbUser_protistrana.surname text1 = 'Vaši nabídku' if id_demand_offer == 1 else 'Váš požadavek' text2 = 'Vaši nabídky' if id_demand_offer == 1 else 'vašeho požadavku' # mail to person who click on "contact" SendMail( GetEmail('noreplyMail'), f'{email_oslovujici}', 'Zaregistrována žádost o spolupráci', f'''<html>Úspěšně jsme zaregistrovali Vaší žádost o spolupráci. <br> Váš kontakt je {name_protistrana}, email: {email_user} <br> Prosíme, spojte se, abyste se mohli domluvit na podrobnostech. Nezapomeňte dodržovat pravidla: <a href="https://app.seniore.org/podminky_dobrovolnici"> dobrovolníci</a> / <a href="https://app.seniore.org/podminky_seniori"> senioři</a><br> V případě potíží, nebo nejasností nám neváhejte napsat na [email protected]. <br> Děkujeme, Váš tým Seniore</html>''') # mail to person who is being contacted SendMail( GetEmail('noreplyMail'), f'{email_user}', 'Zaregistrována žádost o spolupráci', f''' <html> Pan / paní {name_oslovujici} by se s Vámi rád/a spojil/a ohledně možné pomoci. Kontaktní email je: {email_oslovujici} <br> Prosíme, spojte se, abyste se mohli domluvit na podrobnostech. Nezapomeňte dodržovat pravidla: <a href="https://app.seniore.org/podminky_dobrovolnici"> dobrovolníci</a> / <a href="https://app.seniore.org/podminky_seniori"> senioři</a><br> V případě potíží, nebo nejasností nám neváhejte napsat na [email protected]. <br> Děkujeme, Váš tým Seniore < / html > ''') # mail to admins SendMail( GetEmail('noreplyMail'), GetEmail('adminMail'), 'Seniore - zažádáno o spolupráci', f'''Uživatel {user} se s chce setkat s {email_user}! :-D <br> Doplňující informace: {info}. <br> Prosím, zkontrolujte žádost v http://seniore.herokuapp.com/requests_detail?id={id_request}.''' ) # print(response.status_code) # print(response.body) # print(response.headers) return render_template("email_sent.html", text1=text1, text2=text2)