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
d2be9ee6
Commit
d2be9ee6
authored
Apr 30, 2015
by
cahrens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SearchIndex must know about tags to return them.
parent
4af2c003
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
6 deletions
+15
-6
notesapi/v1/search_indexes.py
+1
-0
notesapi/v1/tests/test_views.py
+12
-6
notesapi/v1/views.py
+2
-0
No files found.
notesapi/v1/search_indexes.py
View file @
d2be9ee6
...
@@ -11,6 +11,7 @@ class NoteIndex(indexes.SearchIndex, indexes.Indexable):
...
@@ -11,6 +11,7 @@ class NoteIndex(indexes.SearchIndex, indexes.Indexable):
ranges
=
indexes
.
CharField
(
model_attr
=
'ranges'
,
indexed
=
False
)
ranges
=
indexes
.
CharField
(
model_attr
=
'ranges'
,
indexed
=
False
)
created
=
indexes
.
DateTimeField
(
model_attr
=
'created'
)
created
=
indexes
.
DateTimeField
(
model_attr
=
'created'
)
updated
=
indexes
.
DateTimeField
(
model_attr
=
'updated'
)
updated
=
indexes
.
DateTimeField
(
model_attr
=
'updated'
)
tags
=
indexes
.
CharField
(
model_attr
=
'tags'
)
def
get_model
(
self
):
def
get_model
(
self
):
return
Note
return
Note
...
...
notesapi/v1/tests/test_views.py
View file @
d2be9ee6
...
@@ -417,8 +417,8 @@ class AnnotationSearchViewTests(BaseAnnotationViewTests):
...
@@ -417,8 +417,8 @@ class AnnotationSearchViewTests(BaseAnnotationViewTests):
"""
"""
Tests for search method.
Tests for search method.
"""
"""
self
.
_create_annotation
(
text
=
u'First one'
)
self
.
_create_annotation
(
text
=
u'First one'
,
tags
=
[]
)
self
.
_create_annotation
(
text
=
u'Second note'
)
self
.
_create_annotation
(
text
=
u'Second note'
,
tags
=
[
u'tag1'
,
u'tag2'
]
)
note
=
self
.
_create_annotation
(
text
=
u'Third note'
)
note
=
self
.
_create_annotation
(
text
=
u'Third note'
)
del
note
[
'created'
]
del
note
[
'created'
]
del
note
[
'updated'
]
del
note
[
'updated'
]
...
@@ -430,10 +430,16 @@ class AnnotationSearchViewTests(BaseAnnotationViewTests):
...
@@ -430,10 +430,16 @@ class AnnotationSearchViewTests(BaseAnnotationViewTests):
self
.
assertEqual
(
last_note
,
note
)
self
.
assertEqual
(
last_note
,
note
)
self
.
assertEqual
(
results
[
'total'
],
3
)
self
.
assertEqual
(
results
[
'total'
],
3
)
results
=
self
.
_get_search_results
(
text
=
"Second"
)
def
search_and_verify
(
searchText
,
expectedText
,
expectedTags
):
self
.
assertEqual
(
results
[
'total'
],
1
)
""" Test the results from a specific text search operation """
self
.
assertEqual
(
len
(
results
[
'rows'
]),
1
)
results
=
self
.
_get_search_results
(
text
=
searchText
)
self
.
assertEqual
(
results
[
'rows'
][
0
][
'text'
],
'Second note'
)
self
.
assertEqual
(
results
[
'total'
],
1
)
self
.
assertEqual
(
len
(
results
[
'rows'
]),
1
)
self
.
assertEqual
(
results
[
'rows'
][
0
][
'text'
],
expectedText
)
self
.
assertEqual
(
results
[
'rows'
][
0
][
'tags'
],
expectedTags
)
search_and_verify
(
"First"
,
"First one"
,
[])
search_and_verify
(
"Second"
,
"Second note"
,
[
"tag1"
,
"tag2"
])
def
test_search_deleted
(
self
):
def
test_search_deleted
(
self
):
"""
"""
...
...
notesapi/v1/views.py
View file @
d2be9ee6
...
@@ -74,6 +74,8 @@ class AnnotationSearchView(APIView):
...
@@ -74,6 +74,8 @@ class AnnotationSearchView(APIView):
for
item
in
query
:
for
item
in
query
:
note_dict
=
item
.
get_stored_fields
()
note_dict
=
item
.
get_stored_fields
()
note_dict
[
'ranges'
]
=
json
.
loads
(
item
.
ranges
)
note_dict
[
'ranges'
]
=
json
.
loads
(
item
.
ranges
)
# If ./manage.py rebuild_index has not been run after tags were added, item.tags will be None.
note_dict
[
'tags'
]
=
json
.
loads
(
item
.
tags
)
if
item
.
tags
else
[]
note_dict
[
'id'
]
=
str
(
item
.
pk
)
note_dict
[
'id'
]
=
str
(
item
.
pk
)
if
item
.
highlighted
:
if
item
.
highlighted
:
note_dict
[
'text'
]
=
item
.
highlighted
[
0
]
note_dict
[
'text'
]
=
item
.
highlighted
[
0
]
...
...
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