<commit_before>import sys
if not ('lib.zip' in sys.path):
  sys.path.insert(0, 'lib.zip')

import flask
from flaskext import wtf
import config

app = flask.Flask(__name__)
app.config.from_object(config)

from google.appengine.api import mail

import auth
import util
import model
import admin


@app.route('/')
def welcome():
  return flask.render_template(
      'welcome.html',
      html_class='welcome',
      channel_name='welcome',
    )


################################################################################
# Profile stuff
################################################################################
class ProfileUpdateForm(wtf.Form):
  name = wtf.TextField('Name', [wtf.validators.required()])
  email = wtf.TextField('Email', [
      wtf.validators.optional(),
      wtf.validators.email("That doesn't look like an email"),
    ])


@app.route('/_s/profile/', endpoint='profile_service')
@app.route('/profile/', methods=['GET', 'POST'], endpoint='profile')
@auth.login_required
def profile():
  form = ProfileUpdateForm()
  user_db = auth.current_user_db()
  if form.validate_on_submit():
    user_db.name = form.name.data
    user_db.email = form.email.data.lower()
    user_db.put()
    return flask.redirect(flask.url_for('welcome'))
  if not form.errors:
    form.name.data = user_db.name
    form.email.data = user_db.email or ''

  if flask.request.path.startswith('/_s/'):
    return util.jsonify_model_db(user_db)

  return flask.render_template(
      'profile.html',
      title='Profile',
      html_class='profile',
      form=form,
      user_db=user_db,
    )


################################################################################
# Feedback
################################################################################
class FeedbackForm(wtf.Form):
  subject = wtf.TextField('Subject', [wtf.validators.required()])
  feedback = wtf.TextAreaField('Feedback', [wtf.validators.required()])
  email = wtf.TextField('Email (optional)', [
      wtf.validators.optional(),
      wtf.validators.email("That doesn't look like an email"),
    ])


@app.route('/feedback/', methods=['GET', 'POST'])
def feedback():
  form = FeedbackForm()
  if form.validate_on_submit():
    mail.send_mail(
        sender=model.Config.get_master_db().feedback_email,
        to=model.Config.get_master_db().feedback_email,
        subject='[%s] %s' % (
            model.Config.get_master_db().brand_name,
            form.subject.data,
          ),
        reply_to=form.email.data or model.Config.get_master_db().feedback_email,
        body=form.feedback.data,
      )
    flask.flash('Thank you for your feedback!', category='success')
    return flask.redirect(flask.url_for('welcome'))
  if not form.errors and auth.current_user_id() > 0:
    form.email.data = auth.current_user_db().email

  return flask.render_template(
      'feedback.html',
      title='Feedback',
      html_class='feedback',<commit_msg>Added reply mail to the body, for some reason it's not applied in reply_to field<commit_after>import sys
if not ('lib.zip' in sys.path):
  sys.path.insert(0, 'lib.zip')

import flask
from flaskext import wtf
import config

app = flask.Flask(__name__)
app.config.from_object(config)

from google.appengine.api import mail

import auth
import util
import model
import admin


@app.route('/')
def welcome():
  return flask.render_template(
      'welcome.html',
      html_class='welcome',
      channel_name='welcome',
    )


################################################################################
# Profile stuff
################################################################################
class ProfileUpdateForm(wtf.Form):
  name = wtf.TextField('Name', [wtf.validators.required()])
  email = wtf.TextField('Email', [
      wtf.validators.optional(),
      wtf.validators.email("That doesn't look like an email"),
    ])


@app.route('/_s/profile/', endpoint='profile_service')
@app.route('/profile/', methods=['GET', 'POST'], endpoint='profile')
@auth.login_required
def profile():
  form = ProfileUpdateForm()
  user_db = auth.current_user_db()
  if form.validate_on_submit():
    user_db.name = form.name.data
    user_db.email = form.email.data.lower()
    user_db.put()
    return flask.redirect(flask.url_for('welcome'))
  if not form.errors:
    form.name.data = user_db.name
    form.email.data = user_db.email or ''

  if flask.request.path.startswith('/_s/'):
    return util.jsonify_model_db(user_db)

  return flask.render_template(
      'profile.html',
      title='Profile',
      html_class='profile',
      form=form,
      user_db=user_db,
    )


################################################################################
# Feedback
################################################################################
class FeedbackForm(wtf.Form):
  subject = wtf.TextField('Subject', [wtf.validators.required()])
  feedback = wtf.TextAreaField('Feedback', [wtf.validators.required()])
  email = wtf.TextField('Email (optional)', [
      wtf.validators.optional(),
      wtf.validators.email("That doesn't look like an email"),
    ])


@app.route('/feedback/', methods=['GET', 'POST'])
def feedback():
  form = FeedbackForm()
  if form.validate_on_submit():
    mail.send_mail(
        sender=model.Config.get_master_db().feedback_email,
        to=model.Config.get_master_db().feedback_email,
        subject='[%s] %s' % (
            model.Config.get_master_db().brand_name,
            form.subject.data,
          ),
        reply_to=form.email.data or model.Config.get_master_db().feedback_email,
        body='%s\n\n%s' % (form.feedback.data, form.email.data)
      )
    flask.flash('Thank you for your feedback!', category='success')
    return flask.redirect(flask.url_for('welcome'))
  if not form.errors and auth.current_user_id() > 0:
    form.email.data = auth.current_user_db().email

  return flask.render_template(
      'feedback.html',
      title='Feedback',
      html_class='feedback',
{'fraction_non_alphanumeric': 0.2379759519038076, 'fraction_numerical': 0.0006680026720106881, 'mean_word_length': 4.127568493150685, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '169993', 'n_tokens_mistral': 1859, 'n_tokens_neox': 1783, 'n_words': 329}