Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENT-2230 Add patch method on learner portal enrollment endpoint #565

Merged
merged 1 commit into from
Sep 6, 2019

Conversation

brittneyexline
Copy link
Contributor

Description: Describe in a couple of sentence what this PR adds

JIRA: Link to JIRA ticket

Dependencies: dependencies on other outstanding PRs, issues, etc.

Merge deadline: List merge deadline (if any)

Installation instructions: List any non-trivial installation
instructions.

Testing instructions:

  1. Open page A
  2. Do thing B
  3. Expect C to happen
  4. If D happened instead - check failed.

Merge checklist:

  • New requirements are in the right place
    • base.in if needed in production, but edx-platform doesn't install it.
    • test-master.in if edx-platform pins it, with a matching version.
  • Regenerate requirements with make upgrade && make requirements (and make sure to fix any errors).
    DO NOT just add dependencies to requirements/*.txt files.
  • Called make static for webpack bundling if any static content was updated.
  • All reviewers approved
  • CI build is green
  • Version bumped
  • Changelog record added
  • Documentation updated (not only docstrings)
  • Commits are (reasonably) squashed
  • Translations are updated

Post merge:

  • Create a tag
  • Check new version is pushed to PyPi after tag-triggered build is finished.
  • Delete working branch (if not needed anymore)
  • edx-platform PR (be sure to include edx-platform requirements upgrades that were present in this PR)

Author concerns: List any concerns about this PR - inelegant
solutions, hacks, quick-and-dirty implementations, concerns about
migrations, etc.


data = EnterpriseCourseEnrollmentSerializer(
overviews,
enterprise_enrollments,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a deoptimization? Now we will make a query to the course overview table for every enterprise enrollment instead of batching them like the previous code was doing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the motivation for this was so that it was easier to serialize one enrollment's data below in what the patch function returned, and to also have access to the enterprise enrollment object itself in the serializer for the status determination. i considered passing the enterprise_enrollments as context, but it seemed awkward to do that considering this serializer is supposed to serialize "enrollments". i'm not sure what the performance implications are though... i would guess the table is indexed by course id?

enterprise_customer_user=enterprise_customer_user
).values_list('course_id', flat=True)

overviews = get_course_overviews(course_ids_for_ent_enrollments)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just move the get_course_overviews call to the serializer, but keep the ability to pass multiple enterprise enrollments to the serializer.

Copy link
Contributor

@christopappas christopappas Sep 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default the serializer will only ever work on 1 object at a time though, so even if we hand multiple course enrollments to the serializer, still would be doing a get_course_overviews call for each item in that list/queryset we hand it

A suggestion: in the view, make 1 call to get all the course overviews that we will ever need to look at, and then pass that to the serializer's context. So instead of calling get_course_overviews in the serializer, you could just lookup the course_overview info in the dict that exists in the context

^ This would get you a) 1 DB call for all course_overviews b) the ability to still serialize enterprise course enrollment objects

enterprise_customer_id = request.query_params.get('enterprise_id', None)
course_id = request.query_params.get('course_id', None)
marked_done = request.query_params.get('marked_done', None)
if not (enterprise_customer_id and course_id) or marked_done is None:
Copy link
Contributor

@christopappas christopappas Sep 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personal preference, but I think I prefer not mixing ANDs and ORs if it's possible. Something like:

if not enterprise_customer_id or not course_id or marked_done is None:

Feel free to disregard though

context={'request': request},
).data

return Response(data)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having the response as the newly updated course enrollment serialized by EnterpriseCourseEnrollmentSerializer matches what the frontend will be looking for :)

@brittneyexline brittneyexline force-pushed the bexline/move_to_completed branch 3 times, most recently from 459ce81 to 1c2dd30 Compare September 6, 2019 15:46
@christopappas christopappas self-requested a review September 6, 2019 20:23
Copy link
Contributor

@christopappas christopappas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 , just that one tiny, non-essential suggestion!

Copy link
Member

@adamstankiewicz adamstankiewicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Though, I might feel more comfortable leaving the final approval to those a little more knowledgeable about Django :)

@brittneyexline brittneyexline force-pushed the bexline/move_to_completed branch from 1c2dd30 to 96688bb Compare September 6, 2019 20:27
@brittneyexline brittneyexline force-pushed the bexline/move_to_completed branch from 96688bb to 736a300 Compare September 6, 2019 20:28
@brittneyexline brittneyexline merged commit 69cdb2a into master Sep 6, 2019
@brittneyexline brittneyexline deleted the bexline/move_to_completed branch September 6, 2019 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants