Exemplo n.º 1
0
def index():
    """ Index page """
    count = Address.query.count()
    form = SpammerForm()
    # try to validate, and check for AJAX submission
    if form.validate_on_submit():
            if not utils.check_if_exists(form.address.data):
                flash(
                    u"We've added %s to the database." % form.address.data,
                    "text-success")
            else:
                flash(
                    u"We already know about %s, though." % form.address.data,
                    "text-success")
    if request.is_xhr:
        # OK to send back a fragment
        return render_template(
            'form.jinja',
            form=form,
            )
    # GET or no JS, so render a full page
    return render_template(
        'index.jinja',
        form=form,
        count=count,
        recaptcha_public_key=app.config['RECAPTCHA_PUBLIC_KEY'])
Exemplo n.º 2
0
def index():
    """ Index page """
    count = Address.query.count()
    form = SpammerForm()
    if request.method == 'POST' and request.is_xhr:
        # put request vars into a form and try to validate
        form.address = request.form.get('address')
        form.csrf_token = request.form.get('csrf_token')
        new_form = SpammerForm()
        if form.validate_on_submit():
            if not utils.check_if_exists(form.address):
                # process the address
                # send back thank you, and a new form
                flash(u"Thanks!", "text-success")
            else:
                # address exists, send back an error and a new form
                flash(u"We already know that spammer!", "text-error")
        else:
            # Validation error
            new_form._errors = form.errors
        return render_template('form.jinja', form=new_form)
    # GET, just render a page with a blank form
    return render_template('index.jinja', form=form, count=count)
Exemplo n.º 3
0
def index():
    """ Index page """
    count = Address.query.count()
    form = SpammerForm()
    if request.method == "POST" and request.is_xhr:
        # put request vars into a form and try to validate
        form.address = request.form.get("address")
        form.csrf_token = request.form.get("csrf_token")
        new_form = SpammerForm()
        if form.validate_on_submit():
            if not utils.check_if_exists(form.address):
                # process the address
                # send back thank you, and a new form
                flash(u"Thanks!", "text-success")
            else:
                # address exists, send back an error and a new form
                flash(u"We already know that spammer!", "text-error")
        else:
            # Validation error
            new_form._errors = form.errors
        return render_template("form.jinja", form=new_form)
    # GET, just render a page with a blank form
    return render_template("index.jinja", form=form, count=count)