예제 #1
0
def emp_update_assignment():
    values = json.loads(request.form['params'])
    asnid = values['id']
    try:
        asnid = Assignment.update(values)
    except Exception as ex:
        return jsonify(error=str(ex))
    assignments = Assignment.get_for_employee(values['employee_id'])
    return jsonify(asnid=asnid, assignments=assignments)
def AssignmentCreate(class_code):
    if request.method == "GET":
        session["class_code"] = class_code
        return render_template("assignment/assignment_create.html")
    elif request.method == "POST":
        assignment_name = request.form.get("assignment_name")
        assignment_desc = request.form.get("assignment_desc")
        assignment_input_format = request.form.get("assignment_input_format")
        assignment_output_format = request.form.get("assignment_output_format")

        assignment_input_cases = [
            request.form.get(k) if request.form.get(k) != "" else None
            for k in request.form.keys()
            if k.startswith("assignment_input_case_")
        ]
        assignment_input_cases = "---".join(
            [str(x) for x in assignment_input_cases if x])

        assignment_output_cases = [
            request.form.get(k) if request.form.get(k) != "" else None
            for k in request.form.keys()
            if k.startswith("assignment_output_case_")
        ]
        assignment_output_cases = "---".join(
            [str(x) for x in assignment_output_cases if x])

        # print(assignment_input_cases, assignment_output_cases)

        assignment_constraints = request.form.get("assignment_constraints")
        assignment_deadline = request.form.get('assignment_deadline')
        assignment_deadline = datetime.strptime(assignment_deadline,
                                                "%Y-%m-%dT%H:%M")

        user = GetUser(session["email"])

        # return redirect(url_for("classroom_main", class_code=class_code))

        if session.get("class_code") is None:
            flash("Classroom not selected while creating assignment!", "info")
            return redirect(url_for("dashboard"))

        class_code = session["class_code"]
        classroom = Classroom.query.filter_by(code=class_code).first()
        if classroom is None:
            flash("No class found!", "danger")
            return redirect(url_for("dashboard"))

        if not classroom in user.classrooms:
            flash("Access denied to this classroom!", "warning")
            return redirect(url_for("dashboard"))

        assignment = Assignment(assignment_name,
                                assignment_desc,
                                classroom=classroom)
        assignment.update(input_format=assignment_input_format,
                          output_format=assignment_output_format)
        assignment.update(input_cases=assignment_input_cases,
                          output_cases=assignment_output_cases)
        assignment.update(constraints=assignment_constraints,
                          deadline=assignment_deadline)

        db.session.add(assignment)
        db.session.commit()

        # Create assignment upload folder
        if not os.path.exists(os.path.join(SUBMISSION_FOLDER,
                                           assignment.code)):
            os.mkdir(os.path.join(SUBMISSION_FOLDER, assignment.code))

        flash("Assignment created successfully!", "success")
        return redirect(
            url_for("assignment_main", assignment_code=assignment.code))