def viewletManagerDirective( _context, name, permission, for_=Interface, layer=IDefaultBrowserLayer, view=IBrowserView, provides=interfaces.IViewletManager, class_=None, template=None, allowed_interface=None, allowed_attributes=None): # If class is not given we use the basic viewlet manager. if class_ is None: class_ = manager.ViewletManagerBase # Iterate over permissions if allowed_attributes is None: allowed_attributes = ['render', 'update'] if allowed_interface is not None: for interface in allowed_interface: allowed_attributes.extend(interface.names()) # Make sure that the template exists and that all low-level API methods # have the right permission. if template: template = os.path.abspath(str(_context.path(template))) if not os.path.isfile(template): raise ConfigurationError("No such file", template) allowed_attributes.append('__getitem__') # Create a new class based on the template and class. new_class = manager.ViewletManager( name, provides, template=template, bases=(class_, )) else: # Create a new class based on the class. new_class = manager.ViewletManager(name, provides, bases=(class_, )) # Register interfaces _handle_for(_context, for_) zcml.interface(_context, view) # register a viewlet manager _context.action( discriminator = ('viewletManager', for_, layer, view, name), callable = zcml.handler, args = ('registerAdapter', new_class, (for_, layer, view), provides, name, _context.info),) _context.action( discriminator = ('five:protectClass', new_class), callable = protectClass, args = (new_class, permission) ) if allowed_attributes: for attr in allowed_attributes: _context.action( discriminator = ('five:protectName', new_class, attr), callable = protectName, args = (new_class, attr, permission) ) _context.action( discriminator = ('five:initialize:class', new_class), callable = InitializeClass, args = (new_class,) )
(self.context, self.request, self.__parent__, self), IViewlet) viewlets = self.filter(viewlets) viewlets = self.sort(viewlets) self.viewlets_map = dict(viewlets) # Just use the viewlets from now on self.viewlets = [viewlet for name, viewlet in viewlets] # Update all viewlets [viewlet.update() for viewlet in self.viewlets] OrdersAdminManager = viewlet_manager.ViewletManager( "OrdersAdmin", ipgp.IOrdersAdminManager, os.path.join(os.path.dirname(__file__), "templates", "viewlet-manager.pt"), bases=(OrderAdminManagerBase, )) class ManageOrders(BrowserView): # admin the collection of orders _download_content = None def __call__(self): self.manager = OrdersAdminManager(self.context, self.request, self) self.manager.update() if self._download_content is not None: self.request.response.setHeader('Content-Type', self._download_content[0]) self.request.RESPONSE.setHeader(
# return "Same as billing" return { 'bill_first_line': infos.bill_first_line, 'bill_second_line': infos.bill_second_line, 'bill_city': infos.bill_city, 'bill_country': self.vocab_countries.getTerm(infos.bill_country).title, 'bill_state': '', 'bill_postal_code': infos.bill_postal_code, 'vat_number': infos.vat_number } AdminOrderManager = viewlet_manager.ViewletManager( "AdminOrder", IGDWAdminOrderManager, os.path.join(os.path.dirname(__file__), "templates", "viewlet-manager.pt"), bases=(AdminOrderManagerBase, )) class AdminOrder(BrowserView): """ an order view """ def __init__(self, context, request): self.context = context self.request = request def __call__(self): self.manager = AdminOrderManager(self.context, self.request, self) self.manager.update() return super(AdminOrder, self).__call__()
for n, v in viewlets[:]: if IConditionalViewlet.providedBy(v): if not v.condition(): viewlets.remove((n, v)) return viewlets def sort(self, viewlets): """ sort by name """ viewlets.sort(lambda x, y: cmp(int(getattr(x[1], 'weight', 100)), int(getattr(y[1], 'weight', 100)))) return viewlets ShoppingCartManager = manager.ViewletManager( "ShoppingCart", IGetPaidCartViewletManager, GetPaidShoppingCartTemplate, bases=(ViewletManagerShoppingCart, )) ################################# # Shopping Cart Viewlets class LineItemColumn(object): def __init__(self, name): self.name = name def __call__(self, item, formatter): value = getattr(item, self.name, '') if callable(value): return value()