Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
course-discovery
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
course-discovery
Commits
903d013d
Commit
903d013d
authored
Oct 27, 2016
by
Ivan Ivic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[SOL-1975] Sort CourseRunViewSet queryset by start date
parent
5eecb677
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
46 additions
and
6 deletions
+46
-6
course_discovery/apps/api/serializers.py
+2
-0
course_discovery/apps/api/v1/tests/test_views/test_course_runs.py
+13
-0
course_discovery/apps/api/v1/views.py
+4
-3
course_discovery/apps/core/utils.py
+7
-2
course_discovery/apps/course_metadata/migrations/0034_auto_20161103_0855.py
+19
-0
course_discovery/apps/course_metadata/models.py
+1
-1
No files found.
course_discovery/apps/api/serializers.py
View file @
903d013d
...
...
@@ -385,7 +385,9 @@ class CourseRunWithProgramsSerializer(CourseRunSerializer):
programs
=
serializers
.
SerializerMethodField
()
def
get_programs
(
self
,
obj
):
programs
=
[]
# Filter out non-deleted programs which this course_run is part of the program course_run exclusion
if
obj
.
programs
:
programs
=
[
program
for
program
in
obj
.
programs
.
all
()
if
(
self
.
context
.
get
(
'include_deleted_programs'
)
or
program
.
status
!=
ProgramStatus
.
Deleted
)
and
...
...
course_discovery/apps/api/v1/tests/test_views/test_course_runs.py
View file @
903d013d
...
...
@@ -110,6 +110,19 @@ class CourseRunViewSetTests(SerializationMixin, ElasticsearchTestMixin, APITestC
self
.
serialize_course_run
(
CourseRun
.
objects
.
all
()
.
order_by
(
Lower
(
'key'
)),
many
=
True
)
)
def
test_list_sorted_by_course_start_date
(
self
):
""" Verify the endpoint returns a list of all catalogs sorted by course start date. """
url
=
'{root}?ordering=start'
.
format
(
root
=
reverse
(
'api:v1:course_run-list'
))
with
self
.
assertNumQueries
(
11
):
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertListEqual
(
response
.
data
[
'results'
],
self
.
serialize_course_run
(
CourseRun
.
objects
.
all
()
.
order_by
(
'start'
),
many
=
True
)
)
def
test_list_query
(
self
):
""" Verify the endpoint returns a filtered list of courses """
course_runs
=
CourseRunFactory
.
create_batch
(
3
,
title
=
'Some random title'
,
course__partner
=
self
.
partner
)
...
...
course_discovery/apps/api/v1/views.py
View file @
903d013d
...
...
@@ -19,7 +19,7 @@ from haystack.query import SQ
from
rest_framework
import
status
,
viewsets
from
rest_framework.decorators
import
detail_route
,
list_route
from
rest_framework.exceptions
import
PermissionDenied
,
ParseError
from
rest_framework.filters
import
DjangoFilterBackend
from
rest_framework.filters
import
DjangoFilterBackend
,
OrderingFilter
from
rest_framework.permissions
import
IsAuthenticated
from
rest_framework.response
import
Response
...
...
@@ -289,12 +289,13 @@ class CourseViewSet(viewsets.ReadOnlyModelViewSet):
class
CourseRunViewSet
(
viewsets
.
ReadOnlyModelViewSet
):
""" CourseRun resource. """
filter_backends
=
(
DjangoFilterBackend
,)
filter_backends
=
(
DjangoFilterBackend
,
OrderingFilter
)
filter_class
=
filters
.
CourseRunFilter
lookup_field
=
'key'
lookup_value_regex
=
COURSE_RUN_ID_REGEX
queryset
=
CourseRun
.
objects
.
all
()
.
order_by
(
Lower
(
'key'
)
)
ordering_fields
=
(
'start'
,
)
permission_classes
=
(
IsAuthenticated
,)
queryset
=
CourseRun
.
objects
.
all
()
.
order_by
(
Lower
(
'key'
))
serializer_class
=
serializers
.
CourseRunWithProgramsSerializer
def
_get_partner
(
self
):
...
...
course_discovery/apps/core/utils.py
View file @
903d013d
...
...
@@ -67,8 +67,13 @@ class SearchQuerySetWrapper(object):
def
__init__
(
self
,
qs
):
self
.
qs
=
qs
def
count
(
self
):
return
self
.
qs
.
count
()
def
__getattr__
(
self
,
item
):
try
:
super
()
.
__getattr__
(
item
)
except
AttributeError
:
# If the attribute is not found on this class,
# proxy the request to the SearchQuerySet.
return
getattr
(
self
.
qs
,
item
)
def
__iter__
(
self
):
for
result
in
self
.
qs
:
...
...
course_discovery/apps/course_metadata/migrations/0034_auto_20161103_0855.py
0 → 100644
View file @
903d013d
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'course_metadata'
,
'0033_courserun_mobile_available'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'courserun'
,
name
=
'start'
,
field
=
models
.
DateTimeField
(
blank
=
True
,
null
=
True
,
db_index
=
True
),
),
]
course_discovery/apps/course_metadata/models.py
View file @
903d013d
...
...
@@ -331,7 +331,7 @@ class CourseRun(TimeStampedModel):
max_length
=
255
,
default
=
None
,
null
=
True
,
blank
=
True
,
help_text
=
_
(
"Title specific for this run of a course. Leave this value blank to default to the parent course's title."
))
start
=
models
.
DateTimeField
(
null
=
True
,
blank
=
True
)
start
=
models
.
DateTimeField
(
null
=
True
,
blank
=
True
,
db_index
=
True
)
end
=
models
.
DateTimeField
(
null
=
True
,
blank
=
True
,
db_index
=
True
)
enrollment_start
=
models
.
DateTimeField
(
null
=
True
,
blank
=
True
)
enrollment_end
=
models
.
DateTimeField
(
null
=
True
,
blank
=
True
,
db_index
=
True
)
...
...
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