72 lines
4.1 KiB
Python
72 lines
4.1 KiB
Python
from tools import *
|
|
from Utils.Config import *
|
|
from Utils.Lib import *
|
|
|
|
|
|
CCGO = flask.Blueprint("CCGO", __name__, static_folder = JoinPath(FlaskTempLate, "CCGO"), static_url_path="/", subdomain="ccgo")
|
|
|
|
ABC="ABCDEFHIJKLMNOPQRSTUVWXYZ"
|
|
|
|
@CCGO.route("/")
|
|
def CCGOMain():
|
|
return flask.render_template("/CCGO/index.html")
|
|
|
|
@CCGO.route("/question/<QuestionUUID>")
|
|
def CCGOQuestion(QuestionUUID):
|
|
if not Get16toBytes(QuestionUUID, True) or not len(QuestionUUID) == 32: return flask.redirect("/questionerror.html")
|
|
if not SQLCCGO.istrue("questions", ("QuestionUUID=%s", Get16toBytes(QuestionUUID))): return flask.redirect("/questionerror.html")
|
|
return flask.render_template("/CCGO/template.html", QuestionUUID=QuestionUUID)
|
|
|
|
@CCGO.route("/API/question/<QuestionUUID>")
|
|
def CCGOAPIQuestion(QuestionUUID):
|
|
if not Get16toBytes(QuestionUUID, True) or not len(QuestionUUID) == 32: return "Question ERROR"
|
|
if not (Question := SQLCCGO.selectashead(NSQL.MOD.ALL, FROM="questions", WHERE=("QuestionUUID=%s", Get16toBytes(QuestionUUID)))): return "Question ERROR"
|
|
Question=Question[0]
|
|
Question["QuestionUUID"] = UUIDObj(Question["QuestionUUID"]).UpperStr
|
|
Question["QuestionAuthor"] = UUIDObj(Question["QuestionAuthor"]).UpperStr
|
|
Question["QuestionCreateTime"] = Question["QuestionCreateTime"].strftime("%Y-%m-%d %H:%M:%S")
|
|
single_choice=[]
|
|
multi_choice=[]
|
|
programming=[]
|
|
for i in Question["QuestionJSON"]["single_choice"]:
|
|
if "answer" in i: i["answer"] = random.choice(ABC[0:(len(i["options"])-1)])
|
|
single_choice.append(i)
|
|
for i in Question["QuestionJSON"]["multi_choice"]:
|
|
if "answer" in i: i["answer"] = random.choice(ABC[0:(len(i["options"])-1)])
|
|
multi_choice.append(i)
|
|
for i in Question["QuestionJSON"]["programming"]:
|
|
if "answer" in i: i["answer"] = random.choice(ABC[0:(len(i["options"])-1)])
|
|
programming.append(i)
|
|
Question["single_choice"] = single_choice
|
|
Question["multi_choice"] = multi_choice
|
|
Question["programming"] = programming
|
|
return Question
|
|
|
|
@CCGO.route("/API/setanswer/<QuestionUUID>", methods=["POST"])
|
|
def CCGOAPISetAnswer(QuestionUUID):
|
|
AnswerJSON=flask.request.form.get("AnswerJSON")
|
|
if len(AnswerJSON) > 1024*1024*100: return "Too Big Data"
|
|
if not Get16toBytes(QuestionUUID, True) or not len(QuestionUUID) == 32: return "Question ERROR"
|
|
if not SQLCCGO.istrue("questions", ("QuestionUUID=%s", Get16toBytes(QuestionUUID))): return "Question ERROR"
|
|
if not AnswerJSON: return "AnswerJSON ERROR 1"
|
|
try: json.loads(AnswerJSON)
|
|
except: return "AnswerJSON ERROR 2"
|
|
if (Answer:=SQLCCGO.selectashead(NSQL.MOD.ALL, FROM="answer", WHERE=("QuestionUUID=%s and AnswererUUID=%s", (Get16toBytes(QuestionUUID), Get16toBytes(GetELTUserUUID()))))) and not (Answer[0]["AnswerDone"] if Answer else False):
|
|
SQLCCGO.update(WHERE=("QuestionUUID=%s and AnswererUUID=%s", (Get16toBytes(QuestionUUID), Get16toBytes(GetELTUserUUID()))), FROM="answer", AnswerJSON=AnswerJSON)
|
|
else:
|
|
SQLCCGO.insert("answer", QuestionUUID=Get16toBytes(QuestionUUID), AnswererUUID=Get16toBytes(GetELTUserUUID()), AnswerJSON=AnswerJSON, AnswerDone=0)
|
|
return "OK"
|
|
@CCGO.route("/API/getanswer/<QuestionUUID>")
|
|
def CCGOAPIAnswer(QuestionUUID):
|
|
if not Get16toBytes(QuestionUUID, True) or not len(QuestionUUID) == 32: return "Question ERROR"
|
|
if not SQLCCGO.istrue("questions", ("QuestionUUID=%s", Get16toBytes(QuestionUUID))): return "Question ERROR"
|
|
if not (Answer:=SQLCCGO.selectashead(NSQL.MOD.ALL, FROM="answer", WHERE=("QuestionUUID=%s and AnswererUUID=%s", (Get16toBytes(QuestionUUID), Get16toBytes(GetELTUserUUID()))))) or (Answer[0]["AnswerDone"] if Answer else False): return []
|
|
return Answer[0]["AnswerJSON"]
|
|
|
|
@CCGO.before_request
|
|
def CCGOBeforeRequest():
|
|
#return flask.render_template("Manage/workonit.html")
|
|
allowsu=["txt", "png", "jpg", "gif", "js", "css", "eot", "svg", "tff", "woff", "woff2"]
|
|
if flask.request.url.split(".")[-1].lower() not in allowsu and not GetELTUser():
|
|
return flask.redirect(flask.url_for("MainLoginHTML"))
|