Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-analytics-data-api
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-analytics-data-api
Commits
66914fa0
Commit
66914fa0
authored
Oct 07, 2014
by
Clinton Blackburn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated CSV filename
File names are now compatible with opaque keys.
parent
af18880a
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
5 deletions
+23
-5
analytics_data_api/v0/tests/test_views.py
+0
-0
analytics_data_api/v0/views/courses.py
+22
-5
requirements/base.txt
+1
-0
No files found.
analytics_data_api/v0/tests/test_views.py
View file @
66914fa0
This diff is collapsed.
Click to expand it.
analytics_data_api/v0/views/courses.py
View file @
66914fa0
...
@@ -8,6 +8,7 @@ from django.db.models import Max
...
@@ -8,6 +8,7 @@ from django.db.models import Max
from
django.http
import
Http404
from
django.http
import
Http404
from
django.utils.timezone
import
make_aware
,
utc
from
django.utils.timezone
import
make_aware
,
utc
from
rest_framework
import
generics
from
rest_framework
import
generics
from
opaque_keys.edx.keys
import
CourseKey
from
analytics_data_api.v0
import
models
,
serializers
from
analytics_data_api.v0
import
models
,
serializers
...
@@ -15,8 +16,11 @@ from analytics_data_api.v0 import models, serializers
...
@@ -15,8 +16,11 @@ from analytics_data_api.v0 import models, serializers
class
BaseCourseView
(
generics
.
ListAPIView
):
class
BaseCourseView
(
generics
.
ListAPIView
):
start_date
=
None
start_date
=
None
end_date
=
None
end_date
=
None
course_id
=
None
slug
=
None
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
course_id
=
self
.
kwargs
.
get
(
'course_id'
)
start_date
=
request
.
QUERY_PARAMS
.
get
(
'start_date'
)
start_date
=
request
.
QUERY_PARAMS
.
get
(
'start_date'
)
end_date
=
request
.
QUERY_PARAMS
.
get
(
'end_date'
)
end_date
=
request
.
QUERY_PARAMS
.
get
(
'end_date'
)
timezone
=
utc
timezone
=
utc
...
@@ -44,12 +48,21 @@ class BaseCourseView(generics.ListAPIView):
...
@@ -44,12 +48,21 @@ class BaseCourseView(generics.ListAPIView):
raise
NotImplementedError
raise
NotImplementedError
def
get_queryset
(
self
):
def
get_queryset
(
self
):
course_id
=
self
.
kwargs
.
get
(
'course_id'
)
self
.
verify_course_exists_or_404
(
self
.
course_id
)
self
.
verify_course_exists_or_404
(
course_id
)
queryset
=
self
.
model
.
objects
.
filter
(
course_id
=
self
.
course_id
)
queryset
=
self
.
model
.
objects
.
filter
(
course_id
=
course_id
)
queryset
=
self
.
apply_date_filtering
(
queryset
)
queryset
=
self
.
apply_date_filtering
(
queryset
)
return
queryset
return
queryset
def
get_csv_filename
(
self
):
course_key
=
CourseKey
.
from_string
(
self
.
course_id
)
course_id
=
u'-'
.
join
([
course_key
.
org
,
course_key
.
course
,
course_key
.
run
])
return
u'{0}--{1}.csv'
.
format
(
course_id
,
self
.
slug
)
def
finalize_response
(
self
,
request
,
response
,
*
args
,
**
kwargs
):
if
request
.
META
.
get
(
'HTTP_ACCEPT'
)
==
u'text/csv'
:
response
[
'Content-Disposition'
]
=
u'attachment; filename={}'
.
format
(
self
.
get_csv_filename
())
return
super
(
BaseCourseView
,
self
)
.
finalize_response
(
request
,
response
,
*
args
,
**
kwargs
)
# pylint: disable=line-too-long
# pylint: disable=line-too-long
class
CourseActivityWeeklyView
(
BaseCourseView
):
class
CourseActivityWeeklyView
(
BaseCourseView
):
...
@@ -80,6 +93,7 @@ class CourseActivityWeeklyView(BaseCourseView):
...
@@ -80,6 +93,7 @@ class CourseActivityWeeklyView(BaseCourseView):
end_date -- Date before which all data should be returned (exclusive)
end_date -- Date before which all data should be returned (exclusive)
"""
"""
slug
=
u'engagement-activity'
model
=
models
.
CourseActivityWeekly
model
=
models
.
CourseActivityWeekly
serializer_class
=
serializers
.
CourseActivityWeeklySerializer
serializer_class
=
serializers
.
CourseActivityWeeklySerializer
...
@@ -244,6 +258,7 @@ class CourseEnrollmentByBirthYearView(BaseCourseEnrollmentView):
...
@@ -244,6 +258,7 @@ class CourseEnrollmentByBirthYearView(BaseCourseEnrollmentView):
end_date -- Date before which all data should be returned (exclusive)
end_date -- Date before which all data should be returned (exclusive)
"""
"""
slug
=
u'enrollment-age'
serializer_class
=
serializers
.
CourseEnrollmentByBirthYearSerializer
serializer_class
=
serializers
.
CourseEnrollmentByBirthYearSerializer
model
=
models
.
CourseEnrollmentByBirthYear
model
=
models
.
CourseEnrollmentByBirthYear
...
@@ -263,6 +278,7 @@ class CourseEnrollmentByEducationView(BaseCourseEnrollmentView):
...
@@ -263,6 +278,7 @@ class CourseEnrollmentByEducationView(BaseCourseEnrollmentView):
start_date -- Date after which all data should be returned (inclusive)
start_date -- Date after which all data should be returned (inclusive)
end_date -- Date before which all data should be returned (exclusive)
end_date -- Date before which all data should be returned (exclusive)
"""
"""
slug
=
u'enrollment-education'
serializer_class
=
serializers
.
CourseEnrollmentByEducationSerializer
serializer_class
=
serializers
.
CourseEnrollmentByEducationSerializer
model
=
models
.
CourseEnrollmentByEducation
model
=
models
.
CourseEnrollmentByEducation
...
@@ -287,6 +303,7 @@ class CourseEnrollmentByGenderView(BaseCourseEnrollmentView):
...
@@ -287,6 +303,7 @@ class CourseEnrollmentByGenderView(BaseCourseEnrollmentView):
start_date -- Date after which all data should be returned (inclusive)
start_date -- Date after which all data should be returned (inclusive)
end_date -- Date before which all data should be returned (exclusive)
end_date -- Date before which all data should be returned (exclusive)
"""
"""
slug
=
u'enrollment-gender'
serializer_class
=
serializers
.
CourseEnrollmentByGenderSerializer
serializer_class
=
serializers
.
CourseEnrollmentByGenderSerializer
model
=
models
.
CourseEnrollmentByGender
model
=
models
.
CourseEnrollmentByGender
...
@@ -304,7 +321,7 @@ class CourseEnrollmentView(BaseCourseEnrollmentView):
...
@@ -304,7 +321,7 @@ class CourseEnrollmentView(BaseCourseEnrollmentView):
start_date -- Date after which all data should be returned (inclusive)
start_date -- Date after which all data should be returned (inclusive)
end_date -- Date before which all data should be returned (exclusive)
end_date -- Date before which all data should be returned (exclusive)
"""
"""
slug
=
u'enrollment'
serializer_class
=
serializers
.
CourseEnrollmentDailySerializer
serializer_class
=
serializers
.
CourseEnrollmentDailySerializer
model
=
models
.
CourseEnrollmentDaily
model
=
models
.
CourseEnrollmentDaily
...
@@ -329,7 +346,7 @@ class CourseEnrollmentByLocationView(BaseCourseEnrollmentView):
...
@@ -329,7 +346,7 @@ class CourseEnrollmentByLocationView(BaseCourseEnrollmentView):
start_date -- Date after which all data should be returned (inclusive)
start_date -- Date after which all data should be returned (inclusive)
end_date -- Date before which all data should be returned (exclusive)
end_date -- Date before which all data should be returned (exclusive)
"""
"""
slug
=
u'enrollment-location'
serializer_class
=
serializers
.
CourseEnrollmentByCountrySerializer
serializer_class
=
serializers
.
CourseEnrollmentByCountrySerializer
model
=
models
.
CourseEnrollmentByCountry
model
=
models
.
CourseEnrollmentByCountry
...
...
requirements/base.txt
View file @
66914fa0
...
@@ -7,3 +7,4 @@ ipython==2.1.0 # BSD
...
@@ -7,3 +7,4 @@ ipython==2.1.0 # BSD
django-rest-swagger==0.1.14 # BSD
django-rest-swagger==0.1.14 # BSD
djangorestframework-csv==1.3.3 # BSD
djangorestframework-csv==1.3.3 # BSD
iso3166==0.1 # MIT
iso3166==0.1 # MIT
-e git+https://github.com/edx/opaque-keys.git@d45d0bd8d64c69531be69178b9505b5d38806ce0#egg=opaque-keys
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