2 # Copyright (C) 2018 rubenwardy
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 from flask_user import *
20 from flask.ext import menu
21 from app import app, csrf
22 from app.models import *
23 from app.tasks import celery, TaskError
24 from app.tasks.importtasks import getMeta
25 from app.utils import shouldReturnJson
26 # from celery.result import AsyncResult
28 from app.utils import *
31 @app.route("/tasks/getmeta/new/", methods=["POST"])
33 def new_getmeta_page():
34 author = request.args.get("author")
35 author = current_user.forums_username if author is None else author
36 aresult = getMeta.delay(request.args.get("url"), author)
38 "poll_url": url_for("check_task", id=aresult.id),
41 @app.route("/tasks/<id>/")
43 result = celery.AsyncResult(id)
44 status = result.status
45 traceback = result.traceback
46 result = result.result
49 if isinstance(result, Exception):
55 if current_user.is_authenticated and current_user.rank.atLeast(UserRank.ADMIN):
56 info["error"] = str(traceback)
57 elif str(result)[1:12] == "TaskError: ":
58 info["error"] = str(result)[12:-1]
60 info["error"] = "Unknown server error"
68 if shouldReturnJson():
71 r = request.args.get("r")
72 if r is not None and status == "SUCCESS":
75 return render_template("tasks/view.html", info=info)