コード例 #1
0
ファイル: loginserver.py プロジェクト: py-tofee/Q-Asystem
def create_questions():
	if request.form and 'q_category' in request.form and 'q_title' in request.form and 'q_content' in request.form and 'q_userid' in request.form :

		user = db.session.query(User).filter(User.user_id == request.form['q_userid']).first()
		new_question = Question(request.form['q_category'], request.form['q_title'], request.form['q_content'], user)
		

		if 'invited_user_name' in request.form :
			invied_user = db.session.query(User).filter(User.name == request.form['invited_user_name']).first()
			new_question.q_invited_userid = invied_user.user_id
			print(invied_user.user_id)

		db.session.add(new_question)
		db.session.commit()

		q_user = {
			"user_id": new_question.user.user_id,
			"username": new_question.user.name,
		}

		this_new_question = {
			'q_id': new_question.q_id,
			'q_title': new_question.q_title,
			'q_category': new_question.q_category,
			'q_content': new_question.q_content,
			'q_create_time': new_question.q_create_time,
			'q_userid': new_question.user.user_id,
			'q_read_amount': new_question.q_read_amount,
			'q_concern_amount': new_question.q_concern_amount,
			'q_answer_amount': new_question.q_answer_amount
		}

		return json.dumps({'data': {'message': 'success', 'question': this_new_question, 'q_user': q_user}})
コード例 #2
0
def save(question,answer):
	q=Question(question=question,answer=answer)
	q.save()
	if q.id >0 :
		return True
	else :
		return False
コード例 #3
0
def queryRom():
	q=Question()
	row=q.getPks()
	count=row[random.randint(0,len(row)-1)]
	question=Question.objects.get(pk=count)
	#取出问题,和问题id
	rlist={'question':question.question,'id':question.id}
	return rlist
コード例 #4
0
def add_quiz(request):
    context = {"title": TITLE}
    if request.method == 'POST':
        if 'user_id' in request.session and request.session['user_type'] == 'Uploader':
            quiz_name = request.POST.get("quiz_name", None)
            subjects = request.POST.getlist("subjects", None)
            num_ques = request.POST.get('num_ques', None)
            if quiz_name is None or subjects is None or num_ques is None:
                return HttpResponseBadRequest
            else:
                quiz = Quiz()
                quiz.name = quiz_name
                quiz.num_ques = int(num_ques)
                quiz.is_active = False
                quiz.save()
                subject_objects = [Subject.objects.filter(name=str(subject))[0] for subject in subjects]
                for subject in subject_objects:
                    quiz_to_subject = QuizToSubject()
                    quiz_to_subject.quiz = quiz
                    quiz_to_subject.subject = subject
                    quiz_to_subject.save()
                quiz_to_uploader = QuizToUploaderTag()
                uploader = QuestionUploader.objects.filter(user_id=request.session['user_id'])[0]
                quiz_to_uploader.quiz = quiz
                quiz_to_uploader.uploader = uploader
                quiz_to_uploader.save()

                # Add all the questions
                for i in range(quiz.num_ques):
                    options = Options()
                    options.option1 = "1"
                    options.option2 = "2"
                    options.option3 = "3"
                    options.option4 = "4"
                    options.option5 = "5"
                    options.answer = 0
                    options.save()
                    question = Question()
                    question.description = "{} question number {}".format(quiz.name, str(i+1))
                    question.options = options
                    question.subject = subject_objects[0]
                    question.score = 0
                    question.penalty = 0
                    question.save()
                    quiz_to_question = QuizToQuestion()
                    quiz_to_question.question = question
                    quiz_to_question.quiz = quiz
                    quiz_to_question.seq_num = i+1
                    quiz_to_question.save()

                context["all_quiz"] = [inst.quiz for inst in QuizToUploaderTag.objects.filter(uploader=uploader)]
                return render(request, "upload.html", context)
        else:
            return HttpResponseBadRequest
    else:
        return HttpResponseBadRequest
コード例 #5
0
def question():
    if request.method == 'GET':
        return render_template('question.html')
    else:
        title = request.form.get('title')
        desc = request.form.get('desc')
        if not all([title, desc]):
            flash('参数不足')
            return redirect(url_for('blue_question.question'))
        else:
            question_rel = Question(title=title, desc=desc)
            # 将当前用户賦值给关系属性author
            question_rel.author = g.user
            db.session.add(question_rel)
            db.session.commit()
            return redirect(url_for('blue_index.index'))
コード例 #6
0
ファイル: loginserver.py プロジェクト: py-tofee/Q-Asystem
def create_questions():
    if request.form and 'q_category' in request.form and 'q_title' in request.form and 'q_content' in request.form and 'q_userid' in request.form:

        user = db.session.query(User).filter(
            User.user_id == request.form['q_userid']).first()
        new_question = Question(request.form['q_category'],
                                request.form['q_title'],
                                request.form['q_content'], user)

        if 'invited_user_name' in request.form:
            invied_user = db.session.query(User).filter(
                User.name == request.form['invited_user_name']).first()
            new_question.q_invited_userid = invied_user.user_id
            print(invied_user.user_id)

        db.session.add(new_question)
        db.session.commit()

        q_user = {
            "user_id": new_question.user.user_id,
            "username": new_question.user.name,
        }

        this_new_question = {
            'q_id': new_question.q_id,
            'q_title': new_question.q_title,
            'q_category': new_question.q_category,
            'q_content': new_question.q_content,
            'q_create_time': new_question.q_create_time,
            'q_userid': new_question.user.user_id,
            'q_read_amount': new_question.q_read_amount,
            'q_concern_amount': new_question.q_concern_amount,
            'q_answer_amount': new_question.q_answer_amount
        }

        return json.dumps({
            'data': {
                'message': 'success',
                'question': this_new_question,
                'q_user': q_user
            }
        })
コード例 #7
0
    def post(self):
        file = request.files.get('file')
        lsn_id = request.form.get('lsn_id')
        if lsn_id is None or file is None:
            return {"message": "params error!"}, 400

        ques_objs = []
        try:
            wb = load_workbook(file)
            sheet = wb.active
            for row in sheet.rows:
                cols = [col.value for col in row]
                content = None
                other_option = None
                correct_option = None

                tmp = []
                for col in cols:
                    print(col)
                    if col is None:
                        if content is None:
                            content = "#".join(tmp)
                            print("content", content)
                        elif correct_option is None:
                            correct_option = "#".join(tmp)
                            print("correct_option", correct_option)
                        tmp = []
                    else:
                        tmp.append(str(col))
                other_option = "#".join(tmp)
                print("other_option", other_option)

                obj = Question(lsn_id=lsn_id,
                               content=content,
                               correct_option=correct_option,
                               other_option=other_option)
                ques_objs.append(obj)

            db.session.add_all(ques_objs)
            db.session.commit()
            return schemas.dump(ques_objs)
        except Exception as e:
            db.session.rollback()
            traceback.print_exc()
            return {"message": "文件格式错误"}, 406
コード例 #8
0
ファイル: views.py プロジェクト: vinaykornapalli/quizwizard
def add_question(request):
    if request.method == "POST":
        question  = request.POST.get("question")
        option1 = request.POST.get("option1")
        option2 = request.POST.get("option2")
        option3 = request.POST.get("option3")
        option4 = request.POST.get("option4")
        answer = request.POST.get("answer")
        exam = request.POST.get("exam")
        q = Question()
        q.question = question
        q.option1 = option1
        q.option2 = option2
        q.option3 = option3
        q.option4 = option4
        q.answer = answer
        q.exam = Exam.objects.get(pk=int(exam))
        q.save()
        return HttpResponse("success")