Skip to content

[SE-3329] Expose banner image url in course API - #25045

Merged
ormsbee merged 1 commit into
openedx:masterfrom
open-craft:gabor/expose-banner-image-url
Nov 17, 2020
Merged

[SE-3329] Expose banner image url in course API#25045
ormsbee merged 1 commit into
openedx:masterfrom
open-craft:gabor/expose-banner-image-url

Conversation

@gabor-boros

@gabor-boros gabor-boros commented Sep 22, 2020

Copy link
Copy Markdown
Contributor

This PR extends the course overview and detail APIs to include (both relative and absolute) banner image url, which allows content publishers to specify a banner image and then reuse that from a custom UI/integration.

Dependencies: None

Screenshots:

Screenshot_2020-11-12 Course Detail – Django REST framework
Screenshot_2020-11-12 Course List – Django REST framework

Sandbox URL: https://pr25045.sandbox.opencraft.hosting/

Merge deadline: Preferably 29th of September

Testing instructions:

  1. Open edX Studio from Content -> Files & Uploads, then copy the file name
  2. Paste the file name into Course Banner Image field into Settings -> Advanced Settings page
  3. Open <URL>/api/courses/v1/courses/ to check all the courses, where URL is the sandbox LMS URL
  4. Open <URL>/api/courses/v1/courses/<course_id> to see all the courses, where URL is the sandbox LMS URL and course_id is the course id

Author notes and concerns:

  1. The _AbsolutMediaSerializer is using a private attribute from AbsoluteURLField, but I found no other way to avoid code duplication and have the same absolute url conversion functionality, since AbsoluteURLField requires the request object
    Currently looking for ways to fix it.

Reviewers

Settings

EDXAPP_FEATURES:
  ENABLE_COMBINED_LOGIN_REGISTRATION: true

@openedx-webhooks

openedx-webhooks commented Sep 22, 2020

Copy link
Copy Markdown

Thanks for the pull request, @gabor-boros! I've created OSPR-4994 to keep track of it in JIRA, where we prioritize reviews. Please note that it may take us up to several weeks or months to complete a review and merge your PR.

Feel free to add as much of the following information to the ticket:

  • supporting documentation
  • Open edX discussion forum threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here.

Please let us know once your PR is ready for our review and all tests are green.

@openedx-webhooks openedx-webhooks added needs triage open-source-contribution PR author is not from Axim or 2U labels Sep 22, 2020
@gabor-boros gabor-boros changed the title feat(course-details): Expose banner image url in course API [SE-3329] Expose banner image url in course API Sep 22, 2020
@toxinu

toxinu commented Sep 23, 2020

Copy link
Copy Markdown
Contributor

@gabor-boros Code reviewed and I go through testing instructions. Please ping me when you want another review 👍🏻

@gabor-boros
gabor-boros marked this pull request as ready for review September 23, 2020 07:48
@gabor-boros

gabor-boros commented Sep 23, 2020

Copy link
Copy Markdown
Contributor Author

Then I'm pinging you @toxinu 😊

@openedx-webhooks openedx-webhooks added waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. and removed needs triage labels Sep 23, 2020
@natabene

Copy link
Copy Markdown
Contributor

@gabor-boros Thank you for your contribution. Please let me know once this is ready for our review.

@toxinu

toxinu commented Sep 24, 2020

Copy link
Copy Markdown
Contributor

@gabor-boros @natabene Reviewed and approved 👍🏻

@gabor-boros

Copy link
Copy Markdown
Contributor Author

@natabene It is ready from our side 😊

@openedx-webhooks openedx-webhooks added awaiting prioritization and removed waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. labels Sep 25, 2020
@gabor-boros

Copy link
Copy Markdown
Contributor Author

@natabene do I need to do anything else related to this PR? ☺️

@natabene

Copy link
Copy Markdown
Contributor

@gabor-boros No, just wait till we can get to it.

@bradenmacdonald bradenmacdonald left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@gabor-boros Overall seems good, but I have a few requested cleanups.

Comment thread openedx/core/djangoapps/content/course_overviews/models.py Outdated
Comment thread openedx/core/djangoapps/content/course_overviews/models.py Outdated
Comment thread openedx/core/djangoapps/content/course_overviews/models.py Outdated
Comment thread lms/djangoapps/course_api/serializers.py Outdated

@bradenmacdonald bradenmacdonald Nov 6, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I believe this hack is required because you're declaring the field within this method, instead of as a member of this serializer.

I think that if you just declare the field like this:

class _AbsolutMediaSerializer(_MediaSerializer):
    requires_context = True
    url = AbsoluteURLField(source="get_url")

    def get_url(self):
        ...

then it should work without context hacks.

Edit: Hmm, never mind I guess that won't work because it won't call the method on the serializer. Maybe you can override __init__ to get data and call apply_cdn_to_url on the data there? I think that's cleaner than overriding __call__ and passing the context around like this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, this cannot be done, because the BaseSerializer does not set the self.initial_data if data argument was empty. Although serializers has a get_initial method, the method will return an empty OrderedDict since the serializer did not receive data at all. So we need to pass the context around, but I'm opened to other ideas as well. When I did a research in this topic when I opened the PR, I did not find any other solution which is cleaner.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This test has the same docstring as the previous test and it's hard to tell the difference. It took me a while to figure out that this is testing a slightly different method. Plus it doesn't actually test what it says in the docstring, because this test case doesn't test the case where start_url is already an absolute URL.

Maybe combine the tests, or change the docstring to say "Test the apply_cdn_to_url method directly when used with a single URL"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, it seems I overlooked the docstring here. Thanks for pointing out! I'll fix this as well

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think you forgot to address this review comment ^

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, you are totally right. I'm doing it just right now. Sorry about that.

@gabor-boros

Copy link
Copy Markdown
Contributor Author

@bradenmacdonald I just adjusted most of the comments and updated the images in the description. Could you please give it another review round?

@bradenmacdonald

Copy link
Copy Markdown
Contributor

Thanks @gabor-boros. Looking good now. Please address the remaining issue with the test/docstring, get the tests passing, and squash down to a single commit with a useful commit message. I will then approve.

Also, can you link me directly to an example on the sandbox where I can see the output? And in future, please use sandboxes from Ocim prod, not Ocim stage, since the stage ones don't have valid HTTPS certificates.

@gabor-boros
gabor-boros force-pushed the gabor/expose-banner-image-url branch from 9208fc8 to 80d2737 Compare November 13, 2020 06:52
@gabor-boros

gabor-boros commented Nov 13, 2020

Copy link
Copy Markdown
Contributor Author

Thank you for the review @bradenmacdonald!

I did adjust the comments, squashed the commits and replaced the sandbox URL in the PR description besides made sure that tests are passing. Also I realized I made a typo in the migration file name so it is fixed as well.

PS: the appserver is still provisioning

Banner image URL is exposed on the course list and course details API
endpoints. The new `banner_image_url` API field has both the relative
and absolute URLs for the image it represents, if it is set.
@gabor-boros
gabor-boros force-pushed the gabor/expose-banner-image-url branch from 80d2737 to 2a35410 Compare November 13, 2020 14:35
@edx-status-bot

Copy link
Copy Markdown

Your PR has finished running tests. There were no failures.

@bradenmacdonald bradenmacdonald left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

@ormsbee
ormsbee merged commit 6a55b83 into openedx:master Nov 17, 2020
@openedx-webhooks

Copy link
Copy Markdown

@gabor-boros 🎉 Your pull request was merged!

Please take a moment to answer a two question survey so we can improve your experience in the future.


# URLs
# Not allowing null per django convention; not sure why many TextFields in this model do allow null
banner_image_url = TextField()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for this platform enhancement.
Where may I find documentation on how a "banner image" differs from a "course image"?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Where may I find documentation on how a "banner image" differs from a "course image"?

@nasthagiri I see some context here, but not sure that it qualifies as "documentation" : https://github.com/edx/edx-platform/blob/7afee25ce2150443eefe0ae60b81f3e4f6e61900/common/lib/xmodule/xmodule/course_module.py#L589-L609

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

From a consumer perspective, it would be useful to know when the difference between the 2 images. Perhaps it would help to describe where each image is displayed?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ping @gabor-boros - can you answer that question ^ ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@nasthagiri & @bradenmacdonald Apologies for replying that late, I probably missed the notification about this comment. As far as I can see, the banner_image is part of the extended_course_details. The original addition was part of edx@f7f281b as far as I can see, but I cannot find more information about that either.

From consumer perspective - in my mind - the difference is that the course image is kind of a thumbnail of a course while the banner image is like a cover image. So something like this:

Screenshot 2020-12-08 at 17 24 17

@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

EdX Release Notice: This PR has been deployed to the staging environment in preparation for a release to production.

@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

EdX Release Notice: This PR has been deployed to the production environment.

@bradenmacdonald
bradenmacdonald deleted the gabor/expose-banner-image-url branch November 23, 2020 23:27
nizarmah pushed a commit to open-craft/openedx-platform that referenced this pull request Jan 20, 2021
…image-url

[SE-3329] Expose banner image url in course API

(cherry picked from commit 6a55b83)
0x29a pushed a commit to open-craft/openedx-platform that referenced this pull request Feb 15, 2021
…image-url

[SE-3329] Expose banner image url in course API

(cherry picked from commit 6a55b83)
0x29a pushed a commit to open-craft/openedx-platform that referenced this pull request Apr 20, 2021
…image-url

[SE-3329] Expose banner image url in course API

(cherry picked from commit 6a55b83)
xitij2000 pushed a commit to open-craft/openedx-platform that referenced this pull request Nov 22, 2021
…image-url

[SE-3329] Expose banner image url in course API

(cherry picked from commit 6a55b83)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants