| author | gibus |
| Fri, 19 Nov 2010 18:02:33 +0100 | |
| changeset 335 | 74dbc5568bbd |
| parent 328 | 2a6033ca510e |
| child 336 | f7fb42d3f526 |
| permissions | -rw-r--r-- |
|
287
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
1 |
from piston.handler import AnonymousBaseHandler, BaseHandler |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
2 |
from piston.utils import rc |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
3 |
|
| 293 | 4 |
from cm.models import Text,TextVersion, Role, UserRole, Comment |
|
287
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
5 |
from cm.views import get_keys_from_dict, get_textversion_by_keys_or_404, get_text_by_keys_or_404, get_textversion_by_keys_or_404, redirect |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
6 |
from cm.security import get_texts_with_perm, has_perm, get_viewable_comments, \ |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
7 |
has_perm_on_text_api |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
8 |
from cm.security import get_viewable_comments |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
9 |
from cm.utils.embed import embed_html |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
10 |
from cm.views.create import CreateTextContentForm, create_text |
| 288 | 11 |
from cm.views.texts import client_exchange, text_view_frame, text_view_comments, text_export |
12 |
from cm.views.feeds import text_feed |
|
|
287
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
13 |
from piston.utils import validate |
| 297 | 14 |
from django.conf import settings |
| 328 | 15 |
from django.db.models import F |
|
287
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
16 |
|
| 297 | 17 |
URL_PREFIX = settings.SITE_URL + '/api' |
|
287
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
18 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
19 |
class AnonymousTextHandler(AnonymousBaseHandler): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
20 |
type = "Text methods" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
21 |
title = "Read text info" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
22 |
fields = ('key', 'title', 'format', 'content', 'created', 'modified', 'nb_comments', 'nb_versions', 'embed_html', ('last_text_version', ('created','modified', 'format', 'title', 'content'))) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
23 |
allowed_methods = ('GET', ) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
24 |
model = Text |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
25 |
desc = """ Read text identified by `key`.""" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
26 |
args = None |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
27 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
28 |
@staticmethod |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
29 |
def endpoint(): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
30 |
return URL_PREFIX + '/text/{key}/' |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
31 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
32 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
33 |
@has_perm_on_text_api('can_view_text') |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
34 |
def read(self, request, key): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
35 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
36 |
text = get_text_by_keys_or_404(key) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
37 |
setattr(text,'nb_comments',len(get_viewable_comments(request, text.last_text_version.comment_set.all(), text))) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
38 |
setattr(text,'nb_versions',text.get_versions_number()) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
39 |
setattr(text,'embed_html',embed_html(text.key)) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
40 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
41 |
return text |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
42 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
43 |
class TextHandler(BaseHandler): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
44 |
type = "Text methods" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
45 |
anonymous = AnonymousTextHandler |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
46 |
allowed_methods = ('GET',) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
47 |
no_display = True |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
48 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
49 |
class AnonymousTextVersionHandler(AnonymousBaseHandler): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
50 |
type = "Text methods" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
51 |
title = "Read text version info" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
52 |
fields = ('key', 'title', 'format', 'content', 'created', 'modified', 'nb_comments',) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
53 |
allowed_methods = ('GET', ) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
54 |
model = Text |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
55 |
desc = """ Read text version identified by `version_key` inside text identified by `key`.""" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
56 |
args = None |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
57 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
58 |
@staticmethod |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
59 |
def endpoint(): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
60 |
return URL_PREFIX + '/text/{key}/{version_key}/' |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
61 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
62 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
63 |
@has_perm_on_text_api('can_view_text') |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
64 |
def read(self, request, key, version_key): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
65 |
text_version = get_textversion_by_keys_or_404(version_key, key=key) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
66 |
setattr(text_version,'nb_comments',len(get_viewable_comments(request, text_version.comment_set.all(), text_version.text))) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
67 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
68 |
return text_version |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
69 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
70 |
class TextVersionHandler(BaseHandler): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
71 |
type = "Text methods" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
72 |
anonymous = AnonymousTextVersionHandler |
| 293 | 73 |
fields = ('key', 'title', 'format', 'content', 'created', 'modified', 'nb_comments',) |
74 |
allowed_methods = ('GET', ) |
|
75 |
model = Text |
|
|
287
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
76 |
no_display = True |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
77 |
|
| 293 | 78 |
@has_perm_on_text_api('can_view_text') |
79 |
def read(self, request, key, version_key): |
|
80 |
text_version = get_textversion_by_keys_or_404(version_key, key=key) |
|
81 |
setattr(text_version,'nb_comments',len(get_viewable_comments(request, text_version.comment_set.all(), text_version.text))) |
|
82 |
||
83 |
return text_version |
|
84 |
||
|
287
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
85 |
class AnonymousTextListHandler(AnonymousBaseHandler): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
86 |
title = "List texts" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
87 |
type = "Text methods" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
88 |
fields = ('key', 'title', 'created', 'modified', 'nb_comments', 'nb_versions',) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
89 |
allowed_methods = ('GET',) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
90 |
model = Text |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
91 |
desc = """Lists texts on workspace.""" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
92 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
93 |
@staticmethod |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
94 |
def endpoint(): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
95 |
return URL_PREFIX + '/text/' |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
96 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
97 |
def read(self, request): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
98 |
order_by = '-id' |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
99 |
texts = get_texts_with_perm(request, 'can_view_text').order_by(order_by) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
100 |
return texts |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
101 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
102 |
class TextListHandler(BaseHandler): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
103 |
title = "Create text" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
104 |
type = "Text methods" |
| 288 | 105 |
allowed_methods = ('GET', 'POST') |
| 293 | 106 |
fields = ('key', 'title', 'created', 'modified', 'nb_comments', 'nb_versions',) |
107 |
model = Text |
|
|
287
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
108 |
anonymous = AnonymousTextListHandler |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
109 |
desc = "Create a text with the provided parameters." |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
110 |
args = """<br/> |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
111 |
`title`: title of the text<br/> |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
112 |
`format`: format content ('markdown', 'html')<br/> |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
113 |
`content`: content (in specified format)<br/> |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
114 |
`anon_role`: role to give to anon users: null, 4: commentator, 5: observer<br/> |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
115 |
""" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
116 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
117 |
@staticmethod |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
118 |
def endpoint(): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
119 |
return URL_PREFIX + '/text/' |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
120 |
|
| 288 | 121 |
def read(self, request): |
122 |
order_by = '-id' |
|
123 |
texts = get_texts_with_perm(request, 'can_view_text').order_by(order_by) |
|
124 |
return texts |
|
125 |
||
|
287
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
126 |
def create(self, request): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
127 |
form = CreateTextContentForm(request.POST) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
128 |
if form.is_valid(): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
129 |
text = create_text(request.user, form.cleaned_data) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
130 |
anon_role = request.POST.get('anon_role', None) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
131 |
if anon_role: |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
132 |
userrole = UserRole.objects.create(user=None, role=Role.objects.get(id=anon_role), text=text) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
133 |
return {'key' : text.key , 'version_key' : text.last_text_version.key, 'created': text.created} |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
134 |
else: |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
135 |
resp = rc.BAD_REQUEST |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
136 |
return resp |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
137 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
138 |
from cm.exception import UnauthorizedException |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
139 |
from cm.views.texts import text_delete |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
140 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
141 |
class TextDeleteHandler(BaseHandler): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
142 |
type = "Text methods" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
143 |
allowed_methods = ('POST', ) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
144 |
title = "Delete text" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
145 |
desc = "Delete the text identified by `key`." |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
146 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
147 |
@staticmethod |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
148 |
def endpoint(): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
149 |
return URL_PREFIX + '/text/{key}/delete/' |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
150 |
|
| 288 | 151 |
def create(self, request, key): |
|
287
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
152 |
""" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
153 |
Delete text identified by `key`. |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
154 |
""" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
155 |
try: |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
156 |
text_delete(request, key=key) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
157 |
except UnauthorizedException: |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
158 |
return rc.FORBIDDEN |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
159 |
except KeyError: |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
160 |
return rc.BAD_REQUEST |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
161 |
return rc.DELETED |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
162 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
163 |
from cm.views.texts import text_pre_edit |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
164 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
165 |
class TextPreEditHandler(BaseHandler): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
166 |
type = "Text methods" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
167 |
allowed_methods = ('POST', ) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
168 |
title = "Ask for edit impact" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
169 |
desc = "Returns the number of impacted comments." |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
170 |
args = """<br /> |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
171 |
`new_format`: new format content ('markdown', 'html')<br /> |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
172 |
`new_content`: new content (in specified format)<br /> |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
173 |
""" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
174 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
175 |
@staticmethod |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
176 |
def endpoint(): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
177 |
return URL_PREFIX + '/text/{key}/pre_edit/' |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
178 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
179 |
def create(self, request, key): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
180 |
return text_pre_edit(request, key=key) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
181 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
182 |
from cm.views.texts import text_edit |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
183 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
184 |
class TextEditHandler(BaseHandler): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
185 |
allowed_methods = ('POST', ) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
186 |
type = "Text methods" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
187 |
title = "Edit text" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
188 |
desc = "Update text identified by `key`." |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
189 |
args = """<br /> |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
190 |
`title`: new title of the text<br /> |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
191 |
`format`: new format content ('markdown', 'html')<br /> |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
192 |
`content`: new content (in specified format)<br /> |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
193 |
`note`: note to add to edit<br /> |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
194 |
`new_version`: boolean: should a new version of the text be created?<br /> |
|
300
7aaf5c0d6af4
doc api: add cancel_modified_scopes as parameter of Edit text
gibus
parents:
299
diff
changeset
|
195 |
`keep_comments`: boolean: should existing comments be kept (if possible)?<br /> |
|
7aaf5c0d6af4
doc api: add cancel_modified_scopes as parameter of Edit text
gibus
parents:
299
diff
changeset
|
196 |
`cancel_modified_scopes`: if set to 1, existing comments without scope in a new version are detached, otherwise they are deleted<br /> |
|
287
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
197 |
""" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
198 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
199 |
@staticmethod |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
200 |
def endpoint(): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
201 |
return URL_PREFIX + '/text/{key}/edit/' |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
202 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
203 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
204 |
def create(self, request, key): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
205 |
res = text_edit(request, key=key) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
206 |
text = get_text_by_keys_or_404(key) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
207 |
text_version = text.last_text_version |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
208 |
return {'version_key' : text_version.key , 'created': text_version.created} |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
209 |
|
| 288 | 210 |
|
211 |
class AnonymousTextFeedHandler(AnonymousBaseHandler): |
|
212 |
allowed_methods = ('GET',) |
|
213 |
type = "Text methods" |
|
214 |
title = "Text feed" |
|
215 |
desc = "Returns text RSS feed." |
|
216 |
args = None |
|
217 |
||
218 |
@staticmethod |
|
219 |
def endpoint(): |
|
220 |
return URL_PREFIX + '/text/{key}/feed/?' |
|
221 |
||
222 |
def read(self, request, key): |
|
223 |
return text_feed(request, key=key) |
|
224 |
||
225 |
class TextFeedHandler(BaseHandler): |
|
226 |
type = "Text methods" |
|
227 |
anonymous = AnonymousTextFeedHandler |
|
228 |
allowed_methods = ('GET',) |
|
| 293 | 229 |
no_display = True |
230 |
||
231 |
def read(self, request, key): |
|
232 |
return text_feed(request, key=key) |
|
233 |
||
234 |
class TextVersionRevertHandler(BaseHandler): |
|
235 |
allowed_methods = ('POST', ) |
|
236 |
type = "Text methods" |
|
237 |
title = "Revert to specific text version" |
|
238 |
desc = "Revert to a text version (i.e. copy this text_version which becomes the last text_version)." |
|
239 |
args = """<br /> |
|
240 |
`key`: text's key<br /> |
|
241 |
`version_key`: key of the version to revert to<br /> |
|
242 |
""" |
|
243 |
||
244 |
@staticmethod |
|
245 |
def endpoint(): |
|
246 |
return URL_PREFIX + '/text/{key}/{version_key}/revert/' |
|
247 |
||
248 |
||
249 |
def create(self, request, key, version_key): |
|
250 |
text_version = get_textversion_by_keys_or_404(version_key, key=key) |
|
251 |
new_text_version = text_version.text.revert_to_version(version_key) |
|
252 |
return {'version_key' : new_text_version.key , 'created': new_text_version.created} |
|
253 |
||
254 |
class TextVersionDeleteHandler(BaseHandler): |
|
255 |
allowed_methods = ('POST', ) |
|
256 |
type = "Text methods" |
|
257 |
title = "Delete a specific text version" |
|
258 |
desc = "Delete a text version." |
|
259 |
args = """<br /> |
|
260 |
`key`: text's key<br /> |
|
261 |
`version_key`: key of the version to delete<br /> |
|
262 |
""" |
|
263 |
||
264 |
@staticmethod |
|
265 |
def endpoint(): |
|
266 |
return URL_PREFIX + '/text/{key}/{version_key}/delete/' |
|
267 |
||
268 |
||
269 |
def create(self, request, key, version_key): |
|
270 |
text_version = get_textversion_by_keys_or_404(version_key, key=key) |
|
271 |
text_version.delete() |
|
272 |
return rc.ALL_OK |
|
273 |
||
| 288 | 274 |
## client methods |
275 |
||
276 |
class AnonymousClientHandler(AnonymousBaseHandler): |
|
277 |
allowed_methods = ('POST',) |
|
278 |
type = "Client methods" |
|
279 |
title = "Handles client methods" |
|
280 |
desc = "Handles client (ajax text view) methods." |
|
281 |
args = """<br /> |
|
282 |
post arguments |
|
283 |
""" |
|
284 |
||
285 |
@staticmethod |
|
286 |
def endpoint(): |
|
287 |
return URL_PREFIX + '/client/' |
|
288 |
||
289 |
def create(self, request): |
|
290 |
return client_exchange(request) |
|
291 |
||
292 |
class ClientHandler(BaseHandler): |
|
293 |
type = "Client methods" |
|
294 |
anonymous = AnonymousClientHandler |
|
295 |
allowed_methods = ('POST',) |
|
296 |
no_display = True |
|
297 |
||
298 |
def create(self, request): |
|
299 |
return client_exchange(request) |
|
300 |
||
301 |
## embed methods |
|
302 |
from django.views.i18n import javascript_catalog |
|
| 293 | 303 |
from cm.urls import js_info_dict |
| 288 | 304 |
|
305 |
class JSI18NHandler(AnonymousBaseHandler): |
|
306 |
allowed_methods = ('GET',) |
|
307 |
type = "Embed methods" |
|
308 |
title = "Get js i18n dicts" |
|
309 |
desc = "" |
|
310 |
args = None |
|
311 |
||
312 |
@staticmethod |
|
313 |
def endpoint(): |
|
314 |
return URL_PREFIX + '/jsi18n/' |
|
315 |
||
316 |
def read(self, request): |
|
| 293 | 317 |
return javascript_catalog(request, **js_info_dict) |
| 288 | 318 |
|
319 |
||
320 |
class AnonymousCommentFrameHandler(AnonymousBaseHandler): |
|
321 |
allowed_methods = ('GET',) |
|
322 |
type = "Embed methods" |
|
323 |
title = "Displays embedable frame" |
|
324 |
desc = "" |
|
325 |
args = None |
|
326 |
||
327 |
@staticmethod |
|
328 |
def endpoint(): |
|
329 |
return URL_PREFIX + '/text/{key}/comments_frame/?prefix=/api' |
|
|
299
34b4038e3069
check with api version of security checking prior to fun call
raph
parents:
297
diff
changeset
|
330 |
|
|
34b4038e3069
check with api version of security checking prior to fun call
raph
parents:
297
diff
changeset
|
331 |
@has_perm_on_text_api('can_view_text') |
| 288 | 332 |
def read(self, request, key): |
333 |
return text_view_frame(request, key=key) |
|
334 |
||
335 |
class CommentFrameHandler(BaseHandler): |
|
336 |
type = "Embed methods" |
|
337 |
anonymous = AnonymousCommentFrameHandler |
|
338 |
allowed_methods = ('GET',) |
|
339 |
no_display = True |
|
340 |
||
|
299
34b4038e3069
check with api version of security checking prior to fun call
raph
parents:
297
diff
changeset
|
341 |
@has_perm_on_text_api('can_view_text') |
| 288 | 342 |
def read(self, request, key): |
343 |
return text_view_frame(request, key=key) |
|
344 |
||
345 |
class AnonymousCommentHandler(AnonymousBaseHandler): |
|
346 |
allowed_methods = ('GET',) |
|
347 |
type = "Embed methods" |
|
348 |
title = "Displays embedable frame" |
|
349 |
no_display = True |
|
350 |
desc = "" |
|
351 |
args = None |
|
352 |
||
353 |
@staticmethod |
|
354 |
def endpoint(): |
|
355 |
return URL_PREFIX + '/text/{key}/comments/{version_key}/?' |
|
356 |
||
|
299
34b4038e3069
check with api version of security checking prior to fun call
raph
parents:
297
diff
changeset
|
357 |
@has_perm_on_text_api('can_view_text') |
| 288 | 358 |
def read(self, request, key, version_key): |
359 |
return text_view_comments(request, key=key, version_key=version_key) |
|
360 |
||
361 |
class CommentHandler(BaseHandler): |
|
362 |
type = "Embed methods" |
|
363 |
anonymous = AnonymousCommentHandler |
|
364 |
allowed_methods = ('GET',) |
|
365 |
no_display = True |
|
366 |
||
|
299
34b4038e3069
check with api version of security checking prior to fun call
raph
parents:
297
diff
changeset
|
367 |
@has_perm_on_text_api('can_view_text') |
| 288 | 368 |
def read(self, request, key, version_key): |
369 |
return text_view_comments(request, key=key, version_key=version_key) |
|
370 |
||
371 |
||
372 |
class AnonymousTextExportHandler(AnonymousBaseHandler): |
|
373 |
allowed_methods = ('POST',) |
|
374 |
type = "Embed methods" |
|
375 |
title = "undocumented" |
|
376 |
no_display = True |
|
377 |
desc = "" |
|
378 |
args = None |
|
379 |
||
380 |
@staticmethod |
|
381 |
def endpoint(): |
|
382 |
return URL_PREFIX + ' undocumented' |
|
383 |
||
|
299
34b4038e3069
check with api version of security checking prior to fun call
raph
parents:
297
diff
changeset
|
384 |
@has_perm_on_text_api('can_view_text') |
| 288 | 385 |
def create(self, request, key, format, download, whichcomments, withcolor): |
386 |
return text_export(request, key, format, download, whichcomments, withcolor, adminkey=None) |
|
387 |
||
388 |
class TextExportHandler(BaseHandler): |
|
389 |
type = "Embed methods" |
|
390 |
anonymous = AnonymousTextExportHandler |
|
391 |
allowed_methods = ('POST',) |
|
392 |
no_display = True |
|
393 |
||
|
299
34b4038e3069
check with api version of security checking prior to fun call
raph
parents:
297
diff
changeset
|
394 |
@has_perm_on_text_api('can_view_text') |
| 288 | 395 |
def create(self, request, key, format, download, whichcomments, withcolor): |
396 |
return text_export(request, key, format, download, whichcomments, withcolor, adminkey=None) |
|
397 |
||
| 293 | 398 |
class AnonymousCommentsHandler(AnonymousBaseHandler): |
399 |
allowed_methods = ('GET',) |
|
400 |
type = "Comment methods" |
|
401 |
fields = ('id_key', 'title', 'format', 'content', 'created', 'name', ('text_version' , ('key', ('text', ('key',))) )) |
|
402 |
model = Comment |
|
403 |
title = "Get comments" |
|
404 |
desc = "Get comments from the workspace, most recent first." |
|
|
287
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
405 |
args = """<br /> |
| 293 | 406 |
`keys`: (optional) comma separated keys : limit comments from these texts only<br /> |
407 |
`name`: (optional) limit comments from this user only |
|
408 |
`limit`: (optional) limit number of comments returned |
|
|
287
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
409 |
""" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
410 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
411 |
@staticmethod |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
412 |
def endpoint(): |
| 293 | 413 |
return URL_PREFIX + '/comments/' |
|
287
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
414 |
|
| 293 | 415 |
def read(self, request): |
416 |
name = request.GET.get('name', None) |
|
417 |
limit = request.GET.get('limit', None) |
|
418 |
keys = request.GET.get('keys', None) |
|
419 |
query = Comment.objects.all() |
|
420 |
if keys: |
|
421 |
query = query.filter(text_version__text__key__in=keys.split(',')) |
|
422 |
if name: |
|
423 |
query = query.filter(name=name) |
|
424 |
query = query.order_by('-created') |
|
425 |
if limit: |
|
426 |
query = query[:int(limit)] |
|
427 |
return query |
|
|
287
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
428 |
|
| 293 | 429 |
class CommentsHandler(BaseHandler): |
430 |
type = "Comment methods" |
|
431 |
anonymous = AnonymousCommentsHandler |
|
432 |
allowed_methods = ('GET',) |
|
433 |
fields = ('id_key', 'title', 'format', 'content', 'created', 'name', ('text_version' , ('key', ('text', ('key',))) )) |
|
434 |
model = Comment |
|
435 |
no_display = True |
|
|
287
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
436 |
|
| 293 | 437 |
def read(self, request): |
438 |
name = request.GET.get('name', None) |
|
439 |
limit = request.GET.get('limit', None) |
|
|
335
74dbc5568bbd
add comment_key optional parameter for /api/comments/ to fetch a single comment
gibus
parents:
328
diff
changeset
|
440 |
comment_key = request.GET.get('comment_key', None) |
| 293 | 441 |
keys = request.GET.get('keys', None) |
442 |
query = Comment.objects.all() |
|
443 |
if keys: |
|
444 |
query = query.filter(text_version__text__key__in=keys.split(',')) |
|
445 |
if name: |
|
446 |
query = query.filter(name=name) |
|
|
335
74dbc5568bbd
add comment_key optional parameter for /api/comments/ to fetch a single comment
gibus
parents:
328
diff
changeset
|
447 |
if comment_key: |
|
74dbc5568bbd
add comment_key optional parameter for /api/comments/ to fetch a single comment
gibus
parents:
328
diff
changeset
|
448 |
query = query.filter(id_key=comment_key) |
| 328 | 449 |
query = query.filter(text_version__text__last_text_version__exact=F('text_version__id')) |
| 293 | 450 |
query = query.order_by('-created') |
451 |
if limit: |
|
452 |
query = query[:int(limit)] |
|
453 |
return query |
|
454 |
||
|
287
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
455 |
from piston.doc import documentation_view |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
456 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
457 |
from piston.handler import handler_tracker |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
458 |
from django.template import RequestContext |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
459 |
from piston.doc import generate_doc |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
460 |
from django.shortcuts import render_to_response |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
461 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
462 |
def documentation(request): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
463 |
""" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
464 |
Generic documentation view. Generates documentation |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
465 |
from the handlers you've defined. |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
466 |
""" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
467 |
docs = [ ] |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
468 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
469 |
for handler in handler_tracker: |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
470 |
doc = generate_doc(handler) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
471 |
setattr(doc,'type', handler.type) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
472 |
docs.append(doc) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
473 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
474 |
def _compare(doc1, doc2): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
475 |
#handlers and their anonymous counterparts are put next to each other. |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
476 |
name1 = doc1.name.replace("Anonymous", "") |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
477 |
name2 = doc2.name.replace("Anonymous", "") |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
478 |
return cmp(name1, name2) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
479 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
480 |
#docs.sort(_compare) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
481 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
482 |
return render_to_response('api_doc.html', |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
483 |
{ 'docs': docs }, RequestContext(request)) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
484 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
485 |
from piston.doc import generate_doc |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
486 |
DocHandler = generate_doc(TextPreEditHandler) |