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

feat: handle optional blocks in verticals #279

Closed

Conversation

DanielVZ96
Copy link
Contributor

@DanielVZ96 DanielVZ96 commented Feb 27, 2024

Note: Not sure how to increase coverage since there's no testing in place for

Description: handles not counting optional children for non-optional verticals

Dependencies:
open-craft/edx-platform#638

Testing instructions:

  • Using this branch and feat: optional xblocks edx-platform#34275
  • Create a sequence with a single optional unit and a non-optional unit
    • You can set them as optional in the settings for the unit in the content outline in studio
  • Finish only the non-optional unit
  • Make sure the sequence gets marked as done

Reviewers:

  • tag reviewer
  • tag reviewer

Merge checklist:

  • All reviewers approved
  • CI build is green
  • Version bumped
  • Changelog record added
  • Documentation updated (not only docstrings)
  • Commits are squashed

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)

Private-ref: BB-8586

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Feb 27, 2024
@openedx-webhooks
Copy link

openedx-webhooks commented Feb 27, 2024

Thanks for the pull request, @DanielVZ96! 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 as you can:

  • 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.

This is currently a draft pull request. When it is ready for our review and all tests are green, click "Ready for Review", or remove "WIP" from the title, as appropriate.

@DanielVZ96 DanielVZ96 force-pushed the dvz/optional-completions branch 2 times, most recently from b857473 to 4f66c25 Compare February 27, 2024 02:23
@DanielVZ96 DanielVZ96 force-pushed the dvz/optional-completions branch from 4f66c25 to 51c5c24 Compare February 27, 2024 02:33
child_locations = [
child.scope_ids.usage_id for child in self.get_completable_children(item)
# for non-optional verticals, only include non-optional children
if optional_vertical or not getattr(child, "optional_content", False)
Copy link
Member

Choose a reason for hiding this comment

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

@DanielVZ96, shouldn't this be something like not optional_vertical and not getattr(child, "optional_content", False)? We should add a test for this. We could also use a variable like required_completion = getattr(item, "optional_content", False) to avoid too many negations that make this condition hard to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are only four combinations:

  1. Optional Vertical and Optional Child -> Include Child
  2. Optional Vertical and Required Child -> Include Child (shouldn't happen but this is how we can handle it gracefully)
  3. Required Vertical and Required Child -> Include Child
  4. Required Vertical and Optional Child -> Exclude Child

This means that the only case in which we want to exclude the child
is when the parent is required and the child isn't.

This can be achieved with either of the following logic (nots turns ors into ands)

        a) optional_vertical or required_child  # can be read as "if it's an optional vertical include all, if it's a required vertical only accept required children"
        b) not (required_vertical and optional_child)  # can be read as "exclude the 4th case" 

Your's (not optional_vertical and not getattr(child, "optional_content", False)) can be paraphrased as required_vertical and required_child, and would only return true (thus include) the third case.

I'm refactoring the code to include this explanation and make it easier to test, since the vertical_is_complete is really hard to test without having edx-platform code available.

@Agrendalath
Copy link
Member

@DanielVZ96, please convert this PR to draft - since this should be merged with the upstream PR to edx-platform, it will take a while before this is ready to be merged.

@DanielVZ96 DanielVZ96 marked this pull request as draft February 29, 2024 01:08
@DanielVZ96 DanielVZ96 force-pushed the dvz/optional-completions branch 2 times, most recently from 2d35ae3 to 1f3b3c6 Compare February 29, 2024 07:26
@DanielVZ96 DanielVZ96 force-pushed the dvz/optional-completions branch from 1f3b3c6 to a1d90c6 Compare February 29, 2024 07:29
@DanielVZ96 DanielVZ96 requested a review from Agrendalath March 1, 2024 00:19
@staticmethod
def matches_vertical_optional_completion(optional_vertical, optional_child):
"""
Checks if child should count towards a vertical's completion.
Copy link
Member

Choose a reason for hiding this comment

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

Could we expand this docstring a bit to explain the concept of "optional" XBlocks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 209 to 214
for optional_vertical, optional_child, should_include_child in (
(True, True, True),
(True, False, True),
(False, False, True),
(False, True, False), # do not count optional children for non-optional verticals
):
Copy link
Member

Choose a reason for hiding this comment

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

Nit: we should use @ddt.data for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@DanielVZ96 DanielVZ96 requested a review from Agrendalath March 9, 2024 22:54
@pomegranited
Copy link
Contributor

Hi @DanielVZ96 @Agrendalath are you planning to finish this PR?

@pkulkark and I are CCs on this repo, so one of us can help with reviewing and merging.

@DanielVZ96
Copy link
Contributor Author

@pomegranited It depends on this PR i'm working on open-craft/edx-platform#638 It's been a bit slow because I can't run js browser tests locally in palm.

@pomegranited
Copy link
Contributor

No worries @DanielVZ96 , thanks for the update!

@Agrendalath
Copy link
Member

@DanielVZ96, I need help understanding this PR's context. A course consists of the following components:

  1. Course
  2. Section (chapter)
  3. Subsection (sequence)
  4. Unit (vertical)
  5. Individual XBlocks (potentially with children, in case of a LibraryBlock, ProblemBlock, etc.).

This PR handles counting the optional children of a vertical, which are mentioned in the last point above. We can override XBlock fields through the Django shell, but how can we create such optional XBlocks in Studio?

Also, should we mark the parent as completed in case the optional children are incomplete? In this case, users would get the completion checkmarks for these sections. It would be impossible for them to find the incomplete items if they want to increase their optional completion. I suppose we could introduce some new completion checkmark type (e.g., partial completion), but this will require more investigation and is out of scope here.

@DanielVZ96
Copy link
Contributor Author

@Agrendalath you are completely right. i may have confused the terminology when working on this. there's no way of setting a single xblock as optional in studio for now.

@DanielVZ96 DanielVZ96 closed this Apr 8, 2024
@openedx-webhooks
Copy link

@DanielVZ96 Even though your pull request wasn’t merged, please take a moment to answer a two question survey so we can improve your experience in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants