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