src/cm/views/export.py
changeset 77 fe91eb717a96
parent 57 b32aa76ee411
child 360 bfaab8740995
equal deleted inserted replaced
76:f35d85b2c760 77:fe91eb717a96
     3 from django.http import HttpResponse, HttpResponseRedirect, Http404
     3 from django.http import HttpResponse, HttpResponseRedirect, Http404
     4 from django.shortcuts import render_to_response
     4 from django.shortcuts import render_to_response
     5 from django.template import RequestContext
     5 from django.template import RequestContext
     6 from django.utils.translation import ugettext as _, ugettext_lazy
     6 from django.utils.translation import ugettext as _, ugettext_lazy
     7 from cm.converters.pandoc_converters import pandoc_convert
     7 from cm.converters.pandoc_converters import pandoc_convert
     8 from cm.converters.oo_converters import convert_html as oo_convert
       
     9 from cm.converters.oo_converters import combine_css_body
       
    10 from cm.models import Text, TextVersion, Attachment, Comment
     8 from cm.models import Text, TextVersion, Attachment, Comment
    11 import mimetypes
     9 import mimetypes
    12 import simplejson
    10 import simplejson
    13 EXPORT2_INFOS = {
    11 EXPORT2_INFOS = {
    14 # key -> { mimetype, extension}
    12 # key -> { mimetype, extension}
    34         if use_pandoc :
    32         if use_pandoc :
    35             export_content = pandoc_convert(content, content_format, format, full=True)
    33             export_content = pandoc_convert(content, content_format, format, full=True)
    36         else :
    34         else :
    37             fix_content = content
    35             fix_content = content
    38             if content_format == 'html':
    36             if content_format == 'html':
       
    37                 from cm.converters.oo_converters import combine_css_body                
    39                 fix_content = combine_css_body(content, '')
    38                 fix_content = combine_css_body(content, '')
       
    39             from cm.converters.oo_converters import convert_html as oo_convert                
    40             export_content = oo_convert(fix_content, format)
    40             export_content = oo_convert(fix_content, format)
    41     
    41     
    42     export_infos = EXPORT2_INFOS[format]
    42     export_infos = EXPORT2_INFOS[format]
    43      
    43      
    44     if download_response:
    44     if download_response:
    56         if use_pandoc :
    56         if use_pandoc :
    57             export_content = pandoc_convert(content, src_format, format, full=True)
    57             export_content = pandoc_convert(content, src_format, format, full=True)
    58         else :
    58         else :
    59             fix_content = content
    59             fix_content = content
    60             if src_format == 'html':
    60             if src_format == 'html':
       
    61                 from cm.converters.oo_converters import combine_css_body                
    61                 fix_content = combine_css_body(content, '')
    62                 fix_content = combine_css_body(content, '')
       
    63             from cm.converters.oo_converters import convert_html as oo_convert                
    62             export_content = oo_convert(fix_content, format)
    64             export_content = oo_convert(fix_content, format)
    63     
    65     
    64     export_infos = EXPORT_INFOS[format]
    66     export_infos = EXPORT_INFOS[format]
    65     format_download = export_infos[0] 
    67     format_download = export_infos[0] 
    66      
    68      
   149         if use_pandoc :
   151         if use_pandoc :
   150             export_content = pandoc_convert(content, src_format, format, full=True)
   152             export_content = pandoc_convert(content, src_format, format, full=True)
   151         else :
   153         else :
   152             fix_content = content
   154             fix_content = content
   153             if src_format == 'html':
   155             if src_format == 'html':
       
   156                 from cm.converters.oo_converters import combine_css_body                
   154                 fix_content = combine_css_body(content, '')
   157                 fix_content = combine_css_body(content, '')
       
   158             from cm.converters.oo_converters import convert_html as oo_convert                
   155             export_content = oo_convert(fix_content, format)
   159             export_content = oo_convert(fix_content, format)
   156     
   160     
   157     export_infos = EXPORT_INFOS[format]
   161     export_infos = EXPORT_INFOS[format]
   158     format_download = export_infos[0] 
   162     format_download = export_infos[0] 
   159      
   163