Skip to content

Commit

Permalink
refactor: use a single view
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanttV committed Feb 16, 2024
1 parent f9d671e commit ecb3fe1
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 91 deletions.
13 changes: 7 additions & 6 deletions lms/djangoapps/ora_staff_grader/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
from django.urls import include
from django.urls import path

from rest_framework.routers import DefaultRouter

from lms.djangoapps.ora_staff_grader.views import (
InitializeView,
Expand All @@ -13,19 +13,18 @@
SubmissionLockView,
SubmissionStatusFetchView,
UpdateGradeView,
AssessmentFeedbackToView,
AssessmentFeedbackFromView,
AssessmentFeedbackView,
)


urlpatterns = []
app_name = "ora-staff-grader"

router = DefaultRouter()
router.register("assessments/feedback", AssessmentFeedbackView, basename="assessment-feedback")

urlpatterns += [
path("mock/", include("lms.djangoapps.ora_staff_grader.mock.urls")),
path("initialize", InitializeView.as_view(), name="initialize"),
path("assessments/feedback/from", AssessmentFeedbackFromView.as_view(), name="assessment-feedback-from"),
path("assessments/feedback/to", AssessmentFeedbackToView.as_view(), name="assessment-feedback-to"),
path("submission/batch/unlock", SubmissionBatchUnlockView.as_view(), name="batch-unlock"),
path("submission/files", SubmissionFilesFetchView.as_view(), name="fetch-files"),
path(
Expand All @@ -37,3 +36,5 @@
path("submission/grade", UpdateGradeView.as_view(), name="update-grade"),
path("submission", SubmissionFetchView.as_view(), name="fetch-submission"),
]

urlpatterns += router.urls
149 changes: 64 additions & 85 deletions lms/djangoapps/ora_staff_grader/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# NOTE: we intentionally add extra args using @require_params
# pylint: disable=arguments-differ
import logging
from typing import Callable

from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication
from edx_rest_framework_extensions.auth.session.authentication import (
Expand All @@ -15,9 +16,12 @@
from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import UsageKey
from openassessment.xblock.config_mixin import WAFFLE_NAMESPACE, ENHANCED_STAFF_GRADER
from rest_framework.decorators import action
from rest_framework.generics import RetrieveAPIView
from rest_framework.permissions import IsAuthenticated
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.viewsets import ViewSet
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.exceptions import ItemNotFoundError

Expand Down Expand Up @@ -150,105 +154,80 @@ def get(self, request, ora_location, *args, **kwargs):
return UnknownErrorResponse()


class AssessmentFeedbackToView(StaffGraderBaseView):
class AssessmentFeedbackView(StaffGraderBaseView, ViewSet):
"""
(GET) List all assessments given by a user (according to
their submissionUUID) in an ORA assignment.
View for fetching assessment feedback for a submission.
**Query Params**:
- oraLocation (str): ORA location for XBlock handling
- submissionUUID (str): The ORA submission UUID
Response: {
assessments (List[dict]): [
{
"assessment_id: (str) Assessment id
"scorer_name: (str) Scorer name
"scorer_username: (str) Scorer username
"scorer_email: (str) Scorer email
"assessment_date: (str) Assessment date
"assessment_scores (List[dict]) [
{
"criterion_name: (str) Criterion name
"score_earned: (int) Score earned
"score_type: (str) Score type
}
]
"problem_step (str) Problem step (Self, Peer, or Staff)
"feedback: (str) Feedback of the assessment
}
]
}
Errors:
- MissingParamResponse (HTTP 400) for missing params
- BadOraLocationResponse (HTTP 400) for bad ORA location
- XBlockInternalError (HTTP 500) for an issue with ORA
- UnknownError (HTTP 500) for other errors
"""
@require_params([PARAM_ORA_LOCATION, PARAM_SUBMISSION_ID])
def get(self, request, ora_location, submission_uuid, *args, **kwargs):
"""Get assessments given by a user in an ORA assignment"""
try:
assessments_data = {"assessments": get_assessments_to(request, ora_location, submission_uuid)}
response_data = AssessmentFeedbackSerializer(assessments_data).data
return Response(response_data)

except (InvalidKeyError, ItemNotFoundError):
log.error(f"Bad ORA location provided: {ora_location}")
return BadOraLocationResponse()
**Methods**
except XBlockInternalError as ex:
log.error(ex)
return InternalErrorResponse(context=ex.context)

except Exception as ex:
log.exception(ex)
return UnknownErrorResponse()
* (GET) api/ora_staff_grader/assessments/feedback/from
List all assessments received by a user (according to
their submissionUUID) in an ORA assignment.

class AssessmentFeedbackFromView(StaffGraderBaseView):
"""
(GET) List all assessments received by a user (according to
their submissionUUID) in an ORA assignment.
* (GET) api/ora_staff_grader/assessments/feedback/to
List all assessments given by a user (according to
their submissionUUID) in an ORA assignment.
**Query Params**:
- oraLocation (str): ORA location for XBlock handling
- submissionUUID (str): The ORA submission UUID
Response: {
assessments (List[dict]): [
{
"assessment_id: (str) Assessment id
"scorer_name: (str) Scorer name
"scorer_username: (str) Scorer username
"scorer_email: (str) Scorer email
"assessment_date: (str) Assessment date
"assessment_scores (List[dict]) [
{
"criterion_name: (str) Criterion name
"score_earned: (int) Score earned
"score_type: (str) Score type
}
]
"problem_step (str) Problem step (Self, Peer, or Staff)
"feedback: (str) Feedback of the assessment
}
]
}
**Response**:
Errors:
- MissingParamResponse (HTTP 400) for missing params
- BadOraLocationResponse (HTTP 400) for bad ORA location
- XBlockInternalError (HTTP 500) for an issue with ORA
- UnknownError (HTTP 500) for other errors
{
assessments (List[dict]): [
{
"assessment_id: (str) Assessment id
"scorer_name: (str) Scorer name
"scorer_username: (str) Scorer username
"scorer_email: (str) Scorer email
"assessment_date: (str) Assessment date
"assessment_scores (List[dict]) [
{
"criterion_name: (str) Criterion name
"score_earned: (int) Score earned
"score_type: (str) Score type
}
]
"problem_step (str) Problem step (Self, Peer, or Staff)
"feedback: (str) Feedback of the assessment
}
]
}
**Errors**:
- MissingParamResponse (HTTP 400) for missing params
- BadOraLocationResponse (HTTP 400) for bad ORA location
- XBlockInternalError (HTTP 500) for an issue with ORA
- UnknownError (HTTP 500) for other errors
"""
@action(methods=['get'], detail=False, url_path='from')
@require_params([PARAM_ORA_LOCATION, PARAM_SUBMISSION_ID])
def get_from(self, request: Request, ora_location: str, submission_uuid: str, *args, **kwargs):
return self._get_assessments(request, get_assessments_from, ora_location, submission_uuid)

@action(methods=['get'], detail=False, url_path='to')
@require_params([PARAM_ORA_LOCATION, PARAM_SUBMISSION_ID])
def get(self, request, ora_location, submission_uuid, *args, **kwargs):
"""Get assessments received by a user in an ORA assignment"""
def get_to(self, request: Request, ora_location: str, submission_uuid: str, *args, **kwargs):
return self._get_assessments(request, get_assessments_to, ora_location, submission_uuid)

def _get_assessments(
self, request: Request, getter_func: Callable, ora_location: str, submission_uuid: str
):
"""
Fetches assessment data using the provided assessment getter function.
Args:
request (Request): The Django request object.
getter_func (Callable): A function that retrieves assessments based on criteria.
ora_location (str): The ORA location for XBlock handling.
submission_uuid (str): The ORA submission UUID.
Returns:
A Django response object containing serialized assessment data or an error response.
"""
try:
assessments_data = {"assessments": get_assessments_from(request, ora_location, submission_uuid)}
assessments_data = {"assessments": getter_func(request, ora_location, submission_uuid)}
response_data = AssessmentFeedbackSerializer(assessments_data).data
return Response(response_data)

Expand Down

0 comments on commit ecb3fe1

Please sign in to comment.