Conjunto de mudanças 6510 no repositório publico


Ignorar:
Timestamp:
16/06/2012 19:39:47 (9 anos atrás)
Autor:
mazza
Mensagem:

boxes: DtRow? refatorada p usar um template

Localização:
PortalInterlegis/produtos/il.portalinterlegis/trunk/src/il/portalinterlegis
Arquivos:
1 adicionado
2 editados

Legenda:

Não Modificado
Adicionado
Removido
  • PortalInterlegis/produtos/il.portalinterlegis/trunk/src/il/portalinterlegis/browser/boxes/manager.py

    r6509 r6510  
    2424template_factory = Environment(loader=PackageLoader(__name__))
    2525
    26 class BaseBox(object):
     26class TemplateAware(object):
     27
     28    @property
     29    def template(self):
     30        return template_factory.get_template(self.template_name)
     31
     32
     33class BaseBox(TemplateAware):
    2734    """Base abstract class for editable boxes.
    2835    """
    2936
    30     TEMPLATE_NAME = 'basebox.html'
     37    template_name = 'basebox.html'
    3138
    3239    def __init__(self, permission=ModifyPortalContent):
     
    3441
    3542    def __call__(self, context):
    36         basebox_template = template_factory.get_template(self.TEMPLATE_NAME)
    37         return basebox_template.render(
     43        return self.template.render(
    3844            box = self,
    3945            has_permission = self.has_permission(context),
     
    131137
    132138# ROWS
    133 class DtRow(object):
     139class DtRow(TemplateAware):
    134140
    135     ROW_TEMPLATE = '''
    136   <div class="dt-row">%s
    137   </div>'''
    138 
    139     CELL_TEMPLATE = '''
    140     <div class="dt-cell dt-position-%s dt-width-%s">%s
    141     </div>'''
     141    template_name = 'dtrow.html'
    142142
    143143    def __init__(self, *row_spec):
    144144        try:
    145             for (width, template) in row_spec: pass
     145            for (width, renderable) in row_spec: pass
    146146        except ValueError, e:
    147147            e.args += row_spec
     
    149149        self.row_spec = row_spec
    150150
    151     def _cells(self, context):
    152         """Iterates transforming each cell spec from (width, template) to
    153            (position, width, rendered_html)
     151    def cells(self, context):
     152        """Iterates transforming each cell spec from (width, renderable) to
     153           a dict of {position, width, rendered_html}
    154154        """
    155155        position = 0
    156         for (width, template) in self.row_spec:
    157             yield (position, width, template(context))
     156        for (width, renderable) in self.row_spec:
     157            yield dict(position=position, width=width, html=renderable(context))
    158158            position += width
    159159
     
    162162        `row_spec` is a sequence of cell specs: [(width, schema, number), ...]
    163163        """
    164         return self.ROW_TEMPLATE % ''.join(
    165             [self.CELL_TEMPLATE % cell for cell in self._cells(context)])
     164        return self.template.render(cells = self.cells(context))
    166165
    167166
  • PortalInterlegis/produtos/il.portalinterlegis/trunk/src/il/portalinterlegis/tests/testunitboxes.py

    r6509 r6510  
    8080    </div>
    8181  </div>
    82 ''', DtRow((1, Mock(return_value="\n      AAA")),
    83            (2, Mock(return_value="\n      BBB")),
    84            (3, Mock(return_value="\n      CCC")),
    85            (1, Mock(return_value="\n      DDD"))).render(context))
     82''', DtRow((1, Mock(return_value="AAA")),
     83           (2, Mock(return_value="BBB")),
     84           (3, Mock(return_value="CCC")),
     85           (1, Mock(return_value="DDD"))).render(context))
    8686
    8787
     
    9797        if name == "istubbox.html":
    9898            return Template("{{var}}")
    99         elif name == BaseBox.TEMPLATE_NAME:
    100             return template_factory.get_template(BaseBox.TEMPLATE_NAME)
     99        elif name == "basebox.html":
     100            return template_factory.get_template(name)
    101101        else:
    102             raise AssertionError
    103 
     102            raise AssertionError("Unexpected name: [%s]" % name)
Note: Veja TracChangeset para ajuda no uso do visualizador de conjunto de mudanças.
 

The contents and data of this website are published under license:
Creative Commons 4.0 Brasil - Atribuir Fonte - Compartilhar Igual.