def create(): form = ContactForm() if form.validate() is False: for error_type in form.errors: if form.errors[error_type][0] in dictionary(): form.errors[error_type][0] = dictionary()[form.errors[error_type][0]] return render_template('contact/index.html', form=form, action=url_for('contact.create')) else: contact = Form() contact.name = form.name.data contact.email = form.email.data contact.subject = form.subject.data contact.message = form.message.data contact.postage_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S') message_tpl = render_template('contact/message_template.html', contact=contact) db.session.add(contact) db.session.commit() send_mail("Contato - DataViva", [admin_email], message_tpl) message = gettext("Your message has been sent successfully. We will soon get back to you.") flash(message, 'success') return redirect(url_for('contact.create'))
def new_article_advise(article, server_domain): article_url = server_domain + g.locale + '/' + mod.name + '/article/' + str( article.id) advise_message = render_template('scholar/mail/new_article_advise.html', article=article, article_url=article_url) send_mail("Novo Estudo", [admin_email], advise_message)
def create(): form = ContactForm() if form.validate() is False: for error_type in form.errors: if form.errors[error_type][0] in dictionary(): form.errors[error_type][0] = dictionary()[ form.errors[error_type][0]] return render_template('contact/index.html', form=form, action=url_for('contact.create')) else: contact = Form() contact.name = form.name.data contact.email = form.email.data contact.subject = form.subject.data contact.message = form.message.data contact.postage_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S') message_tpl = render_template('contact/message_template.html', contact=contact) db.session.add(contact) db.session.commit() send_mail("Contato - DataViva", [admin_email], message_tpl) message = gettext( "Your message has been sent successfully. We will soon get back to you." ) flash(message, 'success') return redirect(url_for('contact.create'))
def create(): form = ContactForm() if form.validate() is False: return Response(status=400, mimetype='application/json') else: contact = Form() contact.name = form.name.data contact.email = form.email.data contact.subject = form.subject.data contact.message = form.message.data contact.postage_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S') message_tpl = render_template('contact/message_template.html', contact=contact) db.session.add(contact) db.session.commit() send_mail("Mensagem recebida via página de Contato", ["*****@*****.**"], message_tpl) message = gettext( "Your message has been sent successfully. We will soon get back to you." ) return Response(message, status=200, mimetype='application/json')
def send_confirmation(user): confirmation_url = "http://dataviva.info/%s/account/confirm/%s" % ( g.locale, user.confirmation_code) confirmation_tpl = render_template('account/mail/confirmation.html', user=user.serialize(), confirmation_url=confirmation_url) send_mail("Account confirmation", [user.email], confirmation_tpl)
def ask(user=None): form = AskForm() if request.method == 'POST': if g.user is None or not g.user.is_authenticated(): flash(gettext('You need to be logged in to ask questions.')) return redirect(url_for('account.login')) if form.validate_on_submit(): timestamp = datetime.utcnow() slug = Question.make_unique_slug(form.question.data) from ..utils.profanities_filter import ProfanitiesFilter file_banned_words = open( os.path.join(basedir, "dataviva/static/txt/blacklist.txt")) banned_words = [line.strip() for line in file_banned_words] filter = ProfanitiesFilter(banned_words, replacements='*') _question = filter.clean(str(form.question.data.encode("utf-8"))) _body = filter.clean(str(form.body.data.encode("utf-8"))) _type = filter.clean(str(form.type.data)) question = Question(question=_question, body=_body, timestamp=timestamp, user=g.user, slug=slug, language=g.locale, type_id=_type) if "," in form.tags.data: tags = form.tags.data.split(",") question.str_tags(tags) db.session.add(question) db.session.commit() try: flash( gettext( 'Your message was sent successfully. Thank you for your contribution, it will be helpful to other users and is essential to improving our tool! Our team will contact you by e-mail shortly.' )) send_mail( 'Aviso de nova publicacao no DataViva', [ADMINISTRATOR_EMAIL], render_template('about/ask/ask_feedback.html', question=question)) except BaseException as e: print e # if user and request.remote_addr == SITE_MIRROR.split(":")[1][2:]: # return jsonify({"status": "Success"}) # else: return redirect(url_for('about.contact')) else: return render_template("about/ask/ask.html", page="ask", form=form) return render_template("about/ask/ask.html", page="ask", form=form)
def admin_questions_edit(status, question_id): q = Question.query.get_or_404(question_id) s = Status.query.filter_by(name=status).first_or_404() form = AdminQuestionUpdateForm() if request.method == "POST": previous_status = form.previous_status.data q.status = form.status.data q.status_notes = form.answer.data q.body = form.body.data q.question = form.question.data q.language = form.language.data db.session.add(q) db.session.commit() user = User.query.get(q.user_id) # if status is approve or rejected send email status_id = request.form["status"] subject = gettext("DataViva Reply") if (status_id == "2" or status_id == "3") and int(user.agree_mailer) > 0: if user.email: send_mail.send_mail( subject, [user.email], render_template("admin/mail/ask_feedback.html", title=subject, status=status_id, user=user), ) flash(gettext("This question has now been updated.")) return redirect(url_for(".admin_questions", status=previous_status)) # set defaults form.status.data = s form.language.data = q.language form.previous_status.data = s.name form.answer.data = q.status_notes form.question.data = q.question form.body.data = q.body return render_template("admin/admin_questions_edit.html", question=q, status=status, form=form)
def reset_password(): form = ForgotPasswordForm() try: user = User.query.filter_by(email=form.email.data)[-1] pwd = md5(str(datetime.now()) + form.email.data).hexdigest()[0:5] user.password = sha512(pwd) db.session.commit() email_tp = render_template('user/mail/forgot.html', user=user.serialize(), new_pwd=pwd) send_mail("Forgot Password", [user.email], email_tp) flash(dictionary()["new_password_sent"], "success") except: flash(dictionary()["couldnt_find_user"], "danger") return render_template("user/forgot_password.html", form=form) return redirect(url_for('user.reset_password'))
def ask(user=None): form = AskForm() if request.method == 'POST': if g.user is None or not g.user.is_authenticated(): flash(gettext('You need to be logged in to ask questions.')) return redirect(url_for('account.login')) if form.validate_on_submit(): timestamp = datetime.utcnow() slug = Question.make_unique_slug(form.question.data) from ..utils.profanities_filter import ProfanitiesFilter file_banned_words = open(os.path.join(basedir, "dataviva/static/txt/blacklist.txt")) banned_words = [line.strip() for line in file_banned_words] filter = ProfanitiesFilter(banned_words, replacements = '*') _question = filter.clean(str(form.question.data.encode("utf-8"))) _body = filter.clean(str(form.body.data.encode("utf-8"))) _type = filter.clean(str(form.type.data)) question = Question(question=_question, body=_body, timestamp=timestamp, user=g.user, slug=slug, language=g.locale, type_id=_type) if "," in form.tags.data: tags = form.tags.data.split(",") question.str_tags(tags) db.session.add(question) db.session.commit() try: flash(gettext('Your message was sent successfully. Thank you for your contribution, it will be helpful to other users and is essential to improving our tool! Our team will contact you by e-mail shortly.')) send_mail('Aviso de nova publicacao no DataViva', [ADMINISTRATOR_EMAIL], render_template('about/ask/ask_feedback.html', question=question)) except BaseException as e: print e # if user and request.remote_addr == SITE_MIRROR.split(":")[1][2:]: # return jsonify({"status": "Success"}) # else: return redirect(url_for('about.contact')) else: return render_template("about/ask/ask.html", page = "ask", form = form) return render_template("about/ask/ask.html", page = "ask", form = form)
def reset_password(): form = ForgotPasswordForm() try: user = User.query.filter_by(email=form.email.data)[-1] pwd = md5(str(datetime.now()) + form.email.data).hexdigest()[0:5] user.password = sha512(pwd) db.session.commit() email_tp = render_template('account/mail/forgot.html', user=user.serialize(), new_pwd=pwd) send_mail("Forgot Password", [user.email], email_tp) flash("A new password has been sent to you! Please check you inbox!", "success") except Exception as e: flash("We couldnt find any user with the informed email address", "danger") return render_template("account/forgot_password.html", form=form) return redirect("account/signin")
def reset_password(): form = ForgotPasswordForm() try: user = User.query.filter_by(email=form.email.data)[-1] pwd = md5(str(datetime.now()) + form.email.data).hexdigest()[0:5] user.password = sha512(pwd) db.session.commit() email_tp = render_template('account/mail/forgot.html', user=user.serialize(), new_pwd=pwd) send_mail("Forgot Password", [user.email], email_tp) flash( "A new password has been sent to you! Please check you inbox!", "success") except Exception as e: flash( "We couldnt find any user with the informed email address", "danger") return render_template("account/forgot_password.html", form=form) return redirect("account/signin")
def create(): form = ContactForm() if form.validate() is False: return Response(status=400, mimetype='application/json') else: contact = Form() contact.name = form.name.data contact.email = form.email.data contact.subject = form.subject.data contact.message = form.message.data contact.postage_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S') message_tpl = render_template( 'contact/message_template.html', contact=contact) db.session.add(contact) db.session.commit() send_mail("Mensagem recebida via página de Contato", ["*****@*****.**"], message_tpl) message = gettext( "Your message has been sent successfully. We will soon get back to you.") return Response(message, status=200, mimetype='application/json')
def answer(slug): reply_form = ReplyForm() question = Question.query.filter_by(slug=slug).first_or_404() if request.method == 'POST': # if request.remote_addr == SITE_MIRROR.split(":")[1][2:]: # g.user = User.query.get(request.form["user"]) if g.user is None or not g.user.is_authenticated(): flash(gettext('You need to be signed in to reply to questions.')) return redirect(url_for('about.answer', slug=question.slug)) # if "user" not in request.form: # form_json = {"user": g.user.id, "reply": reply_form.reply.data, "parent": reply_form.parent.data} # try: # opener = urllib2.urlopen("{0}{1}".format(SITE_MIRROR,request.path[1:]),urllib.urlencode(form_json),5) # except: # flash(gettext("The server is not responding. Please try again later.")) # return redirect(url_for('.answer', slug=question.slug)) timestamp = datetime.utcnow() if not reply_form.parent.data: parent_id = 0 else: parent_id = reply_form.parent.data hiddenFld = 2; from ..utils.profanities_filter import ProfanitiesFilter file_banned_words = open(os.path.join(basedir, "dataviva/static/txt/blacklist.txt")) banned_words = [line.strip() for line in file_banned_words] filter = ProfanitiesFilter(banned_words, replacements = '*') _body = filter.clean(str(reply_form.reply.data)) reply = Reply(body=_body, timestamp=timestamp, user=g.user, question=question, parent_id=parent_id, hidden=hiddenFld) db.session.add(reply) db.session.commit() if not reply_form.parent.data: reply.parent_id = reply.id db.session.add(reply) db.session.commit() try: flash(gettext('Reply submitted. Your reply will show up after we review it.')) #envia email para o admin send_mail('Aviso de nova publicacao no DataViva', [ADMINISTRATOR_EMAIL], render_template('about/ask/ask_feedback.html', question=question)) except: flash(gettext('Your Reply was not sent. Try later, please.')) return redirect(url_for('about.answer', slug=question.slug)) else: question.vote = False if g.user.is_authenticated(): vote = Vote.query.filter_by(type = 0, type_id = question.id, user_id = g.user.id).first() if vote: question.vote = True return render_template("about/ask/answer.html", reply_form = reply_form, question = question, page = "ask")
def send_confirmation(user): confirmation_url = "%s%s/user/confirm/%s" % (request.url_root, g.locale, user.confirmation_code) confirmation_tpl = render_template('user/mail/confirmation.html', confirmation_url=confirmation_url) send_mail("Account confirmation", [user.email], confirmation_tpl)
def send_confirmation(user): confirmation_url = "http://dataviva.info/%s/account/confirm/%s" % (g.locale, user.confirmation_code) confirmation_tpl = render_template('account/mail/confirmation.html', user=user.serialize(), confirmation_url=confirmation_url) send_mail("Account confirmation", [user.email], confirmation_tpl)
def new_article_advise(article, server_domain): article_url = server_domain + g.locale + '/' + mod.name + '/article/' + str(article.id) advise_message = render_template('scholar/mail/new_article_advise.html', article=article, article_url=article_url) send_mail("Novo Estudo", [admin_email], advise_message)