Ignorar:
Timestamp:
10/06/2012 20:42:30 (9 anos atrás)
Autor:
mazza
Mensagem:

boxes: GridView? iniciada e funcionando com forms das caixas integrados

Arquivo:
1 editado

Legenda:

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

    r6473 r6475  
     1import martian
    12from Products.CMFCore.interfaces import IFolderish
    23from five import grok
     4from five.grok.components import ZopeTwoPageTemplate
    35from persistent.dict import PersistentDict
    46from z3c.form import form, field, datamanager
     
    810from zope.interface import implements
    911from zope.schema.interfaces import IField
    10 from zope.interface import Interface
     12
     13from interfaces import ISimpleBox, template_dict
     14
    1115
    1216class PersistentDictionaryField(datamanager.DictionaryField):
     
    5155
    5256    def html(self, context, number):
    53         return self._schema_template() % self.box_content(context, number)
     57        return self._schema_template() % NiceDictGetter(
     58            self.box_content(context, number))
    5459
    5560    def _box_key(self, number):
     
    6267        return template_dict[self.schema]
    6368
    64 template_dict = {}
    65 def template(t):
    66     def f(cls):
    67         template_dict[cls] = t
    68         return cls
    69     return f
    70 
    7169def get_or_create_persistent_dict(dictionary, key):
    7270    value = dictionary.get(key, None)
     
    7472        dictionary[key] = value = PersistentDict()
    7573    return value
     74
     75class NiceDictGetter(object):
     76    """Dictionary getter with a default empty string for unknown keys.
     77    """
     78    def __init__(self, wrapped):
     79        self.wrapped = wrapped
     80
     81    def __getitem__(self, key):
     82        value = self.wrapped.get(key, None)
     83        return (value is None) and '---' or value
    7684
    7785# ROWS
     
    94102
    95103def row_html(context, row_spec):
     104    """Renders the html of one row.
     105    `row_spec` is a sequence of cell specs: [(width, schema, number), ...]
     106    """
    96107    return ROW_TEMPLATE % ''.join(
    97108        [CELL_TEMPLATE % cell for cell in row_spec_to_cells(context, row_spec)])
    98109
     110class GridView(grok.View):
     111    "Base class for all grid-like views"
     112    martian.baseclass()
    99113
     114    template = ZopeTwoPageTemplate(filename="gridview.pt")
     115
     116    def rows(self):
     117        for row_spec in self.grid:
     118            yield row_html(self.context, row_spec)
     119
     120################################################################
     121# TODO: o unico lugar em que isto funcionou foi aqui. Entender porque e decidir lugar definitivo.
     122
     123# initialize all the box managers
     124for s in [ISimpleBox,]:
     125    BoxManager(s).build_n_forms(10)
     126
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.