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
145de7e8
Commit
145de7e8
authored
Jan 03, 2013
by
Alexandre Leray
Browse files
Expose annotation attributes in the API
parent
c85015c9
Changes
1
Hide whitespace changes
Inline
Side-by-side
aawiki/api.py
View file @
145de7e8
...
...
@@ -33,9 +33,37 @@ from pygit2 import GIT_OBJ_BLOB, Repository, Signature
try
:
import
simplejson
as
json
except
ImportError
:
import
json
from
markdown.extensions.attr_list
import
get_attrs
from
markdown.extensions.attr_list
import
AttrListTreeprocessor
from
markdown.util
import
etree
REPO
=
Repository
(
REPO_PATH
)
def
assign_attrs
(
elem
,
attrs
):
""" Assign attrs to element. """
for
k
,
v
in
get_attrs
(
attrs
):
if
k
==
'.'
:
# add to class
cls
=
elem
.
get
(
'class'
)
if
cls
:
elem
.
set
(
'class'
,
'%s %s'
%
(
cls
,
v
))
else
:
elem
.
set
(
'class'
,
v
)
else
:
# assing attr k with v
elem
.
set
(
k
,
v
)
def
add_attributes_key
(
x
):
if
not
x
[
"index"
]
==
0
:
RE
=
AttrListTreeprocessor
.
HEADER_RE
m
=
list
(
RE
.
finditer
(
x
[
'header'
].
rstrip
()))
if
m
:
elt
=
etree
.
Element
(
'tmp'
)
assign_attrs
(
elt
,
m
[
-
1
].
group
(
1
))
x
[
'attributes'
]
=
elt
.
attrib
return
x
def
add_html_key
(
x
):
if
x
[
"index"
]
==
0
:
...
...
@@ -209,6 +237,7 @@ class SectionResource(Resource):
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
)
attributes
=
fields
.
DictField
(
attribute
=
'attributes'
,
readonly
=
True
,
null
=
True
)
class
Meta
:
resource_name
=
'section'
...
...
@@ -277,7 +306,7 @@ class SectionResource(Resource):
except
IndexError
:
raise
NotFound
(
"Object not found"
)
return
Section
(
**
add_html_key
(
section
))
return
Section
(
**
add_
attributes_key
(
add_
html_key
(
section
))
)
def
obj_create
(
self
,
bundle
,
request
=
None
,
**
kwargs
):
raise
NotImplementedError
()
...
...
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