Skip to content

Commit

Permalink
chore: PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
adamstankiewicz committed Nov 2, 2023
1 parent e70cffe commit 80e6fa1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ class LearnerContentAssignmentResponseSerializer(serializers.ModelSerializer):
# This causes the related AssignmentConfiguration to be serialized as a UUID (in the response).
assignment_configuration = serializers.PrimaryKeyRelatedField(read_only=True)

actions = serializers.SerializerMethodField()
actions = LearnerContentAssignmentActionSerializer(
help_text='All actions associated with this assignment.',
many=True,
)

class Meta:
model = LearnerContentAssignment
Expand All @@ -79,16 +82,16 @@ class Meta:
]
read_only_fields = fields

def get_actions(self, assignment):
"""
Resolves any associated actions to the assignment in chronological order based on created timestamp.
"""
related_actions = assignment.actions.order_by('created').all()
return LearnerContentAssignmentActionSerializer(
related_actions,
help_text='All actions associated with this assignment.',
many=True,
).data
# def get_actions(self, assignment):
# """
# Resolves any associated actions to the assignment in chronological order based on created timestamp.
# """
# related_actions = assignment.actions.order_by('created').all()
# return LearnerContentAssignmentActionSerializer(
# related_actions,
# help_text='All actions associated with this assignment.',
# many=True,
# ).data


class LearnerContentAssignmentAdminResponseSerializer(LearnerContentAssignmentResponseSerializer):
Expand Down Expand Up @@ -120,6 +123,7 @@ class Meta(LearnerContentAssignmentResponseSerializer.Meta):
]
read_only_fields = fields

@extend_schema_field(serializers.CharField)
def get_error_reason(self, assignment):
"""
Resolves the error reason for the assignment, if any, for display purposes based on
Expand All @@ -130,7 +134,7 @@ def get_error_reason(self, assignment):
return None

# Assignment is an errored state, so determine the appropriate error reason so clients don't need to.
related_actions_with_error = assignment.actions.filter(error_reason__isnull=False).order_by('-created').all()
related_actions_with_error = assignment.actions.filter(error_reason__isnull=False).order_by('-created')
if not related_actions_with_error:
logger.warning(
'LearnerContentAssignment with UUID %s is in an errored state, but has no related '
Expand Down
7 changes: 5 additions & 2 deletions enterprise_access/apps/content_assignments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ def annotate_dynamic_fields_onto_queryset(cls, queryset):
LearnerContentAssignmentAction.objects.filter(
assignment=OuterRef('uuid'),
action_type=AssignmentActions.REMINDED,
completed_at__isnull=False,
error_reason__isnull=True,
completed_at__isnull=False,
)
)
).annotate(
Expand All @@ -363,8 +363,8 @@ def annotate_dynamic_fields_onto_queryset(cls, queryset):
LearnerContentAssignmentAction.objects.filter(
assignment=OuterRef('uuid'),
action_type=AssignmentActions.NOTIFIED,
completed_at__isnull=False,
error_reason__isnull=True,
completed_at__isnull=False,
)
)
).annotate(
Expand Down Expand Up @@ -455,6 +455,9 @@ class LearnerContentAssignmentAction(TimeStampedModel):

history = HistoricalRecords()

class Meta:
ordering = ['created']

def __str__(self):
return (
f'uuid={self.uuid}, action_type={self.action_type}, error_reason={self.error_reason}'
Expand Down
5 changes: 4 additions & 1 deletion enterprise_access/settings/devstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,13 @@

# CORS CONFIG
CORS_ORIGIN_WHITELIST = [
'http://localhost:1991', # frontend-admin-portal
'http://localhost:1991', # frontend-app-admin-portal
'http://localhost:8734', # frontend-app-learner-portal-enterprise
'http://localhost:18450', # frontend-app-support-tools
]
CSRF_TRUSTED_ORIGINS = [
'http://localhost:1991', # frontend-app-admin-portal
]
# END CORS

ECOMMERCE_URL = 'http://edx.devstack.ecommerce:18130'
Expand Down

0 comments on commit 80e6fa1

Please sign in to comment.