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

Assignment handling within single-user syncing #8219

Conversation

jamalex
Copy link
Member

@jamalex jamalex commented Jul 22, 2021

Summary

Fixes #8079.

Reviewer guidance

There's a lot of code duplication between the logic for exams and for lessons, but they're different enough (e.g. in the naming of some attributes) that it seemed cleanest to just copy-paste and adapt.

I'll add some inline notes.

To run the test locally, I use:

INTEGRATION_TEST=True pytest kolibri/core/auth/test/test_morango_integration.py::EcosystemSingleUserAssignmentTestCase::test_single_user_assignment_sync --pdb --capture=no

Testing checklist

  • Contributor has fully tested the PR manually
  • If there are any front-end changes, before/after screenshots are included
  • Critical user journeys are covered by Gherkin stories
  • Critical and brittle code paths are covered by unit tests

PR process

  • PR has the correct target branch and milestone
  • PR has 'needs review' or 'work-in-progress' label
  • If PR is ready for review, a reviewer has been added. (Don't use 'Assignees')
  • If this is an important user-facing change, PR or related issue has a 'changelog' label
  • If this includes an internal dependency change, a link to the diff is provided

Reviewer checklist

  • Automated test coverage is satisfactory
  • PR is fully functional
  • PR has been tested for accessibility regressions
  • External dependency files were updated if necessary (yarn and pip)
  • Documentation is updated
  • Contributor is in AUTHORS.md

@jamalex jamalex added the work-in-progress Not ready for review label Jul 22, 2021
@jamalex jamalex added this to the 0.15.0 milestone Jul 22, 2021
@jamalex jamalex removed the work-in-progress Not ready for review label Jul 27, 2021
@jamalex jamalex changed the title Assignment handling within single-user syncing [WIP] Assignment handling within single-user syncing Jul 27, 2021
) # noqa: F401
from morango.api.viewsets import session_controller # noqa: F401

register_sync_event_handlers(session_controller)
Copy link
Member Author

Choose a reason for hiding this comment

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

I wasn't sure whether this was the best place to put this, but... I couldn't think of a better place. Suggestions welcome, or maybe this is ok.


kwargs = _extract_kwargs_from_context(context)

if isinstance(context, LocalSessionContext):
Copy link
Member Author

Choose a reason for hiding this comment

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

This is to avoid having the hooks be called twice, once for local and once for remote context.

@@ -57,7 +57,7 @@ def manage(self, *args):

def create_model(self, model, **kwargs):
kwarg_text = ",".join(
'{key}=\\"{value}\\"'.format(key=key, value=value)
"{key}={value}".format(key=key, value=repr(value))
for key, value in kwargs.items()
Copy link
Member Author

Choose a reason for hiding this comment

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

Was getting some format issues in the piping -- this helped.

@jamalex jamalex force-pushed the your_assignment_is_due_on_monday_class branch from 455b6c8 to 89d106e Compare July 27, 2021 04:01
@@ -0,0 +1,106 @@
from .models import ExamAssignment
Copy link
Member Author

Choose a reason for hiding this comment

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

This file is virtually identical to kolibri/core/lessons/single_user_assignment_utils.py -- in terms of the overall structure -- some field names and details are different.

I'd be happy to try to DRY it up, it just might make it a bit more "magical" (e.g. a function containing this logic that gets passed models and field names etc, and then the comments in here etc would need to be generalized as well -- might hurt readability.

Copy link
Contributor

Choose a reason for hiding this comment

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

agree with the copy/paste strategy for code maintainability

@jamalex jamalex requested review from rtibbles and bjester July 27, 2021 04:06
Copy link
Member

@rtibbles rtibbles left a comment

Choose a reason for hiding this comment

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

Code all makes sense to me - some potential for cleanup, and possibly some optimization?



@define_hook
class FacilityDataSyncHook(KolibriHook):
Copy link
Member

Choose a reason for hiding this comment

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

This could be separated out into a pre-hook and post-hook, which would then allow each method to be setup with an @abc.abstractmethod decorator, which then gives a clear requirement that the method be instantiated.


# create new syncable exam objects for all new assignments
for assignment in to_create:
IndividualSyncableExam.objects.create(
Copy link
Member

Choose a reason for hiding this comment

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

Any reason not to do a bulk create here?

Copy link
Member

@rtibbles rtibbles left a comment

Choose a reason for hiding this comment

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

Tests check out. Other issues can be followed up after merge.

Copy link
Contributor

@indirectlylit indirectlylit left a comment

Choose a reason for hiding this comment

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

exciting! nice work

@@ -0,0 +1,106 @@
from .models import ExamAssignment
Copy link
Contributor

Choose a reason for hiding this comment

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

agree with the copy/paste strategy for code maintainability

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.

Add side loading for single user sync of data that does not fall within single user scope
3 participants