Exemple #1
0
def edit_book(book_id):
    items = item_index["id"].get(book_id, None)

    if items is None:
        flask.abort(http.client.NOT_FOUND, f"Book with id {id} was not found")

    message = utils_flask.extract_string_from_request("message")
    from_name = utils_flask.extract_string_from_request("name")
    from_email = utils_flask.extract_email_from_request("email")

    if not all([message, from_name, from_email]):
        flask.abort(http.client.BAD_REQUEST, "Empty values aren't allowed")

    item = utils.first(items)
    message = messenger.ErrorReport(item, from_email, from_name, message)
    message.send()

    return {"message": flask_babel.gettext("interface:report:thanks")}
Exemple #2
0
def get_backups():
	format = utils_flask.extract_string_from_request("format", default="html")
	with db.make_transaction() as session:
		backups = session.query(db.Backup).order_by(db.Backup.path).all()
	if format == "html":
		return flask.render_template("backups.html", backups=backups)
		pass
	elif format == "json":
		response = flask.make_response(json.dumps(backups, cls=db.SqlAlchemyEncoder))
		response.content_type = "application/json; charset=utf-8"
		return response
	else:
		flask.abort(http.client.BAD_REQUEST, f"Unknown format: {format}")