def submit(): if request.method == 'GET' or request.method == 'HEAD': return render_template( 'form.html.jinja', form_action=url_for('submit'), body='', ) body = Quote.prepare(request.form['body']) quote = Quote(body, datetime.now()) db_session.add(quote) db_session.commit() if app.config.get('ENABLE_IRCBOT_WEBHOOKS'): ircbot.notify_bot(quote) flash('Quote added!') return redirect(url_for('home'))
def submit(): if request.method in ('GET', 'HEAD'): return render_template('form.html.jinja', body='') if is_spam(request.form['body']): return abort(400) body = prepare_quote(request.form['body'], strip_timestamps=bool( request.form.get('strip_timestamps'))) quote = Quote(body, datetime.now(), request.remote_addr) if session.get('logged_in'): quote.approved = True db_session.add(quote) db_session.commit() if app.config.get('ENABLE_IRCBOT_WEBHOOKS'): ircbot.notify_bot(quote) flash('Quote added!') return redirect(url_for('home'))
def submit(): if request.method in ("GET", "HEAD"): return render_template("form.html.jinja", body="") if is_spam(request.form["body"]): return abort(400) body = prepare_quote( request.form["body"], strip_timestamps=bool(request.form.get("strip_timestamps")), ) if not body: return abort(400) quote = Quote(body, datetime.now(), request.remote_addr) if session.get("logged_in"): quote.approved = True db_session.add(quote) db_session.commit() if app.config.get("ENABLE_IRCBOT_WEBHOOKS"): ircbot.notify_bot(quote) flash("Quote added!") return redirect(url_for("home"))
def make_quote(body='', submitted_at=None, submitter_ip=None, approved=False): if not submitted_at: submitted_at = datetime.datetime.now() return Quote(body, submitted_at, submitter_ip, approved)