Changeset 13:d57a45e8a7b2

Show
Ignore:
Timestamp:
07/14/08 22:09:55 (5 years ago)
Author:
Nicolas Evrard <nicoe@…>
Branch:
default
Message:

- Created a NullTemplate? object for unavailable templates

  • test for trml2pdf presence (we do not want to depend on this)
  • generate different hashes for images althought the expr is the same
Location:
relatorio
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • relatorio/reporting.py

    r12 r13  
    1919############################################################################### 
    2020 
    21 __revision__ = "$Id: reporting.py 13 2008-07-10 16:41:20Z ged $" 
     21__revision__ = "$Id: reporting.py 14 2008-07-14 22:09:55Z nicoe $" 
    2222__metaclass__ = type 
    2323 
     
    2828from genshi.template import TemplateLoader 
    2929 
     30from templates import NullTemplate 
    3031from templates.odt import Template as OOTemplate 
    31 from templates.pdf import Template as PDFTemplate 
     32 
     33try: 
     34    from templates.pdf import Template as PDFTemplate 
     35except ImportError: 
     36    PDFTemplate = NullTemplate 
     37    warnings.warn("trml2pdf is not installed on your system. You will not " 
     38                  "be able to create PDF files.") 
    3239 
    3340def _absolute(path): 
  • relatorio/templates/__init__.py

    r1 r13  
     1############################################################################### 
     2# 
     3# Copyright (c) 2007, 2008 OpenHex SPRL. (http://openhex.com) All Rights 
     4# Reserved. 
     5# 
     6# This program is free software; you can redistribute it and/or modify it under 
     7# the terms of the GNU General Public License as published by the Free Software 
     8# Foundation; either version 2 of the License, or (at your option) any later 
     9# version. 
     10# 
     11# This program is distributed in the hope that it will be useful, but WITHOUT 
     12# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
     13# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more  
     14# details. 
     15# 
     16# You should have received a copy of the GNU General Public License along with 
     17# this program.  If not, see <http://www.gnu.org/licenses/>. 
     18# 
     19############################################################################### 
     20 
     21__revision__ = "$Id: __init__.py 14 2008-07-14 22:09:55Z nicoe $" 
     22__metaclass__ = type 
     23 
     24from genshi.template import Template as GenshiTemplate, MarkupTemplate 
     25 
     26 
     27class NullTemplate(GenshiTemplate): 
     28 
     29    def __init__(self, source, filepath=None, filename=None, loader=None, 
     30                 encoding=None, lookup='strict', allow_exec=True): 
     31        raise NotImplementedError 
     32 
     33    def _parse(self, source, encoding): 
     34        pass 
     35     
     36    def _prepare(self, stream): 
     37        pass 
     38 
     39    def generate(self, *args, **kwargs): 
     40        pass 
  • relatorio/templates/odt.py

    r8 r13  
    1919############################################################################### 
    2020 
    21 __revision__ = "$Id: odt.py 9 2008-07-08 19:23:12Z nicoe $" 
     21__revision__ = "$Id: odt.py 14 2008-07-14 22:09:55Z nicoe $" 
    2222__metaclass__ = type 
    2323 
     
    4646             } 
    4747 
    48 def _make_href(zip): 
    49     def attr_maker(expr, name): 
     48class ImageHref: 
     49     
     50    def __init__(self, zipfile): 
     51        self.zip = zipfile 
     52        self.count = 0 
     53 
     54    def __call__(self, expr, name): 
    5055        bitstream, mimetype = expr 
    51         name = md5.new(name).hexdigest() 
     56        name = md5.new('%s-%s' % (name, self.count)).hexdigest() 
     57        self.count += 1 
    5258        path = 'Pictures/%s.%s' % (name, EXTENSIONS[mimetype]) 
    5359        bitstream.seek(0) 
    54         zip.writestr(path, bitstream.read()) 
     60        self.zip.writestr(path, bitstream.read()) 
    5561        return {'{%s}href' % NS['xlink']: path} 
    56     return attr_maker 
    5762 
    5863 
     
    178183        outzip = zipfile.ZipFile(new_oo, 'w') 
    179184 
    180         kwargs['make_href'] = _make_href(outzip) 
     185        kwargs['make_href'] = ImageHref(outzip) 
    181186        content = str(self.content_template.generate(*args, **kwargs)) 
    182187