| author | Simon Descarpentries <sid@sopinspace.com> |
| Tue, 06 May 2014 13:52:01 +0200 | |
| changeset 651 | 9bbc657f6837 |
| parent 463 | 9c7de6dd1723 |
| 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 |
|
|
415
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
4 |
from cm.models import Text,TextVersion, Role, UserRole, Comment, Attachment |
|
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 |
|
463
9c7de6dd1723
Fix import for use with api (with co_ment Drupal module for eg.).
gibus
parents:
415
diff
changeset
|
10 |
from cm.views.create import CreateTextContentForm, create_text, CreateTextImportForm, _text_create_import |
| 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 |
|
415
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
137 |
|
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
138 |
from cm.converters import _convert_from_mimetype |
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
139 |
import os |
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
140 |
from django.core.urlresolvers import reverse |
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
141 |
|
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
142 |
class ConvertHandler(BaseHandler): |
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
143 |
type = "Text methods" |
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
144 |
allowed_methods = ('POST', ) |
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
145 |
title = "Convert a legacy file" |
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
146 |
desc = "Returns the HTLM file." |
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
147 |
args = """<br /> |
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
148 |
`file`: the file in legacy format<br /> |
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
149 |
""" |
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
150 |
|
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
151 |
@staticmethod |
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
152 |
def endpoint(): |
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
153 |
return URL_PREFIX + '/convert/' |
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
154 |
|
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
155 |
def create(self, request): |
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
156 |
mime = request.POST.get('mime', None) |
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
157 |
the_file = request.FILES['file']; |
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
158 |
html, attachs = _convert_from_mimetype(the_file.read(), mime, 'html') |
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
159 |
for attach_file in attachs: |
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
160 |
attach_data = file(attach_file, 'rb').read() |
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
161 |
filename = os.path.basename(attach_file) |
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
162 |
attachment = Attachment.objects.create_attachment(filename=filename, data=attach_data, text_version=None) |
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
163 |
attach_url = reverse('notext-attach', args=[attachment.key]) |
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
164 |
html = html.replace(filename, settings.SITE_URL + attach_url) |
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
165 |
return {'html' : html} |
|
287
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
166 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
167 |
from cm.exception import UnauthorizedException |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
168 |
from cm.views.texts import text_delete |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
169 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
170 |
class TextDeleteHandler(BaseHandler): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
171 |
type = "Text methods" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
172 |
allowed_methods = ('POST', ) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
173 |
title = "Delete text" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
174 |
desc = "Delete the text identified by `key`." |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
175 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
176 |
@staticmethod |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
177 |
def endpoint(): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
178 |
return URL_PREFIX + '/text/{key}/delete/' |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
179 |
|
| 288 | 180 |
def create(self, request, key): |
|
287
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 |
Delete text identified by `key`. |
|
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 |
try: |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
185 |
text_delete(request, key=key) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
186 |
except UnauthorizedException: |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
187 |
return rc.FORBIDDEN |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
188 |
except KeyError: |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
189 |
return rc.BAD_REQUEST |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
190 |
return rc.DELETED |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
191 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
192 |
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
|
193 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
194 |
class TextPreEditHandler(BaseHandler): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
195 |
type = "Text methods" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
196 |
allowed_methods = ('POST', ) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
197 |
title = "Ask for edit impact" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
198 |
desc = "Returns the number of impacted comments." |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
199 |
args = """<br /> |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
200 |
`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
|
201 |
`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
|
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 |
@staticmethod |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
205 |
def endpoint(): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
206 |
return URL_PREFIX + '/text/{key}/pre_edit/' |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
207 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
208 |
def create(self, request, key): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
209 |
return text_pre_edit(request, key=key) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
210 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
211 |
from cm.views.texts import text_edit |
|
463
9c7de6dd1723
Fix import for use with api (with co_ment Drupal module for eg.).
gibus
parents:
415
diff
changeset
|
212 |
|
|
287
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
213 |
class TextEditHandler(BaseHandler): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
214 |
allowed_methods = ('POST', ) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
215 |
type = "Text methods" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
216 |
title = "Edit text" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
217 |
desc = "Update text identified by `key`." |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
218 |
args = """<br /> |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
219 |
`title`: new title of the text<br /> |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
220 |
`format`: new format content ('markdown', 'html')<br /> |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
221 |
`content`: new content (in specified format)<br /> |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
222 |
`note`: note to add to edit<br /> |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
223 |
`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
|
224 |
`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
|
225 |
`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
|
226 |
""" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
227 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
228 |
@staticmethod |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
229 |
def endpoint(): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
230 |
return URL_PREFIX + '/text/{key}/edit/' |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
231 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
232 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
233 |
def create(self, request, key): |
|
415
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
234 |
prev_text = get_text_by_keys_or_404(key) |
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
235 |
prev_text_version = prev_text.last_text_version |
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
236 |
prev_comments = prev_text_version.get_comments() |
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
237 |
prev_scope_removed = [c for c in prev_comments if c.is_scope_removed()] |
|
287
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
238 |
res = text_edit(request, key=key) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
239 |
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
|
240 |
text_version = text.last_text_version |
|
415
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
241 |
comments = text_version.get_comments() |
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
242 |
scope_removed = [c for c in comments if c.is_scope_removed()] |
|
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
243 |
return {'version_key' : text_version.key , 'created': text_version.created, 'nb_deleted' : len(prev_comments) - len(comments), 'nb_scope_removed' : len(scope_removed) - len(prev_scope_removed)} |
|
287
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
244 |
|
| 288 | 245 |
|
246 |
class AnonymousTextFeedHandler(AnonymousBaseHandler): |
|
247 |
allowed_methods = ('GET',) |
|
248 |
type = "Text methods" |
|
249 |
title = "Text feed" |
|
250 |
desc = "Returns text RSS feed." |
|
251 |
args = None |
|
252 |
||
253 |
@staticmethod |
|
254 |
def endpoint(): |
|
255 |
return URL_PREFIX + '/text/{key}/feed/?' |
|
256 |
||
257 |
def read(self, request, key): |
|
258 |
return text_feed(request, key=key) |
|
259 |
||
260 |
class TextFeedHandler(BaseHandler): |
|
261 |
type = "Text methods" |
|
262 |
anonymous = AnonymousTextFeedHandler |
|
263 |
allowed_methods = ('GET',) |
|
| 293 | 264 |
no_display = True |
265 |
||
266 |
def read(self, request, key): |
|
267 |
return text_feed(request, key=key) |
|
268 |
||
269 |
class TextVersionRevertHandler(BaseHandler): |
|
270 |
allowed_methods = ('POST', ) |
|
271 |
type = "Text methods" |
|
272 |
title = "Revert to specific text version" |
|
273 |
desc = "Revert to a text version (i.e. copy this text_version which becomes the last text_version)." |
|
274 |
args = """<br /> |
|
275 |
`key`: text's key<br /> |
|
276 |
`version_key`: key of the version to revert to<br /> |
|
277 |
""" |
|
278 |
||
279 |
@staticmethod |
|
280 |
def endpoint(): |
|
281 |
return URL_PREFIX + '/text/{key}/{version_key}/revert/' |
|
282 |
||
283 |
||
284 |
def create(self, request, key, version_key): |
|
285 |
text_version = get_textversion_by_keys_or_404(version_key, key=key) |
|
286 |
new_text_version = text_version.text.revert_to_version(version_key) |
|
287 |
return {'version_key' : new_text_version.key , 'created': new_text_version.created} |
|
288 |
||
289 |
class TextVersionDeleteHandler(BaseHandler): |
|
290 |
allowed_methods = ('POST', ) |
|
291 |
type = "Text methods" |
|
292 |
title = "Delete a specific text version" |
|
293 |
desc = "Delete a text version." |
|
294 |
args = """<br /> |
|
295 |
`key`: text's key<br /> |
|
296 |
`version_key`: key of the version to delete<br /> |
|
297 |
""" |
|
298 |
||
299 |
@staticmethod |
|
300 |
def endpoint(): |
|
301 |
return URL_PREFIX + '/text/{key}/{version_key}/delete/' |
|
302 |
||
303 |
||
304 |
def create(self, request, key, version_key): |
|
305 |
text_version = get_textversion_by_keys_or_404(version_key, key=key) |
|
306 |
text_version.delete() |
|
307 |
return rc.ALL_OK |
|
308 |
||
| 288 | 309 |
## client methods |
310 |
||
311 |
class AnonymousClientHandler(AnonymousBaseHandler): |
|
312 |
allowed_methods = ('POST',) |
|
313 |
type = "Client methods" |
|
314 |
title = "Handles client methods" |
|
315 |
desc = "Handles client (ajax text view) methods." |
|
316 |
args = """<br /> |
|
317 |
post arguments |
|
318 |
""" |
|
319 |
||
320 |
@staticmethod |
|
321 |
def endpoint(): |
|
322 |
return URL_PREFIX + '/client/' |
|
323 |
||
324 |
def create(self, request): |
|
325 |
return client_exchange(request) |
|
326 |
||
327 |
class ClientHandler(BaseHandler): |
|
328 |
type = "Client methods" |
|
329 |
anonymous = AnonymousClientHandler |
|
330 |
allowed_methods = ('POST',) |
|
331 |
no_display = True |
|
332 |
||
333 |
def create(self, request): |
|
334 |
return client_exchange(request) |
|
335 |
||
336 |
## embed methods |
|
337 |
from django.views.i18n import javascript_catalog |
|
| 293 | 338 |
from cm.urls import js_info_dict |
| 288 | 339 |
|
340 |
class JSI18NHandler(AnonymousBaseHandler): |
|
341 |
allowed_methods = ('GET',) |
|
342 |
type = "Embed methods" |
|
343 |
title = "Get js i18n dicts" |
|
344 |
desc = "" |
|
345 |
args = None |
|
346 |
||
347 |
@staticmethod |
|
348 |
def endpoint(): |
|
349 |
return URL_PREFIX + '/jsi18n/' |
|
350 |
||
351 |
def read(self, request): |
|
| 293 | 352 |
return javascript_catalog(request, **js_info_dict) |
| 288 | 353 |
|
354 |
||
355 |
class AnonymousCommentFrameHandler(AnonymousBaseHandler): |
|
356 |
allowed_methods = ('GET',) |
|
357 |
type = "Embed methods" |
|
358 |
title = "Displays embedable frame" |
|
359 |
desc = "" |
|
360 |
args = None |
|
361 |
||
362 |
@staticmethod |
|
363 |
def endpoint(): |
|
364 |
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
|
365 |
|
|
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): |
368 |
return text_view_frame(request, key=key) |
|
369 |
||
370 |
class CommentFrameHandler(BaseHandler): |
|
371 |
type = "Embed methods" |
|
372 |
anonymous = AnonymousCommentFrameHandler |
|
373 |
allowed_methods = ('GET',) |
|
374 |
no_display = True |
|
375 |
||
|
299
34b4038e3069
check with api version of security checking prior to fun call
raph
parents:
297
diff
changeset
|
376 |
@has_perm_on_text_api('can_view_text') |
| 288 | 377 |
def read(self, request, key): |
378 |
return text_view_frame(request, key=key) |
|
379 |
||
380 |
class AnonymousCommentHandler(AnonymousBaseHandler): |
|
381 |
allowed_methods = ('GET',) |
|
382 |
type = "Embed methods" |
|
383 |
title = "Displays embedable frame" |
|
384 |
no_display = True |
|
385 |
desc = "" |
|
386 |
args = None |
|
387 |
||
388 |
@staticmethod |
|
389 |
def endpoint(): |
|
390 |
return URL_PREFIX + '/text/{key}/comments/{version_key}/?' |
|
391 |
||
|
299
34b4038e3069
check with api version of security checking prior to fun call
raph
parents:
297
diff
changeset
|
392 |
@has_perm_on_text_api('can_view_text') |
| 288 | 393 |
def read(self, request, key, version_key): |
394 |
return text_view_comments(request, key=key, version_key=version_key) |
|
395 |
||
396 |
class CommentHandler(BaseHandler): |
|
397 |
type = "Embed methods" |
|
398 |
anonymous = AnonymousCommentHandler |
|
399 |
allowed_methods = ('GET',) |
|
400 |
no_display = True |
|
401 |
||
|
299
34b4038e3069
check with api version of security checking prior to fun call
raph
parents:
297
diff
changeset
|
402 |
@has_perm_on_text_api('can_view_text') |
| 288 | 403 |
def read(self, request, key, version_key): |
404 |
return text_view_comments(request, key=key, version_key=version_key) |
|
405 |
||
406 |
||
407 |
class AnonymousTextExportHandler(AnonymousBaseHandler): |
|
408 |
allowed_methods = ('POST',) |
|
409 |
type = "Embed methods" |
|
410 |
title = "undocumented" |
|
411 |
no_display = True |
|
412 |
desc = "" |
|
413 |
args = None |
|
414 |
||
415 |
@staticmethod |
|
416 |
def endpoint(): |
|
417 |
return URL_PREFIX + ' undocumented' |
|
418 |
||
|
299
34b4038e3069
check with api version of security checking prior to fun call
raph
parents:
297
diff
changeset
|
419 |
@has_perm_on_text_api('can_view_text') |
| 288 | 420 |
def create(self, request, key, format, download, whichcomments, withcolor): |
421 |
return text_export(request, key, format, download, whichcomments, withcolor, adminkey=None) |
|
422 |
||
423 |
class TextExportHandler(BaseHandler): |
|
424 |
type = "Embed methods" |
|
425 |
anonymous = AnonymousTextExportHandler |
|
426 |
allowed_methods = ('POST',) |
|
427 |
no_display = True |
|
428 |
||
|
299
34b4038e3069
check with api version of security checking prior to fun call
raph
parents:
297
diff
changeset
|
429 |
@has_perm_on_text_api('can_view_text') |
| 288 | 430 |
def create(self, request, key, format, download, whichcomments, withcolor): |
431 |
return text_export(request, key, format, download, whichcomments, withcolor, adminkey=None) |
|
432 |
||
|
463
9c7de6dd1723
Fix import for use with api (with co_ment Drupal module for eg.).
gibus
parents:
415
diff
changeset
|
433 |
class ImportHandler(BaseHandler): |
|
9c7de6dd1723
Fix import for use with api (with co_ment Drupal module for eg.).
gibus
parents:
415
diff
changeset
|
434 |
allowed_methods = ('POST', ) |
|
9c7de6dd1723
Fix import for use with api (with co_ment Drupal module for eg.).
gibus
parents:
415
diff
changeset
|
435 |
type = "Text methods" |
|
9c7de6dd1723
Fix import for use with api (with co_ment Drupal module for eg.).
gibus
parents:
415
diff
changeset
|
436 |
title = "Import text and comments" |
|
9c7de6dd1723
Fix import for use with api (with co_ment Drupal module for eg.).
gibus
parents:
415
diff
changeset
|
437 |
desc = "Import a previously exported text, along with comments and attachments in XML format." |
|
9c7de6dd1723
Fix import for use with api (with co_ment Drupal module for eg.).
gibus
parents:
415
diff
changeset
|
438 |
args = """<br /> |
|
9c7de6dd1723
Fix import for use with api (with co_ment Drupal module for eg.).
gibus
parents:
415
diff
changeset
|
439 |
`xml`: Previously exported XML file of text, comments and attachments<br /> |
|
9c7de6dd1723
Fix import for use with api (with co_ment Drupal module for eg.).
gibus
parents:
415
diff
changeset
|
440 |
""" |
|
9c7de6dd1723
Fix import for use with api (with co_ment Drupal module for eg.).
gibus
parents:
415
diff
changeset
|
441 |
|
|
9c7de6dd1723
Fix import for use with api (with co_ment Drupal module for eg.).
gibus
parents:
415
diff
changeset
|
442 |
@staticmethod |
|
9c7de6dd1723
Fix import for use with api (with co_ment Drupal module for eg.).
gibus
parents:
415
diff
changeset
|
443 |
def endpoint(): |
|
9c7de6dd1723
Fix import for use with api (with co_ment Drupal module for eg.).
gibus
parents:
415
diff
changeset
|
444 |
return URL_PREFIX + '/import/' |
|
9c7de6dd1723
Fix import for use with api (with co_ment Drupal module for eg.).
gibus
parents:
415
diff
changeset
|
445 |
|
|
9c7de6dd1723
Fix import for use with api (with co_ment Drupal module for eg.).
gibus
parents:
415
diff
changeset
|
446 |
|
|
9c7de6dd1723
Fix import for use with api (with co_ment Drupal module for eg.).
gibus
parents:
415
diff
changeset
|
447 |
def create(self, request): |
|
9c7de6dd1723
Fix import for use with api (with co_ment Drupal module for eg.).
gibus
parents:
415
diff
changeset
|
448 |
text, res = _text_create_import(request, CreateTextImportForm) |
|
9c7de6dd1723
Fix import for use with api (with co_ment Drupal module for eg.).
gibus
parents:
415
diff
changeset
|
449 |
text_version = text.last_text_version |
|
9c7de6dd1723
Fix import for use with api (with co_ment Drupal module for eg.).
gibus
parents:
415
diff
changeset
|
450 |
return {'key' : text.key , 'version_key' : text.last_text_version.key, 'html': text_version.content} |
|
9c7de6dd1723
Fix import for use with api (with co_ment Drupal module for eg.).
gibus
parents:
415
diff
changeset
|
451 |
|
| 293 | 452 |
class AnonymousCommentsHandler(AnonymousBaseHandler): |
453 |
allowed_methods = ('GET',) |
|
454 |
type = "Comment methods" |
|
455 |
fields = ('id_key', 'title', 'format', 'content', 'created', 'name', ('text_version' , ('key', ('text', ('key',))) )) |
|
456 |
model = Comment |
|
457 |
title = "Get comments" |
|
458 |
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
|
459 |
args = """<br /> |
| 293 | 460 |
`keys`: (optional) comma separated keys : limit comments from these texts only<br /> |
| 336 | 461 |
`comment_key`: (optional) get only this comment |
| 293 | 462 |
`name`: (optional) limit comments from this user only |
463 |
`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
|
464 |
""" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
465 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
466 |
@staticmethod |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
467 |
def endpoint(): |
| 293 | 468 |
return URL_PREFIX + '/comments/' |
|
287
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
469 |
|
| 293 | 470 |
def read(self, request): |
471 |
name = request.GET.get('name', None) |
|
472 |
limit = request.GET.get('limit', None) |
|
473 |
keys = request.GET.get('keys', None) |
|
474 |
query = Comment.objects.all() |
|
475 |
if keys: |
|
476 |
query = query.filter(text_version__text__key__in=keys.split(',')) |
|
477 |
if name: |
|
478 |
query = query.filter(name=name) |
|
479 |
query = query.order_by('-created') |
|
480 |
if limit: |
|
481 |
query = query[:int(limit)] |
|
482 |
return query |
|
|
287
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
483 |
|
| 293 | 484 |
class CommentsHandler(BaseHandler): |
485 |
type = "Comment methods" |
|
486 |
anonymous = AnonymousCommentsHandler |
|
487 |
allowed_methods = ('GET',) |
|
488 |
fields = ('id_key', 'title', 'format', 'content', 'created', 'name', ('text_version' , ('key', ('text', ('key',))) )) |
|
489 |
model = Comment |
|
490 |
no_display = True |
|
|
287
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
491 |
|
| 293 | 492 |
def read(self, request): |
493 |
name = request.GET.get('name', None) |
|
494 |
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
|
495 |
comment_key = request.GET.get('comment_key', None) |
| 293 | 496 |
keys = request.GET.get('keys', None) |
497 |
query = Comment.objects.all() |
|
498 |
if keys: |
|
499 |
query = query.filter(text_version__text__key__in=keys.split(',')) |
|
500 |
if name: |
|
501 |
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
|
502 |
if comment_key: |
|
74dbc5568bbd
add comment_key optional parameter for /api/comments/ to fetch a single comment
gibus
parents:
328
diff
changeset
|
503 |
query = query.filter(id_key=comment_key) |
| 328 | 504 |
query = query.filter(text_version__text__last_text_version__exact=F('text_version__id')) |
| 293 | 505 |
query = query.order_by('-created') |
506 |
if limit: |
|
507 |
query = query[:int(limit)] |
|
508 |
return query |
|
|
415
bacf162c7b58
Adds api/convert to return HTML document from legacy format + Saves attached images when just converting to HTML, without creating a text + Returns nb of detached and removed commentswhen updating text.
gibus
parents:
336
diff
changeset
|
509 |
|
|
287
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
510 |
from piston.doc import documentation_view |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
511 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
512 |
from piston.handler import handler_tracker |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
513 |
from django.template import RequestContext |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
514 |
from piston.doc import generate_doc |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
515 |
from django.shortcuts import render_to_response |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
516 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
517 |
def documentation(request): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
518 |
""" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
519 |
Generic documentation view. Generates documentation |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
520 |
from the handlers you've defined. |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
521 |
""" |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
522 |
docs = [ ] |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
523 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
524 |
for handler in handler_tracker: |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
525 |
doc = generate_doc(handler) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
526 |
setattr(doc,'type', handler.type) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
527 |
docs.append(doc) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
528 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
529 |
def _compare(doc1, doc2): |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
530 |
#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
|
531 |
name1 = doc1.name.replace("Anonymous", "") |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
532 |
name2 = doc2.name.replace("Anonymous", "") |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
533 |
return cmp(name1, name2) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
534 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
535 |
#docs.sort(_compare) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
536 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
537 |
return render_to_response('api_doc.html', |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
538 |
{ 'docs': docs }, RequestContext(request)) |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
539 |
|
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
540 |
from piston.doc import generate_doc |
|
fc5ed157ebfe
add api: basic auth / unit tests / online doc (based on django-piston)
raph
parents:
diff
changeset
|
541 |
DocHandler = generate_doc(TextPreEditHandler) |