2018-05-11 16:04:17 +02:00
|
|
|
from flask import *
|
|
|
|
from flask_user import *
|
|
|
|
from flask.ext import menu
|
2018-05-13 19:37:57 +02:00
|
|
|
from app import app, csrf
|
2018-05-11 16:04:17 +02:00
|
|
|
from app.models import *
|
|
|
|
from app.tasks import celery
|
|
|
|
from app.tasks.importtasks import getMeta
|
|
|
|
from .utils import shouldReturnJson
|
|
|
|
# from celery.result import AsyncResult
|
|
|
|
|
|
|
|
from .utils import *
|
|
|
|
|
2018-05-13 19:37:57 +02:00
|
|
|
@csrf.exempt
|
2018-05-11 16:14:35 +02:00
|
|
|
@app.route("/tasks/getmeta/new/", methods=["POST"])
|
|
|
|
@login_required
|
2018-05-11 16:04:17 +02:00
|
|
|
def new_getmeta_page():
|
2018-05-12 19:50:09 +02:00
|
|
|
author = request.args.get("author")
|
|
|
|
author = current_user.forums_username if author is None else author
|
|
|
|
aresult = getMeta.delay(request.args.get("url"), author)
|
2018-05-11 16:04:17 +02:00
|
|
|
return jsonify({
|
|
|
|
"poll_url": url_for("check_task", id=aresult.id),
|
|
|
|
})
|
|
|
|
|
|
|
|
@app.route("/tasks/<id>/")
|
2018-05-11 16:14:35 +02:00
|
|
|
@login_required
|
2018-05-11 16:04:17 +02:00
|
|
|
def check_task(id):
|
|
|
|
result = celery.AsyncResult(id)
|
|
|
|
status = result.status
|
|
|
|
traceback = result.traceback
|
|
|
|
result = result.result
|
|
|
|
|
|
|
|
info = None
|
|
|
|
if isinstance(result, Exception):
|
|
|
|
info = {
|
2018-05-11 16:29:26 +02:00
|
|
|
'id': id,
|
2018-05-11 16:04:17 +02:00
|
|
|
'status': status,
|
|
|
|
'error': str(result),
|
|
|
|
}
|
|
|
|
else:
|
|
|
|
info = {
|
2018-05-11 16:29:26 +02:00
|
|
|
'id': id,
|
2018-05-11 16:04:17 +02:00
|
|
|
'status': status,
|
|
|
|
'result': result,
|
|
|
|
}
|
|
|
|
|
|
|
|
if shouldReturnJson():
|
|
|
|
return jsonify(info)
|
|
|
|
else:
|
|
|
|
r = request.args.get("r")
|
|
|
|
if r is None:
|
|
|
|
abort(422)
|
|
|
|
|
|
|
|
if status == "SUCCESS":
|
|
|
|
flash("Task complete!", "success")
|
|
|
|
return redirect(r)
|
|
|
|
else:
|
|
|
|
return render_template("tasks/view.html", info=info)
|