Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
aa
wiki
Commits
50f4a3d2
Commit
50f4a3d2
authored
Dec 11, 2012
by
Alexandre Leray
Browse files
Modified the api to return html on section edit
parent
0133d237
Changes
1
Hide whitespace changes
Inline
Side-by-side
aawiki/api.py
View file @
50f4a3d2
...
...
@@ -24,6 +24,7 @@ from tastypie.utils import trailing_slash
import
time
from
aawiki.mdx
import
get_markdown
from
aawiki.mdx.mdx_sectionedit
import
(
sectionalize
,
sectionalize_replace
)
from
aawiki.utils
import
convert_line_endings
from
aawiki.settings
import
REPO_PATH
...
...
@@ -36,6 +37,15 @@ except ImportError: import json
REPO
=
Repository
(
REPO_PATH
)
def
add_html_key
(
x
):
if
x
[
"index"
]
==
0
:
md
=
get_markdown
()
else
:
md
=
get_markdown
(
simple
=
True
)
x
[
'html'
]
=
md
.
convert
(
x
[
'content'
])
return
x
class
Section
(
object
):
def
__init__
(
self
,
**
kwargs
):
self
.
__dict__
.
update
(
kwargs
)
...
...
@@ -193,17 +203,19 @@ class PageResource(Resource):
class
SectionResource
(
Resource
):
content
=
fields
.
CharField
(
attribute
=
'content'
)
header
=
fields
.
CharField
(
attribute
=
'header'
,
readonly
=
True
)
body
=
fields
.
CharField
(
attribute
=
'body'
,
readonly
=
True
)
header
=
fields
.
CharField
(
attribute
=
'header'
,
readonly
=
True
,
null
=
True
)
body
=
fields
.
CharField
(
attribute
=
'body'
,
readonly
=
True
,
null
=
True
)
index
=
fields
.
IntegerField
(
attribute
=
'index'
,
readonly
=
True
)
start
=
fields
.
IntegerField
(
attribute
=
'start'
,
readonly
=
True
)
end
=
fields
.
IntegerField
(
attribute
=
'end'
,
readonly
=
True
)
start
=
fields
.
IntegerField
(
attribute
=
'start'
,
readonly
=
True
,
null
=
True
)
end
=
fields
.
IntegerField
(
attribute
=
'end'
,
readonly
=
True
,
null
=
True
)
html
=
fields
.
CharField
(
attribute
=
'html'
,
readonly
=
True
,
null
=
True
)
class
Meta
:
resource_name
=
'section'
object_class
=
Section
authentication
=
Authentication
()
authorization
=
Authorization
()
always_return_data
=
True
def
base_urls
(
self
):
return
[
...
...
@@ -217,6 +229,12 @@ class SectionResource(Resource):
%
(
self
.
_meta
.
resource_name
,
trailing_slash
()),
self
.
wrap_view
(
'dispatch_detail'
),
name
=
"api_dispatch_detail"
),
]
def
hydrate
(
self
,
bundle
):
md
=
get_markdown
(
simple
=
True
)
#import ipdb; ipdb.set_trace()
bundle
.
data
[
'html'
]
=
md
.
convert
(
bundle
.
data
[
'content'
])
return
bundle
def
get_resource_uri
(
self
,
bundle_or_obj
):
kwargs
=
{
'resource_name'
:
self
.
_meta
.
resource_name
,
...
...
@@ -241,7 +259,9 @@ class SectionResource(Resource):
except
KeyError
:
raise
NotFound
(
"Object not found"
)
return
[
Section
(
**
i
)
for
i
in
sectionalize
(
page
.
content
)]
sections
=
map
(
add_html_key
,
sectionalize
(
page
.
content
))
return
[
Section
(
**
i
)
for
i
in
sections
]
def
obj_get
(
self
,
request
=
None
,
**
kwargs
):
hex
=
request
.
GET
.
get
(
'hex'
)
if
request
else
None
...
...
@@ -257,7 +277,7 @@ class SectionResource(Resource):
except
IndexError
:
raise
NotFound
(
"Object not found"
)
return
Section
(
**
section
)
return
Section
(
**
add_html_key
(
section
)
)
def
obj_create
(
self
,
bundle
,
request
=
None
,
**
kwargs
):
raise
NotImplementedError
()
...
...
@@ -283,4 +303,9 @@ class SectionResource(Resource):
page
.
commit
(
message
=
message
,
user
=
user
,
email
=
email
)
if
self
.
Meta
.
always_return_data
:
bundle
.
obj
.
index
=
int
(
kwargs
[
"pk"
])
md
=
get_markdown
(
simple
=
False
)
bundle
.
obj
.
html
=
md
.
convert
(
bundle
.
obj
.
content
)
return
bundle
Write
Preview
Supports
Markdown
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