288 comments = [] # whichcomments=="none" |
288 comments = [] # whichcomments=="none" |
289 |
289 |
290 if whichcomments == "filtered" or whichcomments == "all": |
290 if whichcomments == "filtered" or whichcomments == "all": |
291 #comments = text_version.comment_set.filter(reply_to__isnull=True)# whichcomments=="all" |
291 #comments = text_version.comment_set.filter(reply_to__isnull=True)# whichcomments=="all" |
292 #comments = get_viewable_comments(request, text_version.comment_set.filter(reply_to__isnull=True), text, order_by=('start_wrapper','start_offset','end_wrapper','end_offset'))# whichcomments=="all" |
292 #comments = get_viewable_comments(request, text_version.comment_set.filter(reply_to__isnull=True), text, order_by=('start_wrapper','start_offset','end_wrapper','end_offset'))# whichcomments=="all" |
293 comments = get_viewable_comments(request, text_version.comment_set.all(), text, order_by=('start_wrapper','start_offset','end_wrapper','end_offset'))# whichcomments=="all" |
293 |
294 |
294 _comments = text_version.comment_set.all() |
295 if whichcomments == "filtered" : |
295 if whichcomments == "filtered" : |
|
296 filteredIds = [] |
296 if request.method == 'POST' : |
297 if request.method == 'POST' : |
297 ll = request.POST.get('filteredIds',[]).split(",") |
298 ll = request.POST.get('filteredIds',[]).split(",") |
298 filteredIds = [ int(l) for l in ll if l] |
299 filteredIds = [ int(l) for l in ll if l] |
299 comments = comments.filter(id__in=filteredIds) # security ! TODO CROSS PERMISSIONS WITH POST CONTENT |
300 _comments = text_version.comment_set.filter(id__in=filteredIds) # security ! TODO CROSS PERMISSIONS WITH POST CONTENT |
300 else : |
301 |
301 comments = [] |
302 comments = get_viewable_comments(request, _comments, text, order_by=('start_wrapper','start_offset','end_wrapper','end_offset'))# whichcomments=="all" |
302 |
303 |
|
304 # decide to use pandoc or not |
|
305 if with_color : |
|
306 use_pandoc = False # pandoc wouldn't preserve comments scope background colors |
|
307 else : |
|
308 if format in ('markdown', 'tex') : |
|
309 use_pandoc = True |
|
310 elif format in ('pdf', 'odt') : |
|
311 use_pandoc = (original_format == "markdown") |
|
312 elif format in ('doc', 'html') : |
|
313 use_pandoc = False |
303 if len(comments) == 0 : #want to bypass html conversion in this case |
314 if len(comments) == 0 : #want to bypass html conversion in this case |
304 return content_export2(request, original_content, text_version.title, original_format, format, False, download_response) |
315 return content_export2(request, original_content, text_version.title, original_format, format, use_pandoc, download_response) |
305 else : # case comments to be added |
316 else : # case comments to be added |
306 #comments = comments.order_by('start_wrapper','start_offset','end_wrapper','end_offset') |
317 #comments = comments.order_by('start_wrapper','start_offset','end_wrapper','end_offset') |
307 html = text_version.get_content() |
318 html = text_version.get_content() |
308 wrapped_text_version, _ , _ = spannify(html) |
319 wrapped_text_version, _ , _ = spannify(html) |
309 with_markers = True |
320 with_markers = True |
310 marked_content = insert_comment_markers(wrapped_text_version, comments, with_markers, with_color) |
321 marked_content = insert_comment_markers(wrapped_text_version, comments, with_markers, with_color) |
311 |
322 |
312 viewable_comments = comments_thread(request, text_version, text) |
323 viewable_comments = comments_thread(request, text_version, text) |
313 # viewable_commentsnoreply = get_viewable_comments(request, commentsnoreply, text, order_by = ('start_wrapper','start_offset','end_wrapper','end_offset')) |
324 # viewable_commentsnoreply = get_viewable_comments(request, commentsnoreply, text, order_by = ('start_wrapper','start_offset','end_wrapper','end_offset')) |
314 # viewable_comments = [] |
325 # viewable_comments = [] |
315 # for cc in viewable_commentsnoreply : |
326 # for cc in viewable_commentsnoreply : |
316 # viewable_comments += list_viewable_comments(request, [cc], text) |
327 # viewable_comments += list_viewable_comments(request, [cc], text) |
317 |
328 |
318 # numerotation{ id --> numbered as a child} |
329 # numerotation{ id --> numbered as a child} |
319 extended_comments = {} |
330 extended_comments = {} |
320 nb_children = {} |
331 nb_children = {} |
321 for cc in viewable_comments : |
332 for cc in viewable_comments : |
330 extended_comments[cc.id] = cc |
341 extended_comments[cc.id] = cc |
331 |
342 |
332 if cc.is_reply() : |
343 if cc.is_reply() : |
333 cc.num = "%s.%s"%(extended_comments[cc.reply_to_id].num, cc.num) |
344 cc.num = "%s.%s"%(extended_comments[cc.reply_to_id].num, cc.num) |
334 |
345 |
335 # viewable_comments += list_viewable_comments(request, viewable_commentsnoreply, text) |
346 # viewable_comments += list_viewable_comments(request, viewable_commentsnoreply, text) |
336 html_comments=render_to_string('site/macros/text_comments.html',{'comments':viewable_comments }, context_instance=RequestContext(request)) |
347 html_comments=render_to_string('site/macros/text_comments.html',{'comments':viewable_comments }, context_instance=RequestContext(request)) |
337 |
348 |
338 content = "%s%s"%(marked_content, html_comments) |
349 content = "%s%s"%(marked_content, html_comments) |
339 content_format = "html" |
350 content_format = "html" |
340 # impossible to satisfy because of color then no colors instead: |
351 # impossible to satisfy because of color then no colors instead: |
341 if with_color and format in ('markdown', 'tex') : #TODO : add S5 |
352 if with_color and format in ('markdown', 'tex') : #TODO : add S5 |
342 with_color = False |
353 with_color = False |
343 |
|
344 # decide to use pandoc or not |
|
345 if with_color : |
|
346 use_pandoc = False # pandoc wouldn't preserve comments scope background colors |
|
347 else : |
|
348 if format in ('markdown', 'tex') : |
|
349 use_pandoc = True |
|
350 elif format in ('pdf', 'odt') : |
|
351 use_pandoc = (original_format == "markdown") |
|
352 elif format in ('doc', 'html') : |
|
353 use_pandoc = False |
|
354 |
354 |
355 return content_export2(request, content, text_version.title, content_format, format, use_pandoc, download_response) |
355 return content_export2(request, content, text_version.title, content_format, format, use_pandoc, download_response) |
356 |
356 |
357 def text_print(request, key, adminkey=None): |
357 def text_print(request, key, adminkey=None): |
358 text, admin = get_text_and_admin(key, adminkey) |
358 text, admin = get_text_and_admin(key, adminkey) |