def put(f): r = polo.upload_file(f) if not r: return "" url = "http://{}:{}/polo/object/".format(settings.POLO_HOST, settings.POLO_PORT) + r.hash return url
def create_paper_file(paper, data, fmt, size, usage): try: # create paper file filepath = get_paper(data, fmt, size, usage) with open(filepath, "rb") as outfile: r = polo.upload_file(outfile) if not r: return APIResponse(code=STORE_FILE_FAILED, message=_("存储文件失败")) hash_code = r.hash models.ExamRelatedPaper.save_hash(paper=paper, type=size, hash_code=hash_code, usage=usage, fmt=fmt) except Exception as e: logger.error("upload paper file to polo error, detail: {}".format(e))
def create_answersheet(paper, data, size=None): try: size = size or models.AnswerSheetSizeSet.A4 # create answer sheet paper_data = QuestionNumberBuilder(paper_data=data).attach_ques_no answer_path, answer_sheet_data, sub_json_data = get4answer_sheet_data(paper_data) with open(answer_path, "rb") as outfile: r = polo.upload_file(outfile) if not r: return APIResponse(code=STORE_FILE_FAILED, message=_("存储文件失败")) answer_hash_code = r.hash # save json_data and hash json_data = get_json(sub_json_data) models.ExamRelatedAnswersheet.save_answer(paper, size, answer_hash_code, json_data) except Exception as e: traceback.print_exc() logger.error("upload answer sheet file to polo error, detail: {}".format(e))
def put(f): r = polo.upload_file(f) if not r: return "" url = "http://class-test.h3c.com:8300/polo/object/"+r["fileHash"] return url