Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-notes-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-notes-api
Commits
4627cf17
Commit
4627cf17
authored
Jan 05, 2015
by
Oleg Marshev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
List all from db.
parent
2b66897a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
12 deletions
+23
-12
notesapi/v1/tests/test_views.py
+7
-2
notesapi/v1/views.py
+16
-10
No files found.
notesapi/v1/tests/test_views.py
View file @
4627cf17
...
...
@@ -445,9 +445,10 @@ class AnnotationViewTests(BaseAnnotationViewTests):
def
test_read_all_no_annotations
(
self
):
"""
Tests list all annotations endpoint when no annotations are present in
elasticsearch
.
Tests list all annotations endpoint when no annotations are present in
database
.
"""
url
=
reverse
(
'api:v1:annotations'
)
self
.
headers
[
"course_id"
]
=
"a/b/c"
response
=
self
.
client
.
get
(
url
,
self
.
headers
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertEqual
(
len
(
response
.
data
),
0
,
"no annotation should be returned in response"
)
...
...
@@ -457,10 +458,13 @@ class AnnotationViewTests(BaseAnnotationViewTests):
Tests list all annotations.
"""
for
i
in
xrange
(
5
):
kwargs
=
{
'text'
:
'Foo_{}'
.
format
(
i
)}
kwargs
=
{
'text'
:
'Foo_{}'
.
format
(
i
),
}
self
.
_create_annotation
(
**
kwargs
)
url
=
reverse
(
'api:v1:annotations'
)
self
.
headers
[
"course_id"
]
=
"test-course-id"
response
=
self
.
client
.
get
(
url
,
self
.
headers
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertEqual
(
len
(
response
.
data
),
5
,
"five annotations should be returned in response"
)
...
...
@@ -505,6 +509,7 @@ class TokenTests(BaseAnnotationViewTests):
"""
Ensure we can read list of annotations
"""
self
.
headers
[
"course_id"
]
=
"test-course-id"
response
=
self
.
client
.
get
(
self
.
url
,
self
.
headers
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
...
...
notesapi/v1/views.py
View file @
4627cf17
...
...
@@ -57,11 +57,16 @@ class AnnotationListView(APIView):
Get a list of all annotations.
"""
params
=
self
.
request
.
QUERY_PARAMS
.
dict
()
results
=
NoteMappingType
.
process_result
(
list
(
note_searcher
.
filter
(
**
params
)
.
values_dict
(
"_source"
))
)
return
Response
(
results
)
if
'course_id'
and
'user'
not
in
params
:
return
Response
(
status
=
status
.
HTTP_400_BAD_REQUEST
)
try
:
results
=
Note
.
objects
.
filter
(
course_id
=
params
[
'course_id'
],
user_id
=
params
[
'user'
])
except
Note
.
DoesNotExist
:
pass
return
Response
([
result
.
as_dict
()
for
result
in
results
])
def
post
(
self
,
*
args
,
**
kwargs
):
# pylint: disable=unused-argument
"""
...
...
@@ -98,12 +103,13 @@ class AnnotationDetailView(APIView):
Get an existing annotation.
"""
note_id
=
self
.
kwargs
.
get
(
'annotation_id'
)
if
not
note_searcher
.
filter
(
id
=
note_id
)
.
count
():
return
Response
(
False
,
status
=
status
.
HTTP_404_NOT_FOUND
)
results
=
NoteMappingType
.
process_result
(
list
(
note_searcher
.
filter
(
id
=
note_id
)
.
values_dict
(
"_source"
))
)
return
Response
(
results
[
0
])
try
:
note
=
Note
.
objects
.
get
(
id
=
note_id
)
except
Note
.
DoesNotExist
:
return
Response
(
'Annotation not found!'
,
status
=
status
.
HTTP_404_NOT_FOUND
)
return
Response
(
note
.
as_dict
())
def
put
(
self
,
*
args
,
**
kwargs
):
# pylint: disable=unused-argument
"""
...
...
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