Exemplo n.º 1
0
Arquivo: routes.py Projeto: risb0r/qdb
def show(quote_id):
    quote = db_session.query(Quote).filter(Quote.id == quote_id).first()

    if not quote:
        return abort(404)

    if request.method in ("GET", "HEAD"):
        if request.headers.get("Accept") == "application/json":
            return jsonify(quote=quote)
        return render_template("show.html.jinja", quote=quote)

    if not session.get("logged_in"):
        return abort(401)

    if request.method == "DELETE":
        db_session.delete(quote)
        db_session.commit()
        return "OK"

    quote.body = prepare_quote(
        request.form["body"],
        strip_timestamps=bool(request.form.get("strip_timestamps")),
    )
    db_session.add(quote)
    db_session.commit()
    return "OK"
Exemplo n.º 2
0
Arquivo: routes.py Projeto: x89/qdb
def show(quote_id):
	quote = db_session.query(Quote) \
		.filter(Quote.id == quote_id) \
		.first()

	if not quote:
		return abort(404)

	if request.method == 'GET' or request.method == 'HEAD':
		if request.headers.get('Accept') == 'application/json':
			return jsonify(quote=quote)
		return render_template('show.html.jinja', quote=quote)

	if not session.get('logged_in'):
		return abort(401)

	if request.method == 'DELETE':
		db_session.delete(quote)
		db_session.commit()
		return 'OK'

	body = Quote.prepare(request.form['body'])
	quote.body = body
	db_session.add(quote)
	db_session.commit()
	return 'OK'
Exemplo n.º 3
0
Arquivo: routes.py Projeto: x89/qdb
def show(quote_id):
    quote = db_session.query(Quote) \
     .filter(Quote.id == quote_id) \
     .first()

    if not quote:
        return abort(404)

    if request.method == 'GET' or request.method == 'HEAD':
        if request.headers.get('Accept') == 'application/json':
            return jsonify(quote=quote)
        return render_template('show.html.jinja', quote=quote)

    if not session.get('logged_in'):
        return abort(401)

    if request.method == 'DELETE':
        db_session.delete(quote)
        db_session.commit()
        return 'OK'

    body = Quote.prepare(request.form['body'])
    quote.body = body
    db_session.add(quote)
    db_session.commit()
    return 'OK'
Exemplo n.º 4
0
Arquivo: routes.py Projeto: risb0r/qdb
def reject(quote_id):
    if not session.get("logged_in"):
        return abort(401)

    quote = db_session.query(Quote).filter(Quote.id == quote_id).first()

    if not quote:
        return abort(404)

    quote.approved = False
    db_session.add(quote)
    db_session.commit()

    return "OK"
Exemplo n.º 5
0
Arquivo: routes.py Projeto: x89/qdb
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'))
Exemplo n.º 6
0
Arquivo: routes.py Projeto: risb0r/qdb
def approve(quote_id):
    if not session.get("logged_in"):
        return abort(401)

    quote = db_session.query(Quote).filter(Quote.id == quote_id).first()

    if not quote:
        return abort(404)

    quote.approved = True
    db_session.add(quote)
    db_session.commit()

    if app.config.get("ENABLE_IRCBOT_WEBHOOKS"):
        ircbot.notify_bot(quote)

    return "OK"
Exemplo n.º 7
0
Arquivo: routes.py Projeto: x89/qdb
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'))
Exemplo n.º 8
0
Arquivo: routes.py Projeto: x89/qdb
def approve(quote_id):
	if not session.get('logged_in'):
		return abort(401)

	quote = db_session.query(Quote) \
		.filter(Quote.id == quote_id) \
		.first()

	if not quote:
		return abort(404)

	quote.approved = True
	db_session.add(quote)
	db_session.commit()

	if app.config.get('ENABLE_IRCBOT_WEBHOOKS'):
		ircbot.notify_bot(quote)

	return 'OK'
Exemplo n.º 9
0
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'))
Exemplo n.º 10
0
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 = Quote.prepare(
		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'))
Exemplo n.º 11
0
Arquivo: routes.py Projeto: risb0r/qdb
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"))