-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Self paced relative dates #23008
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
Merged
cpennington
merged 2 commits into
openedx:master
from
cpennington:self-paced-relative-dates
Feb 21, 2020
Merged
Self paced relative dates #23008
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # -*- coding: utf-8 -*- | ||
| """ | ||
| Django Admin pages for SelfPacedRelativeDatesConfig. | ||
| """ | ||
|
|
||
|
|
||
| from django.contrib import admin | ||
|
|
||
| from openedx.core.djangoapps.config_model_utils.admin import StackedConfigModelAdmin | ||
|
|
||
| from .models import SelfPacedRelativeDatesConfig | ||
|
|
||
|
|
||
| admin.site.register(SelfPacedRelativeDatesConfig, StackedConfigModelAdmin) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
openedx/core/djangoapps/course_date_signals/migrations/0001_initial.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # Generated by Django 1.11.27 on 2020-02-03 21:22 | ||
| from __future__ import unicode_literals | ||
|
|
||
| from django.conf import settings | ||
| from django.db import migrations, models | ||
| import django.db.models.deletion | ||
| import openedx.core.djangoapps.config_model_utils.models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| initial = True | ||
|
|
||
| dependencies = [ | ||
| ('course_overviews', '0019_improve_courseoverviewtab'), | ||
| ('sites', '0002_alter_domain_unique'), | ||
| migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name='SelfPacedRelativeDatesConfig', | ||
| fields=[ | ||
| ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
| ('change_date', models.DateTimeField(auto_now_add=True, verbose_name='Change date')), | ||
| ('enabled', models.NullBooleanField(default=None, verbose_name='Enabled')), | ||
| ('org', models.CharField(blank=True, db_index=True, help_text='Configure values for all course runs associated with this Organization. This is the organization string (i.e. edX, MITx).', max_length=255, null=True)), | ||
| ('org_course', models.CharField(blank=True, db_index=True, help_text="Configure values for all course runs associated with this course. This is should be formatted as 'org+course' (i.e. MITx+6.002x, HarvardX+CS50).", max_length=255, null=True, validators=[openedx.core.djangoapps.config_model_utils.models.validate_course_in_org], verbose_name='Course in Org')), | ||
| ('changed_by', models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL, verbose_name='Changed by')), | ||
| ('course', models.ForeignKey(blank=True, help_text='Configure values for this course run. This should be formatted as the CourseKey (i.e. course-v1://MITx+6.002x+2019_Q1)', null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='course_overviews.CourseOverview', verbose_name='Course Run')), | ||
| ('site', models.ForeignKey(blank=True, help_text='Configure values for all course runs associated with this site.', null=True, on_delete=django.db.models.deletion.CASCADE, to='sites.Site')), | ||
| ], | ||
| options={ | ||
| 'abstract': False, | ||
| }, | ||
| ), | ||
| migrations.AddIndex( | ||
| model_name='selfpacedrelativedatesconfig', | ||
| index=models.Index(fields=['site', 'org', 'course'], name='course_date_site_id_a44836_idx'), | ||
| ), | ||
| migrations.AddIndex( | ||
| model_name='selfpacedrelativedatesconfig', | ||
| index=models.Index(fields=['site', 'org', 'org_course', 'course'], name='course_date_site_id_c0164a_idx'), | ||
| ), | ||
| ] |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| """ | ||
| Models for configuration course_date_signals | ||
|
|
||
| SelfPacedRelativeDatesConfig: | ||
| manage which orgs/courses/course runs have self-paced relative dates enabled | ||
| """ | ||
|
|
||
| from openedx.core.djangoapps.config_model_utils.models import StackedConfigurationModel | ||
|
|
||
|
|
||
| class SelfPacedRelativeDatesConfig(StackedConfigurationModel): | ||
|
cpennington marked this conversation as resolved.
Outdated
|
||
| """ | ||
| Configuration to manage the SelfPacedRelativeDates settings. | ||
|
|
||
| .. no_pii: | ||
| """ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| """ | ||
| Utility functions around course dates. | ||
|
|
||
| get_expected_duration: return the expected duration of a course (absent any user information) | ||
| """ | ||
|
|
||
| from datetime import timedelta | ||
|
|
||
| from course_modes.models import CourseMode | ||
| from openedx.core.djangoapps.catalog.utils import get_course_run_details | ||
|
|
||
|
|
||
| MIN_DURATION = timedelta(weeks=4) | ||
| MAX_DURATION = timedelta(weeks=18) | ||
|
|
||
|
|
||
| def get_expected_duration(course): | ||
| """ | ||
| Return a `datetime.timedelta` defining the expected length of the supplied course. | ||
| """ | ||
|
|
||
| access_duration = MIN_DURATION | ||
|
|
||
| verified_mode = CourseMode.verified_mode_for_course(course=course, include_expired=True) | ||
|
|
||
| if not verified_mode: | ||
| return None | ||
|
|
||
| # The user course expiration date is the content availability date | ||
| # plus the weeks_to_complete field from course-discovery. | ||
| discovery_course_details = get_course_run_details(course.id, ['weeks_to_complete']) | ||
| expected_weeks = discovery_course_details.get('weeks_to_complete') | ||
| if expected_weeks: | ||
| access_duration = timedelta(weeks=expected_weeks) | ||
|
|
||
| # Course access duration is bounded by the min and max duration. | ||
| access_duration = max(MIN_DURATION, min(MAX_DURATION, access_duration)) | ||
|
|
||
| return access_duration |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.