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
2a7ed61e
Commit
2a7ed61e
authored
Dec 24, 2014
by
Oleg Marshev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add course key field.
parent
5f92a534
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
9 deletions
+7
-9
notesapi/v1/models.py
+4
-4
notesapi/v1/tests/test_models.py
+3
-5
No files found.
notesapi/v1/models.py
View file @
2a7ed61e
...
@@ -2,7 +2,7 @@ import json
...
@@ -2,7 +2,7 @@ import json
from
django.db
import
models
from
django.db
import
models
from
django.core.exceptions
import
ValidationError
from
django.core.exceptions
import
ValidationError
from
opaque_keys.edx.keys
import
CourseKey
,
UsageKey
from
opaque_keys.edx.keys
import
CourseKey
,
UsageKey
from
opaque_keys.edx.locations
import
BlockUsageLocator
from
opaque_keys.edx.locations
import
BlockUsageLocator
,
CourseLocator
def
_strip_object
(
key
):
def
_strip_object
(
key
):
...
@@ -116,7 +116,7 @@ class UsageKeyField(OpaqueKeyField):
...
@@ -116,7 +116,7 @@ class UsageKeyField(OpaqueKeyField):
class
Note
(
models
.
Model
):
class
Note
(
models
.
Model
):
user_id
=
models
.
CharField
(
max_length
=
255
)
user_id
=
models
.
CharField
(
max_length
=
255
)
course_id
=
models
.
Char
Field
(
max_length
=
255
)
course_id
=
CourseKey
Field
(
max_length
=
255
)
usage_id
=
UsageKeyField
(
max_length
=
255
)
usage_id
=
UsageKeyField
(
max_length
=
255
)
text
=
models
.
TextField
(
default
=
""
)
text
=
models
.
TextField
(
default
=
""
)
quote
=
models
.
TextField
(
default
=
""
)
quote
=
models
.
TextField
(
default
=
""
)
...
@@ -147,7 +147,7 @@ class Note(models.Model):
...
@@ -147,7 +147,7 @@ class Note(models.Model):
self
.
quote
=
body
.
get
(
'quote'
,
''
)
self
.
quote
=
body
.
get
(
'quote'
,
''
)
try
:
try
:
self
.
course_id
=
body
[
'course_id'
]
self
.
course_id
=
CourseLocator
.
from_string
(
body
[
'course_id'
])
self
.
usage_id
=
BlockUsageLocator
.
from_string
(
body
[
'usage_id'
])
self
.
usage_id
=
BlockUsageLocator
.
from_string
(
body
[
'usage_id'
])
self
.
user_id
=
body
[
'user'
]
self
.
user_id
=
body
[
'user'
]
except
KeyError
as
error
:
except
KeyError
as
error
:
...
@@ -172,7 +172,7 @@ class Note(models.Model):
...
@@ -172,7 +172,7 @@ class Note(models.Model):
return
{
return
{
'id'
:
self
.
pk
,
'id'
:
self
.
pk
,
'user'
:
self
.
user_id
,
'user'
:
self
.
user_id
,
'course_id'
:
self
.
course_id
,
'course_id'
:
self
.
course_id
.
html_id
()
,
'usage_id'
:
self
.
usage_id
.
to_deprecated_string
(),
'usage_id'
:
self
.
usage_id
.
to_deprecated_string
(),
'text'
:
self
.
text
,
'text'
:
self
.
text
,
'quote'
:
self
.
quote
,
'quote'
:
self
.
quote
,
...
...
notesapi/v1/tests/test_models.py
View file @
2a7ed61e
...
@@ -6,13 +6,11 @@ from django.core.exceptions import ValidationError
...
@@ -6,13 +6,11 @@ from django.core.exceptions import ValidationError
class
NoteTest
(
TestCase
):
class
NoteTest
(
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
course_id
=
"test_course_id"
self
.
user_id
=
"test_user_id"
self
.
note
=
{
self
.
note
=
{
"user"
:
u"test_user_id"
,
"user"
:
u"test_user_id"
,
"usage_id"
:
"i4x://org/course/category/name
"
,
"usage_id"
:
u"i4x://org/course/html/52aa9816425a4ce98a07625b8cb70811
"
,
"course_id"
:
u"
test-course-id
"
,
"course_id"
:
u"
org/course/run
"
,
"text"
:
u"test note text"
,
"text"
:
u"test note text"
,
"quote"
:
u"test note quote"
,
"quote"
:
u"test note quote"
,
"ranges"
:
[
"ranges"
:
[
...
@@ -58,7 +56,7 @@ class NoteTest(TestCase):
...
@@ -58,7 +56,7 @@ class NoteTest(TestCase):
note
.
clean
(
json
.
dumps
({
note
.
clean
(
json
.
dumps
({
'text'
:
'foo'
,
'text'
:
'foo'
,
'quote'
:
'bar'
,
'quote'
:
'bar'
,
'ranges'
:
[{}
for
i
in
range
(
10
)]
#
too many ranges
'ranges'
:
[{}
for
i
in
range
(
10
)]
#
Too many ranges.
}))
}))
def
test_save
(
self
):
def
test_save
(
self
):
...
...
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