def version_export(request, version_id): version = get_object_or_404(TextVersion,pk = version_id) if request.method == 'POST': format = request.POST['format'] from cm.utils.ooconvert import fmts fmt = fmts.get_by_name(format) response = HttpResponse(mimetype=fmt['mimetype']) file_title = version.title + u'.%s' %fmt['extension'] encoded_name = str(Header(file_title.encode('utf8'), charset='utf8', maxlinelen=500)) h = u'attachment; filename=%s' %encoded_name response['Content-Disposition'] = h body = version.content if request.POST['txtOnly'] == '0' : body = export_add_comment(request, version) from cm.utils.ooconvert import convert_html,combine_css_body data = combine_css_body(body,version.css) content = convert_html(data.encode('utf-8'),fmt['name']) response.write(content) #.decode('utf-8') return response return HttpResponse()
def embed(request,text_id,type): if user_has_perm_on_text(None, 'can_view_local_text', text_id): if type=="public_view" : return _viewandcommentversion(request,text_id,embed = True) else :#if type=="public_view_textonly" : text = get_object_or_404(Text,pk = text_id) version = text.get_latest_version() additional_commentsinfo_css = """ .acinfo { padding:5px 10px 5px 10px; color:#222; font:normal 11px tahoma, arial, helvetica, sans-serif; } """ nbcomments,nbreplies = version.get_visible_commentsandreplies_count(request.user) comment_count_msg = _(u'this text has %(nbcomments)d comment(s) and %(nbreplies)d reply(ies)') % {'nbcomments': nbcomments,'nbreplies': nbreplies,} if user_has_perm_on_text(None, 'can_add_comment_local_text', text_id) : click_here_msg = _(u"click here to view or add comments") else : click_here_msg = _(u"click here to view comments") viewandcomment_url = settings.SITE_URL + reverse('text-viewandcomment',args=[text_id]) additional_commentsinfo = u"""<div class="acinfo">co-ment®: %s, <a href="%s" target="blank" >%s</a> </div>""" % (comment_count_msg, viewandcomment_url, click_here_msg) body = "%s%s" % (version.content, additional_commentsinfo) css = "%s%s" % (additional_commentsinfo_css, version.css) content = combine_css_body(body,css) return HttpResponse(content) else: redirect_url = reverse('embeded_unauthorized') return HttpResponseRedirect(redirect_url)
def version_print(request, version_id): version = get_object_or_404(TextVersion,pk = version_id) body = version.content if request.method == 'POST'and request.POST['txtOnly'] == '0' : body = export_add_comment(request, version) body += """<script type="text/javascript">window.print();</script>"""; from cm.utils.ooconvert import combine_css_body content = combine_css_body(body,version.css) return HttpResponse(content)