Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
d5a77dd7
Commit
d5a77dd7
authored
Dec 20, 2017
by
Harry Rein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't show unpulished or un-upgradable seats in available sessions.
parent
72bb440d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
12 deletions
+49
-12
common/djangoapps/student/views.py
+5
-12
openedx/core/djangoapps/catalog/utils.py
+44
-0
No files found.
common/djangoapps/student/views.py
View file @
d5a77dd7
...
...
@@ -3,7 +3,6 @@ Student Views
"""
import
datetime
import
dateutil
import
json
import
logging
import
uuid
...
...
@@ -75,7 +74,7 @@ from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification
# Note that this lives in LMS, so this dependency should be refactored.
from
notification_prefs.views
import
enable_notifications
from
openedx.core.djangoapps
import
monitoring_utils
from
openedx.core.djangoapps.catalog.utils
import
get_programs_with_type
,
get_course_runs_for_course
from
openedx.core.djangoapps.catalog.utils
import
get_programs_with_type
,
get_
visible_
course_runs_for_course
from
openedx.core.djangoapps.certificates.api
import
certificates_viewable_for_course
from
openedx.core.djangoapps.credit.email_utils
import
get_credit_provider_display_names
,
make_providers_strings
from
openedx.core.djangoapps.embargo
import
api
as
embargo_api
...
...
@@ -703,16 +702,10 @@ def dashboard(request):
course_entitlement_available_sessions
=
{}
for
course_entitlement
in
course_entitlements
:
course_entitlement
.
update_expired_at
()
# Filter only the course runs that do not have an enrollment_end date set, or have one set in the future
course_runs_for_course
=
get_course_runs_for_course
(
str
(
course_entitlement
.
course_uuid
))
enrollable_course_runs
=
[]
for
course_run
in
course_runs_for_course
:
enrollment_end
=
course_run
.
get
(
'enrollment_end'
)
if
not
enrollment_end
or
(
dateutil
.
parser
.
parse
(
enrollment_end
)
>
datetime
.
datetime
.
now
(
UTC
)):
enrollable_course_runs
.
append
(
course_run
)
course_entitlement_available_sessions
[
str
(
course_entitlement
.
uuid
)]
=
enrollable_course_runs
valid_course_runs
=
get_visible_course_runs_for_course
(
course_entitlement
,
str
(
course_entitlement
.
course_uuid
)
)
course_entitlement_available_sessions
[
str
(
course_entitlement
.
uuid
)]
=
valid_course_runs
# Record how many courses there are so that we can get a better
# understanding of usage patterns on prod.
...
...
openedx/core/djangoapps/catalog/utils.py
View file @
d5a77dd7
"""Helper functions for working with the catalog service."""
from
dateutil.parser
import
parse
as
datetime_parse
import
copy
import
datetime
import
logging
from
django.conf
import
settings
...
...
@@ -14,6 +16,7 @@ from openedx.core.djangoapps.catalog.cache import (
from
openedx.core.djangoapps.catalog.models
import
CatalogIntegration
from
openedx.core.lib.edx_api_utils
import
get_edx_api_data
from
openedx.core.lib.token_utils
import
JwtBuilder
from
pytz
import
UTC
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -239,6 +242,47 @@ def get_course_runs_for_course(course_uuid):
else
:
return
[]
def
get_visible_course_runs_for_course
(
entitlement
,
course_uuid
):
"""
We only want to show courses for a particular entitlement that:
1) Are currently running or in the future
2) A user can enroll in
3) A user can upgrade in
4) Are published
"""
course_runs_for_course
=
get_course_runs_for_course
(
course_uuid
)
enrollable_course_runs
=
[]
# Only show published course runs that can still be enrolled and upgraded
now
=
datetime
.
datetime
.
now
(
UTC
)
for
course_run
in
course_runs_for_course
:
# Only courses that have not ended will be displayed
run_start
=
course_run
.
get
(
'start'
)
run_end
=
course_run
.
get
(
'end'
)
is_running
=
run_start
and
run_end
and
datetime_parse
(
run_end
)
>
now
# Only courses that can currently be enrolled in will be displayed
enrollment_start
=
course_run
.
get
(
'enrollment_start'
)
enrollment_end
=
course_run
.
get
(
'enrollment_end'
)
can_enroll
=
((
not
enrollment_start
or
datetime_parse
(
enrollment_start
)
<
now
)
and
(
not
enrollment_end
or
(
datetime_parse
(
enrollment_end
)
>
now
)))
# Only upgrade-able courses will be displayed
upgrade_deadline
=
next
(
iter
(
[
seat
.
get
(
'upgrade_deadline'
)
for
seat
in
course_run
.
get
(
'seats'
)
if
seat
.
get
(
'type'
)
==
entitlement
.
mode
]),
None
)
can_upgrade
=
not
upgrade_deadline
or
(
datetime_parse
(
upgrade_deadline
)
>
now
)
# Only published courses will be displayed
is_published
=
course_run
.
get
(
'status'
)
==
'published'
if
is_running
and
can_upgrade
and
can_enroll
and
is_published
:
enrollable_course_runs
.
append
(
course_run
)
return
enrollable_course_runs
def
get_course_run_details
(
course_run_key
,
fields
):
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment