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
c0691a8c
Commit
c0691a8c
authored
Dec 26, 2014
by
Oleg Marshev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move filtering to clean.
parent
a1fae635
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
31 deletions
+7
-31
notesapi/v1/models.py
+5
-6
notesapi/v1/views.py
+2
-25
No files found.
notesapi/v1/models.py
View file @
c0691a8c
...
...
@@ -25,12 +25,12 @@ class Note(models.Model):
"""
Clean the note object or raises a ValidationError.
"""
if
note
is
None
:
raise
ValidationError
(
'Note must have a body.'
)
if
type
(
note
)
is
not
dict
:
if
not
isinstance
(
note
,
dict
):
raise
ValidationError
(
'Note must be a dictionary.'
)
if
len
(
note
)
==
0
:
raise
ValidationError
(
'Note must have a body.'
)
self
.
text
=
note
.
get
(
'text'
,
''
)
self
.
quote
=
note
.
get
(
'quote'
,
''
)
...
...
@@ -125,4 +125,4 @@ class NoteMappingType(MappingType, Indexable):
data
[
i
][
k
]
=
v
[
0
]
return
data
note_searcher
=
NoteMappingType
.
search
()
\ No newline at end of file
note_searcher
=
NoteMappingType
.
search
()
notesapi/v1/views.py
View file @
c0691a8c
...
...
@@ -10,9 +10,6 @@ from rest_framework.views import APIView
from
notesapi.v1.models
import
Note
,
NoteMappingType
,
note_searcher
CREATE_FILTER_FIELDS
=
(
'updated'
,
'created'
,
'consumer'
,
'id'
)
UPDATE_FILTER_FIELDS
=
(
'updated'
,
'created'
,
'user'
,
'consumer'
)
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -60,15 +57,10 @@ class AnnotationListView(APIView):
if
'id'
in
self
.
request
.
DATA
:
return
Response
(
status
=
status
.
HTTP_400_BAD_REQUEST
)
filtered_payload
=
_filter_input
(
self
.
request
.
DATA
,
CREATE_FILTER_FIELDS
)
if
len
(
filtered_payload
)
==
0
:
return
Response
(
status
=
status
.
HTTP_400_BAD_REQUEST
)
note
=
Note
()
try
:
note
.
clean
(
filtered_payload
)
note
.
clean
(
self
.
request
.
DATA
)
except
ValidationError
as
error
:
log
.
debug
(
error
)
return
Response
(
status
=
status
.
HTTP_400_BAD_REQUEST
)
...
...
@@ -116,13 +108,8 @@ class AnnotationDetailView(APIView):
if
note
.
user_id
!=
self
.
request
.
DATA
[
'user'
]:
return
Response
(
status
=
status
.
HTTP_400_BAD_REQUEST
)
filtered_payload
=
_filter_input
(
self
.
request
.
DATA
,
UPDATE_FILTER_FIELDS
)
# use id from URL, regardless of what arrives in JSON payload.
filtered_payload
[
'id'
]
=
note_id
try
:
note
.
clean
(
filtered_payload
)
note
.
clean
(
self
.
request
.
DATA
)
except
ValidationError
as
e
:
log
.
debug
(
e
)
return
Response
(
status
=
status
.
HTTP_400_BAD_REQUEST
)
...
...
@@ -151,16 +138,6 @@ class AnnotationDetailView(APIView):
return
Response
(
status
=
status
.
HTTP_204_NO_CONTENT
)
def
_filter_input
(
annotation
,
fields
):
"""
Pop given fields from annotation.
"""
for
field
in
fields
:
annotation
.
pop
(
field
,
None
)
return
annotation
def
_convert_to_int
(
value
,
default
=
None
):
"""
Convert given value to int.
...
...
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