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
3f18f96a
Commit
3f18f96a
authored
Dec 22, 2014
by
Oleg Marshev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add model.
parent
5ed1b732
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
0 deletions
+70
-0
notesapi/v1/models.py
+63
-0
notesserver/settings/dev.py
+7
-0
No files found.
notesapi/v1/models.py
0 → 100644
View file @
3f18f96a
from
django.db
import
models
class
Note
(
models
.
Model
):
user_id
=
models
.
CharField
(
max_length
=
255
)
course_id
=
models
.
CharField
(
max_length
=
255
)
usage_id
=
models
.
CharField
(
max_length
=
255
)
text
=
models
.
TextField
(
default
=
""
)
quote
=
models
.
TextField
(
default
=
""
)
range_start
=
models
.
CharField
(
max_length
=
2048
)
range_start_offset
=
models
.
IntegerField
()
range_end
=
models
.
CharField
(
max_length
=
2048
)
range_end_offset
=
models
.
IntegerField
()
created
=
models
.
DateTimeField
(
auto_now_add
=
True
)
updated
=
models
.
DateTimeField
(
auto_now
=
True
)
def
clean
(
self
,
json_body
):
"""
Cleans the note object or raises a ValidationError.
"""
if
json_body
is
None
:
raise
ValidationError
(
'Note must have a body.'
)
self
.
text
=
strip_tags
(
body
.
get
(
'text'
,
''
))
self
.
quote
=
strip_tags
(
body
.
get
(
'quote'
,
''
))
try
:
self
.
course_id
=
body
[
'course_id'
]
self
.
usage_id
=
body
[
'usage_id'
]
self
.
user_id
=
body
[
'user_id'
]
except
KeyError
as
error
:
raise
ValidationError
(
'Note must have a course_id and usage_id and user_id.'
)
body
=
json
.
loads
(
json_body
)
if
not
type
(
body
)
is
dict
:
raise
ValidationError
(
'Note body must be a dictionary.'
)
self
.
range_start
=
ranges
[
0
][
'start'
]
self
.
range_start_offset
=
ranges
[
0
][
'startOffset'
]
self
.
range_end
=
ranges
[
0
][
'end'
]
self
.
range_end_offset
=
ranges
[
0
][
'endOffset'
]
def
as_dict
(
self
):
"""
Returns the note object as a dictionary.
"""
return
{
'id'
:
self
.
pk
,
'user'
:
self
.
user
,
'course_id'
:
self
.
course_id
,
'usage_id'
:
self
.
usage_id
,
'text'
:
self
.
text
,
'quote'
:
self
.
quote
,
'ranges'
:
[{
'start'
:
self
.
range_start
,
'startOffset'
:
self
.
range_start_offset
,
'end'
:
self
.
range_end
,
'endOffset'
:
self
.
range_end_offset
}],
'created'
:
str
(
self
.
created
),
'updated'
:
str
(
self
.
updated
)
}
notesserver/settings/dev.py
View file @
3f18f96a
...
@@ -6,6 +6,13 @@ DEBUG = True
...
@@ -6,6 +6,13 @@ DEBUG = True
ELASTICSEARCH_INDEX
=
'edx-notes-dev'
ELASTICSEARCH_INDEX
=
'edx-notes-dev'
DATABASES
=
{
'default'
:
{
'ENGINE'
:
'django.db.backends.sqlite3'
,
'NAME'
:
'default.db'
,
}
}
###############################################################################
###############################################################################
# Override default annotator-store elasticsearch settings.
# Override default annotator-store elasticsearch settings.
###############################################################################
###############################################################################
...
...
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