Skip to content

Commit cd0b3af

Browse files
Update b2b docs (#3040)
1 parent aa68b45 commit cd0b3af

File tree

4 files changed

+46
-15
lines changed

4 files changed

+46
-15
lines changed

b2b/management/commands/b2b_courseware.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,15 @@ def handle_add(self, contract, coursewares, **kwargs):
147147
)
148148
)
149149

150-
prog_add, prog_skip = contract.add_program_courses(courseware)
150+
prog_add, prog_skip, prog_no_source = contract.add_program_courses(
151+
courseware
152+
)
153+
if prog_no_source > 0:
154+
self.stdout.write(
155+
self.style.WARNING(
156+
f"Program '{courseware.readable_id}' has {prog_no_source} courses with no source runs; cannot create contract runs for these courses."
157+
)
158+
)
151159
contract.save()
152160
managed += prog_add
153161
skipped += prog_skip

b2b/models.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -377,18 +377,25 @@ def add_program_courses(self, program):
377377
- program (courses.Program): the program to add
378378
379379
Returns:
380-
- tuple, courses created and skipped
380+
- tuple: Tuple with three integers:
381+
- number of course runs created
382+
- number of course runs skipped (already existed)
383+
- number of courses with no source run
381384
"""
382385

383386
from b2b.api import create_contract_run
384387

385-
managed = 0
386-
skipped = 0
387-
388388
# Clear any cached properties to ensure fresh data
389389
if hasattr(program, "_courses_with_requirements_data"):
390390
delattr(program, "_courses_with_requirements_data")
391391

392+
managed = 0
393+
skipped_run_creation = 0
394+
no_source = program.courses_qset.exclude(
395+
models.Q(courseruns__is_source_run=True)
396+
| models.Q(courseruns__run_tag="SOURCE")
397+
).count()
398+
392399
for course in program.courses_qset.filter(
393400
models.Q(courseruns__is_source_run=True)
394401
| models.Q(courseruns__run_tag="SOURCE")
@@ -397,11 +404,11 @@ def add_program_courses(self, program):
397404
create_contract_run(self, course)
398405
managed += 1
399406
except TargetCourseRunExistsError: # noqa: PERF203
400-
skipped += 1
407+
skipped_run_creation += 1
401408

402409
self.programs.add(program)
403410

404-
return (managed, skipped)
411+
return (managed, skipped_run_creation, no_source)
405412

406413
class Meta:
407414
"""Meta options for the ContractPage."""

b2b/models_test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ def test_add_program_courses_to_contract(mocker):
2424

2525
program.refresh_from_db()
2626

27-
created, skipped = contract.add_program_courses(program)
27+
created, skipped, no_source = contract.add_program_courses(program)
2828

2929
assert created == 3
3030
assert skipped == 0
31+
assert no_source == 0
3132

3233
contract.save()
3334
contract.refresh_from_db()
@@ -40,10 +41,11 @@ def test_add_program_courses_to_contract(mocker):
4041
program.save()
4142
program.refresh_from_db()
4243

43-
created, skipped = contract.add_program_courses(program)
44+
created, skipped, no_source = contract.add_program_courses(program)
4445

4546
assert created == 1
4647
assert skipped == 3
48+
assert no_source == 0
4749

4850
contract.save()
4951
contract.refresh_from_db()

docs/source/configuration/b2b.rst

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ The management commands you will need to use are:
1414

1515
* ``b2b_contracts`` - manages organizations and contracts
1616
* ``b2b_list`` - lists data about B2B resources
17+
* ``b2b_courseware`` - manages courseware assignments to contracts
1718

1819
Quick Setup
1920
-----------
@@ -27,13 +28,18 @@ This is how UAI contracts that have SSO integration with the host organization a
2728

2829

2930
#. Create a contract with a new organization:
30-
``b2b_contract create UniversityX "UniversityX Contract" sso --description "Test uncapped SSO contract"``
31+
``b2b_contract create "University X" "Contract Name" sso --description "Test uncapped SSO contract"``
32+
33+
- if organization does not yet exist, add ``--create`` and ``--org-key <org key>`` to set the organization key
3134
#. List the details about your new organization:
3235
``b2b_list organizations``
3336
#. List the details about your new contract: *(You'll need the ID from the output for the next step.)*
3437
``b2b_list contracts``
35-
#. Add the course to the contract. This will also create a course run for the course:
36-
``b2b_contract courseware <contract ID> <course readable ID>``
38+
#. Add courseware (course or program) to the contract. This will also create a course run for the course:
39+
``b2b_courseware add <contract ID> <courseware readable ID>``
40+
41+
- Courses must have a *source run* in order to create contract-specific runs; see the "Courseware Setup in edX" section below for more details.
42+
- Program readable_ids must begin with ``program-v1``.
3743
#. List the details about the contract's courseware:
3844
``b2b_list courseware --contract <contract ID>``
3945

@@ -52,7 +58,7 @@ This is how a B2B contract would be set up typically.
5258
#. List the details about your new contract: *(You'll need the ID from the output for the next step.)*
5359
``b2b_list contracts``
5460
#. Add the course to the contract. This will also create a course run for the course:
55-
``b2b_contract courseware <contract ID> <course readable ID>``
61+
``b2b_courseware add <contract ID> <course readable ID>``
5662
#. List the details about the contract's courseware:
5763
``b2b_list courseware --contract <contract ID>``
5864
#. Get the enrollment codes for the contract:
@@ -183,9 +189,17 @@ Courseware Setup in edX
183189

184190
B2B courses in edX should be set up in a particular fashion, both to make sure we can identify them within edX easily, and to allow the system to automatically create runs for new contracts.
185191

186-
Each B2B course starts with a source course. Usually, these are separate courses and runs, but not always. If you're creating a new course, it should be created in edX with the organization ``UAI_SOURCE`` and the run tag ``SOURCE``. A corresponding course run in MITx Online should also be created. The ``import_courserun`` command can be used to help facilitate this. If you want to use an existing course, you should create a ``SOURCE`` run for it from the run you want to use as the source course in edX.
192+
Each B2B course starts with a source course and courserun. Usually, these are separate courses and runs, but not always.
193+
194+
195+
* If using a separate course & courserun, it should be created in edX with the organization ``UAI_SOURCE`` and run tag ``SOURCE``. The ``import courserun`` command can assist in importing the course from OpenEdx into MITxOnline.
196+
* If reusing an existing course, create a new courserunw with run tag ``SOURCE``.
197+
198+
199+
**In both cases:** The courserun should have the `is_source_run` flag set to `True` in MITxOnline (this can be done via Django Admin).
200+
201+
When associating a course or program with a contract, the ``b2b_contract courseware`` command will try to create a contract-specific run for each source course (either the one you've specified or the ones that are in the specified program).
187202

188-
When associating a course or program with a contract, the ``b2b_contract courseware`` command will try to create a contract-specific run for each source course (either the one you've specified or the ones that are in the specified program). It does this by trying to find an appropriate source course run for the course in MITx Online. It will look first for a course run with the run tag ``SOURCE`` - if it can't find this, it will use whatever the first course run is in database order. **This is probably not what you want** - you should try to have a ``SOURCE`` course run if at all possible.
189203

190204
Course runs will be created using the start/end date of the contract, if those dates are set. If the contract is open-ended, the runs will be created with the current time/date as the course and enrollment start date and no end date. The runs will be created with the organization set to ``UAI_`` and the organization key set in the org record, and the run key will be set to the current year, ``C``, and the ID of the new contract.
191205

0 commit comments

Comments
 (0)