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
646ad4a1
Commit
646ad4a1
authored
Oct 15, 2014
by
Clinton Blackburn
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #34 from edx/opaque-keys
Updated Course ID Regex and CSV filename
parents
29437878
66914fa0
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
9 deletions
+26
-9
analytics_data_api/v0/tests/test_views.py
+0
-0
analytics_data_api/v0/urls/courses.py
+3
-4
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 @
646ad4a1
This diff is collapsed.
Click to expand it.
analytics_data_api/v0/urls/courses.py
View file @
646ad4a1
import
re
from
django.conf.urls
import
patterns
,
url
from
analytics_data_api.v0.views
import
courses
as
views
COURSE_ID_PATTERN
=
r'(?P<course_id>[^/+]+[/+][^/+]+[/+][^/]+)'
COURSE_URLS
=
[
(
'activity'
,
views
.
CourseActivityWeeklyView
,
'activity'
),
(
'recent_activity'
,
views
.
CourseActivityMostRecentWeekView
,
'recent_activity'
),
...
...
@@ -18,4 +16,5 @@ COURSE_URLS = [
urlpatterns
=
[]
for
path
,
view
,
name
in
COURSE_URLS
:
urlpatterns
+=
patterns
(
''
,
url
(
r'^(?P<course_id>.+)/'
+
re
.
escape
(
path
)
+
r'/$'
,
view
.
as_view
(),
name
=
name
))
regex
=
r'^{0}/{1}/$'
.
format
(
COURSE_ID_PATTERN
,
path
)
urlpatterns
+=
patterns
(
''
,
url
(
regex
,
view
.
as_view
(),
name
=
name
))
analytics_data_api/v0/views/courses.py
View file @
646ad4a1
...
...
@@ -8,6 +8,7 @@ from django.db.models import Max
from
django.http
import
Http404
from
django.utils.timezone
import
make_aware
,
utc
from
rest_framework
import
generics
from
opaque_keys.edx.keys
import
CourseKey
from
analytics_data_api.v0
import
models
,
serializers
...
...
@@ -15,8 +16,11 @@ from analytics_data_api.v0 import models, serializers
class
BaseCourseView
(
generics
.
ListAPIView
):
start_date
=
None
end_date
=
None
course_id
=
None
slug
=
None
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
course_id
=
self
.
kwargs
.
get
(
'course_id'
)
start_date
=
request
.
QUERY_PARAMS
.
get
(
'start_date'
)
end_date
=
request
.
QUERY_PARAMS
.
get
(
'end_date'
)
timezone
=
utc
...
...
@@ -44,12 +48,21 @@ class BaseCourseView(generics.ListAPIView):
raise
NotImplementedError
def
get_queryset
(
self
):
course_id
=
self
.
kwargs
.
get
(
'course_id'
)
self
.
verify_course_exists_or_404
(
course_id
)
queryset
=
self
.
model
.
objects
.
filter
(
course_id
=
course_id
)
self
.
verify_course_exists_or_404
(
self
.
course_id
)
queryset
=
self
.
model
.
objects
.
filter
(
course_id
=
self
.
course_id
)
queryset
=
self
.
apply_date_filtering
(
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
class
CourseActivityWeeklyView
(
BaseCourseView
):
...
...
@@ -80,6 +93,7 @@ class CourseActivityWeeklyView(BaseCourseView):
end_date -- Date before which all data should be returned (exclusive)
"""
slug
=
u'engagement-activity'
model
=
models
.
CourseActivityWeekly
serializer_class
=
serializers
.
CourseActivityWeeklySerializer
...
...
@@ -244,6 +258,7 @@ class CourseEnrollmentByBirthYearView(BaseCourseEnrollmentView):
end_date -- Date before which all data should be returned (exclusive)
"""
slug
=
u'enrollment-age'
serializer_class
=
serializers
.
CourseEnrollmentByBirthYearSerializer
model
=
models
.
CourseEnrollmentByBirthYear
...
...
@@ -263,6 +278,7 @@ class CourseEnrollmentByEducationView(BaseCourseEnrollmentView):
start_date -- Date after which all data should be returned (inclusive)
end_date -- Date before which all data should be returned (exclusive)
"""
slug
=
u'enrollment-education'
serializer_class
=
serializers
.
CourseEnrollmentByEducationSerializer
model
=
models
.
CourseEnrollmentByEducation
...
...
@@ -287,6 +303,7 @@ class CourseEnrollmentByGenderView(BaseCourseEnrollmentView):
start_date -- Date after which all data should be returned (inclusive)
end_date -- Date before which all data should be returned (exclusive)
"""
slug
=
u'enrollment-gender'
serializer_class
=
serializers
.
CourseEnrollmentByGenderSerializer
model
=
models
.
CourseEnrollmentByGender
...
...
@@ -304,7 +321,7 @@ class CourseEnrollmentView(BaseCourseEnrollmentView):
start_date -- Date after which all data should be returned (inclusive)
end_date -- Date before which all data should be returned (exclusive)
"""
slug
=
u'enrollment'
serializer_class
=
serializers
.
CourseEnrollmentDailySerializer
model
=
models
.
CourseEnrollmentDaily
...
...
@@ -329,7 +346,7 @@ class CourseEnrollmentByLocationView(BaseCourseEnrollmentView):
start_date -- Date after which all data should be returned (inclusive)
end_date -- Date before which all data should be returned (exclusive)
"""
slug
=
u'enrollment-location'
serializer_class
=
serializers
.
CourseEnrollmentByCountrySerializer
model
=
models
.
CourseEnrollmentByCountry
...
...
requirements/base.txt
View file @
646ad4a1
...
...
@@ -7,3 +7,4 @@ ipython==2.1.0 # BSD
django-rest-swagger==0.1.14 # BSD
djangorestframework-csv==1.3.3 # BSD
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