コード例 #1
0
ファイル: _view_assignment.py プロジェクト: animekraxe/galah
def view_assignment(assignment_id):
    simple_archive_form = SimpleArchiveForm()

    # Convert the assignment in the URL into an ObjectId
    try:
        id = ObjectId(assignment_id)
    except InvalidId:
        logger.info("Invalid Assignment ID requested.")

        abort(404)

    # Retrieve the assignment
    try:
        assignment = Assignment.objects.get(id=id)
    except Assignment.DoesNotExist:
        logger.info("Non-extant ID requested.")

        abort(404)

    # Get all of the submissions for this assignmnet
    submissions = list(Submission.objects(user=current_user.id, assignment=id).order_by("-most_recent", "-timestamp"))

    # Add the pretty version of each submissions timestamp
    for i in submissions:
        i.timestamp_pretty = pretty_time(i.timestamp)

    return render_template(
        "assignment.html",
        now=datetime.datetime.today(),
        create_time_element=create_time_element,
        assignment=assignment,
        submissions=submissions,
        simple_archive_form=simple_archive_form,
        new_submissions=[v for k, v in get_flashed_messages(with_categories=True) if k == "new_submission"],
    )
コード例 #2
0
def view_assignment(assignment_id):
    simple_archive_form = SimpleArchiveForm()

    # Convert the assignment in the URL into an ObjectId
    try:
        id = ObjectId(assignment_id)
    except InvalidId:
        app.logger.debug("Invalid ID (%s)" % str(id))

        abort(404)

    # Retrieve the assignment
    try:
        assignment = Assignment.objects.get(id=id)
    except Assignment.DoesNotExist:
        app.logger.debug("Non-extant ID (%s)" % str(id))

        abort(404)

    # Get all of the submissions for this assignmnet
    submissions = list(Submission.objects(user=current_user.id, assignment=id))

    # Add the pretty version of each submissions timestamp
    for i in submissions:
        i.timestamp_pretty = pretty_time(i.timestamp)

    return render_template(
        "assignment.html",
        now=datetime.datetime.today(),
        create_time_element=create_time_element,
        assignment=assignment,
        submissions=submissions,
        simple_archive_form=simple_archive_form,
        new_submissions=[
            v for k, v in get_flashed_messages(with_categories=True)
            if k == "new_submission"
        ])
コード例 #3
0
ファイル: _view_assignment.py プロジェクト: itsjohncs/galah
def view_assignment(assignment_id):
    simple_archive_form = SimpleArchiveForm()

    # Convert the assignment in the URL into an ObjectId
    try:
        id = ObjectId(assignment_id)
    except InvalidId:
        logger.info("Invalid Assignment ID requested.")

        abort(404)

    # Retrieve the assignment
    try:
        assignment = Assignment.objects.get(id=id)
    except Assignment.DoesNotExist:
        logger.info("Non-extant ID requested.")

        abort(404)

    assignment.apply_personal_deadlines(current_user)

    # Get all of the submissions for this assignment
    submissions = list(
        Submission.objects(user=current_user.id,
                           assignment=id).order_by("-most_recent",
                                                   "-timestamp"))

    # Get student submissions if being viewed as teacher
    student_submissions = []
    students = []
    if current_user.account_type in ["teacher", "teaching_assistant"]:
        students = list(
            User.objects(classes=assignment.for_class,
                         account_type="student").order_by("-email"))

        student_submissions = list(
            Submission.objects(user__in=[i.email for i in students],
                               assignment=assignment_id,
                               most_recent=True))

    test_results = list(
        TestResult.objects(
            id__in=[i.test_results for i in submissions if i.test_results]))

    # Match test results to submissions
    for i in submissions:
        for j in test_results:
            if i.test_results == j.id:
                i.test_results_obj = j

    # Current time to be compared to submission test_request_timestamp
    now = datetime.datetime.now()

    # Flag to set refresh trigger if user is waiting on test results
    wait_and_refresh = False

    # Add the pretty version of each submissions timestamp
    for i in submissions:
        i.timestamp_pretty = pretty_time(i.timestamp)
        i.status = "Submitted"

        # If the user submitted a test request and there aren't any results
        if (i.test_request_timestamp and not i.test_results):
            timedelta = now - i.test_request_timestamp
            i.show_resubmit = (timedelta > config["STUDENT_RETRY_INTERVAL"])
            if not i.show_resubmit:
                i.status = "Waiting for test results..."
            else:
                i.status = "Test request timed out"
        elif (i.test_results and i.test_results_obj.failed):
            i.status = "Tests Failed"
            i.show_resubmit = True
        elif (i.test_results and not i.test_results_obj.failed):
            i.status = "Tests Completed"

    wait_and_refresh = \
        any(i.status == "Waiting for test results..." for i in submissions)

    return render_template(
        "assignment.html",
        now=datetime.datetime.today(),
        create_time_element=create_time_element,
        assignment=assignment,
        submissions=submissions,
        simple_archive_form=simple_archive_form,
        wait_and_refresh=wait_and_refresh,
        new_submissions=[
            v for k, v in get_flashed_messages(with_categories=True)
            if k == "new_submission"
        ],
        view_as_teacher=(current_user.account_type
                         in ["teacher", "teaching_assistant"]),
        students=students,
        student_submissions=student_submissions,
        enumerate=enumerate)
コード例 #4
0
ファイル: _view_assignment.py プロジェクト: pastorenue/galah
def view_assignment(assignment_id):
    simple_archive_form = SimpleArchiveForm()

    # Convert the assignment in the URL into an ObjectId
    try:
        id = ObjectId(assignment_id)
    except InvalidId:
        logger.info("Invalid Assignment ID requested.")

        abort(404)

    # Retrieve the assignment
    try:
        assignment = Assignment.objects.get(id=id)
    except Assignment.DoesNotExist:
        logger.info("Non-extant ID requested.")

        abort(404)

    assignment.apply_personal_deadlines(current_user)

    # Get all of the submissions for this assignment
    submissions = list(Submission.objects(user=current_user.id, assignment=id).order_by("-most_recent", "-timestamp"))

    # Get student submissions if being viewed as teacher
    student_submissions = []
    students = []
    if current_user.account_type in ["teacher", "teaching_assistant"]:
        students = list(User.objects(classes=assignment.for_class, account_type="student").order_by("-email"))

        student_submissions = list(
            Submission.objects(user__in=[i.email for i in students], assignment=assignment_id, most_recent=True)
        )

    test_results = list(TestResult.objects(id__in=[i.test_results for i in submissions if i.test_results]))

    # Match test results to submissions
    for i in submissions:
        for j in test_results:
            if i.test_results == j.id:
                i.test_results_obj = j

    # Current time to be compared to submission test_request_timestamp
    now = datetime.datetime.now()

    # Flag to set refresh trigger if user is waiting on test results
    wait_and_refresh = False

    # Add the pretty version of each submissions timestamp
    for i in submissions:
        i.timestamp_pretty = pretty_time(i.timestamp)
        i.status = "Submitted"

        # If the user submitted a test request and there aren't any results
        if i.test_request_timestamp and not i.test_results:
            timedelta = now - i.test_request_timestamp
            i.show_resubmit = timedelta > config["STUDENT_RETRY_INTERVAL"]
            if not i.show_resubmit:
                i.status = "Waiting for test results..."
            else:
                i.status = "Test request timed out"
        elif i.test_results and i.test_results_obj.failed:
            i.status = "Tests Failed"
            i.show_resubmit = True
        elif i.test_results and not i.test_results_obj.failed:
            i.status = "Tests Completed"

    wait_and_refresh = any(i.status == "Waiting for test results..." for i in submissions)

    return render_template(
        "assignment.html",
        now=datetime.datetime.today(),
        create_time_element=create_time_element,
        assignment=assignment,
        submissions=submissions,
        simple_archive_form=simple_archive_form,
        wait_and_refresh=wait_and_refresh,
        new_submissions=[v for k, v in get_flashed_messages(with_categories=True) if k == "new_submission"],
        view_as_teacher=(current_user.account_type in ["teacher", "teaching_assistant"]),
        students=students,
        student_submissions=student_submissions,
        enumerate=enumerate,
    )