class UpdateWithArguments(grok.View): grok.name('update') grok.template('update') def update(self, message, another): self.message = message self.another = another
class SimpleUserSearch(grok.View): """ Simplified search results which searches on the Canonical Name, User Id and Email fields """ grok.context(LDAPApp) grok.name('simpleusersearch') grok.template('searchusers') grok.require(u'gum.View') def results(self): search_term = ldap.filter.escape_filter_chars( self.request.form.get('search_term')) if not search_term: return [] users = self.context['users'] results = {} # search the Canonical Name (cn) for user in users.search('cn', search_term, False): results[user.__name__] = user # search the User Id (uid) for user in users.search('uid', search_term, False): results[user.__name__] = user # search the Email (email) for user in users.search('mail', search_term, False): results[user.__name__] = user return results.values()
class NavigationItem(grok.Viewlet): grok.viewletmanager(Navigation) grok.require('builder.Authenticated') grok.template('navigationitem') grok.baseclass() title = u'Undefined Title' link = '#'
class OSDDEdition(grok.View): grok.context(asm.cms.interfaces.IEdition) grok.name("osdd.xml") grok.template("osdd") def title(self): return self.context.title
class Index(grok.View): grok.require('zope.Public') grok.template("template") def update(self): bootstrap.need() resource.style.need()
class OSDDCMS(grok.View): grok.context(asm.cms.interfaces.ICMS) grok.name("osdd.xml") grok.template("osdd") def title(self): edition = asm.cms.edition.select_edition(self.context, self.request) return edition.title + u" CMS"
class ViewLayout(mars.template.LayoutFactory): grok.template('templates/complex.pt') # required grok.context(MammothView) # define the adapted view grok.name('complex') # view must use named adapter lookup grok.provides(IMyPageTemplate) # view must use this interface to lookup mars.template.macro('body') # define the macro to use mars.template.content_type('text/html') # define the contentType grok.layer(DirLayer) # registered on this layer.
class EmpleadoIndex(grok.View): grok.template('template') grok.require('ct.empleado') grok.name('index') def update(self): bootstrap.need() resource.style.need()
class AddSeccionView(grok.View): grok.context(ContenedorSecciones) grok.name('agregar') grok.require('ct.admin') grok.template('template') def update(self): bootstrap.need() resource.style.need()
class YearIndex(grok.Viewlet): grok.context(Year) grok.template('dateindex') grok.viewletmanager(Main) def entries(self): from_ = datetime(self.context.year, 1, 1) until = datetime(self.context.year + 1, 1, 1) return entriesInDateRange(from_, until)
class EditarUsuarioView(grok.View): grok.context(Usuarios) grok.name('editar') grok.require('ct.admin') grok.template('template') def update(self): bootstrap.need() resource.style.need()
class Login(grok.View): grok.context(Interface) grok.name('login') grok.require('zope.Public') grok.template('template') def update(self): bootstrap.need() resource.style.need() self.site = grok.getApplication()
class DayIndex(grok.View): grok.name('index') grok.context(Day) grok.template('dateindex') def entries(self): from_ = datetime(self.context.year, self.context.month, self.context.day) until = from_ + timedelta(days=1) return entriesInDateRange(from_, until)
class UsuariosIndex(grok.View): grok.context(Usuarios) grok.require('ct.admin') grok.template('template') grok.name('index') def update(self): plugin_auth = component.getUtility(IAuthenticatorPlugin, 'autenticacion') bootstrap.need() resource.style.need() self.usuarios = plugin_auth.listarUsuarios()
class ContenedorSeccionesIndex(grok.View): grok.context(ContenedorSecciones) grok.require('ct.admin') grok.template('template') grok.name('index') def update(self, seccion=None): bootstrap.need() resource.style.need() if not seccion: return self.context.borrar_seccion(seccion)
class AutoLoginTemplateFactory(mars.form.WidgetTemplateFactory): """Define a custom template for autologin field. I'm thinking that I could use this field to choose between using cookie (ie lifetime) and session credentials. In the meantime I'm leaving it with lifetime cookie. """ grok.name('input') grok.context(zope.interface.Interface) grok.template('templates/autologin-widget.pt') mars.form.view(Login) mars.form.field(zope.schema.Bool)
class MonthIndex(grok.View): grok.name('index') grok.context(Month) grok.template('dateindex') def entries(self): from_ = datetime(self.context.year, self.context.month, 1) month = self.context.month + 1 year = self.context.year if month > 12: month = 1 year += 1 until = datetime(year, month, 1) return entriesInDateRange(from_, until)
class SubSectionNavigation(SectionNavigation): grok.template("sectionnavigation") def find_subsection(self): section = self.find_section() if section is None: return return self.find_section(root=section) def tree(self): root_edition = self.find_subsection() root = root_edition.page tree = _create_navigation_subtree(self.active, root, NAVTREE_MAX_LEVELS, self.request) return tree['subpages']
class Embedded(grok.Viewlet): grok.layer(ISkin) grok.context(MediaGallery) grok.viewletmanager(EmbeddedPageContent) grok.template('embedded') def domId(self): intids = zope.component.getUtility(zope.intid.IIntIds) return "embedded-%d" % intids.getId(self.context) def items(self): for item in self.context.list_subpages(): edition = select_edition(item, self.request) if isinstance(edition, NullEdition): continue yield edition
class ErrorView(grok.View): ''' An error display which serves as a base for redirect_urls ''' grok.context(component.Interface) grok.require('zope.Public') grok.template('errorview') grok.baseclass() error = None error_description = None error_uri = None def update(self, error=None, error_description=None, error_uri=None): if error is not None: self.error = error self.error_description = error_description self.error_uri = error_uri
class Sum(grok.View): """Simple view for a model""" grok.context(Calculator) # this is actually the default (from module) grok.template('sum') # this is actually the default (from class name) grok.name('sum') # this is actually the default (from class name) grok.require('zope.Public') # this is actually the default def calculateSum(self): """you can pull this in the template through view/calculateSum""" def update(self): """executed before the template is rendered""" self.sum = self.calculateSum() self.sendEmail() def sendEmail(self): """send an email here"""
class Embedded(grok.Viewlet): grok.layer(ISkin) grok.context(asm.cms.news.NewsFolder) grok.viewletmanager(EmbeddedPageContent) grok.template('embedded') def news(self): news = list() for item in self.context.list(): edition = asm.cms.edition.select_edition(item, self.request) if isinstance(edition, asm.cms.edition.NullEdition): continue result = dict(edition=edition, news=asm.cms.news.INewsFields(edition)) news.append(result) news.sort(key=lambda x: x['edition'].created, reverse=True) return news[:5]
class TinyMCELinkBrowser(grok.View): grok.context(asm.cms.interfaces.IPage) grok.name('tinymce-linkbrowser') grok.template('linkbrowser') def pages(self): # Return a set of editions representing the pages for page in self.context.subpages: yield asm.cms.edition.select_edition(page, self.request) def breadcrumbs(self): result = [] current = self.context while True: result.insert( 0, asm.cms.edition.select_edition(current, self.request)) if current is self.application: break current = current.__parent__ return result
class FilesWidget(SchemaFieldWidget): grok.adapts(FilesSchemaField, interfaces.IFormData, Interface) grok.template(str(INPUT)) def prepareContentValue(self, value): if value is NO_VALUE or value is None: return {self.identifier: False} return {self.identifier: True} def update(self): filer_css.need() filer_js.need() #if not self.form.ignoreContent: ## raise NotImplementedError("Files can't be represented.") SchemaFieldWidget.update(self) def getFiles(self): import json content = self.form.getContentData().getContent() if getattr(content, self.component._field.getName(), None): rc = [{ 'url': '%s/++download++%s' % (grok.url(self.request, content), fileobj.filename), 'name': fileobj.filename, 'size': fileobj.size, 'type': fileobj.contentType } for fileobj in self.component._field.get(content)] else: rc = [] print json.dumps(rc) return json.dumps(rc)
class MemberIndexTemplate(mars.template.TemplateFactory): grok.context(MemberIndex) grok.template('templates/member.pt')
class IndexTemplate(mars.template.TemplateFactory): """layout template for `home`""" grok.context(Index) grok.template('templates/contents.pt')
class EmpleadoIndexContenido(grok.Viewlet): grok.template('contenido_empleado') grok.viewletmanager(IContenido) grok.context(Empleado) grok.view(EmpleadoIndex)
class ToolActions(grok.Viewlet): grok.template('actions') grok.viewletmanager(asm.cmsui.base.NavigationToolActions) grok.context(zope.interface.Interface)
class PreviewWindow(grok.View): grok.name('preview-window') grok.template('preview-window')
class IndexTemplate(mars.template.TemplateFactory): grok.context(Index) grok.template('templates/index.pt')
""" This will raise a GrokImportError """ import grok grok.template('invalid')