Exemple #1
0
def add_demo():
  if current_user.check_admin():
    form = DemoTestQuestion()
    ##for relative file location
    dirname = path.dirname(__file__)
    if form.validate_on_submit():
        totalMarks = form.marks1.data + form.marks2.data + form.marks3.data
        testNumber = next_test(form.unitCode.data)
        dictionary = {
        "unitCode" : form.unitCode.data,
        "unitName": form.unitName.data,
        "testNumber": testNumber,
        "totalMarks": totalMarks,
        "questions": [
          {
            "questionNumber": 1,
            "marks" : form.marks1.data,
            "prompt": form.prompt1.data,
            "answer": form.answer1.data,
            "questionType": "multipleChoice",
            "totalOptions": form.options1.data
          },
          {
            "questionNumber": 2,
            "marks" : form.marks2.data,
            "prompt": form.prompt2.data,
            "answer": form.answer2.data,
            "questionType": "shortAnswer",
            "totalOptions": None
          },
          {
            "questionNumber": 3,
            "marks" : form.marks3.data,
            "prompt": form.prompt3.data,
            "answer": None,
            "questionType": "openAnswer",
            "totalOptions": None
          }
        ]
        }
        ##dumps for 4 items, change indent variable if there's more items required
        json_object = dumps(dictionary, indent = 4)
        if add_test(form.unitCode.data, testNumber) == -1:
          flash('Error: Test already exists!')
          return redirect(url_for('userprofile'))
        else:
            with open(path.join(dirname, "questions/" + form.unitCode.data.lower() + "_" + str(testNumber)  + ".json"), "w") as outfile:
                outfile.write(json_object)
                flash('Demo test added!')
                return redirect(url_for('managetests'))
  else:
    flash('Not an admin: Please contact your supervisor')
    return redirect(url_for('userprofile'))
  return render_template("tests/adddemo_template.html", title="Add Demo Questions", form=form)
Exemple #2
0
def manageusers():
    if not current_user.check_admin(): # Student logins cannot access this page
        return redirect(url_for('userprofile'))
    else:
        users = User.query.all()
        num_admins = 0
        num_students = 0
        for user in users:
            if user.check_admin():
                num_admins += 1
            else:
                num_students += 1
        return render_template('manage/students.html', num_users=len(users), num_admins=num_admins, num_students=num_students, users=users)
Exemple #3
0
def marktests():
    if not current_user.check_admin(): # Student logins cannot access this page
        return redirect(url_for('userprofile'))
    feedbackDir = 'app/feedback/'
    res = []
    for filename in os.listdir(feedbackDir):
        if filename == ".gitkeep":
            continue
        feedback = open(feedbackDir + filename)
        content = load(feedback)
        if content["marked"] == "Partial":
            res.append(content)
    return render_template('marktests.html', title="Mark Completed Tests", markTests=res)
Exemple #4
0
def attempts():
    attempts = []
    feedbackDir = 'app/feedback/'
    if current_user.check_admin(): # Get every feedback if teacher
        for filename in os.listdir(feedbackDir):
            if filename == ".gitkeep":
                continue
            feedback = open(feedbackDir + filename)
            attempts.append(load(feedback))
    else:
        for filename in os.listdir(feedbackDir):
            if filename == ".gitkeep":
                continue
            if filename.startswith(current_user.username): # Get user specific feedback
                feedback = open(feedbackDir + filename)
                attempts.append(load(feedback))
    return render_template("attempts.html", title="Previous Attempts", userAttempts=attempts)
Exemple #5
0
def managetests():
    if not current_user.check_admin(): # Student logins cannot access this page
        return redirect(url_for('userprofile'))
    else:
        tests = get_all("app/questions/units.json")
        questionSets = []
        for unit in tests:
            for qset in tests[unit]:
                filepath = "app/questions/{}_{}.json".format(unit.lower(), qset)
                questionSet = load(open(filepath))
                numq = 0
                for question in questionSet["questions"]:
                    numq += 1
                thisSet = {
                    "unitCode": questionSet["unitCode"],
                    "unitName": questionSet["unitName"],
                    "testNumber": questionSet["testNumber"],
                    "totalMarks": questionSet["totalMarks"],
                    "questions": numq
                }
                questionSets.append(thisSet)
        return render_template('manage/tests.html', title="Manage Tests", sets=questionSets)
Exemple #6
0
def testfeedback(test_id):
    filepath = 'app/feedback/' + test_id + ".json"
    feedback_file = open(filepath)
    feedback = load(feedback_file)

    # Access to feedback file given to admin or user itself
    if current_user.check_admin() or current_user.username == feedback["user"]:
        
        # Store relevant number of form.marks in input
        form = ManualMarkForm()
        inputs = []
        for prompt in form:
            if len(inputs) == len(feedback["manualMarks"]):
                break
            inputs.append(prompt)

        if form.validate_on_submit():
            newManualMarks = []
            total = 0
            for markInput in inputs:
                mark = int(markInput.data)
                newManualMarks.append(mark)
                total += mark
            feedback["manualMarks"] = newManualMarks
            feedback["manualMarksachieved"] = total
            feedback["marked"] = "Fully"

            # Update the file
            json_object = dumps(feedback, indent=4)
            newfeedback = open(filepath, "w")
            newfeedback.write(json_object)
            flash('Marks manually updated')

        # Access is granted
        return render_template("feedback.html", title="Feedback", content=feedback, inputs=inputs, form=form)

    return redirect(url_for('userprofile'))