class ReviewViewlet(grok.Viewlet): grok.viewletmanager(uvcsite.browser.layout.slots.interfaces.IAboveContent) grok.context(interface.Interface) grok.baseclass() def available(self): if (len(self.values) > 0 and not ICOUser.providedBy(self.request.principal)): return True return False def update(self): self.homefolder = uvcsite.interfaces.IHomeFolder(self.request) @property def values(self): results = [] if self.homefolder: interaction = self.request.interaction for productfolder in self.homefolder.values(): if not productfolder.__name__.startswith('__'): if interaction.checkPermission( 'uvc.ViewContent', productfolder): results = [x for x in productfolder.values() if IWorkflowState(x).getState() == uvcsite.workflow.State.REVIEW] return results def render(self): url = self.view.url(self.homefolder) return ( u"<p class='alert'> Sie haben ({}) " + u"Dokumente in Ihrer <a href='{}/review_list'>ReviewList</a>.</p>" ).format(len(self.values), url)
class AjaxPLZOrt(grok.JSON): grok.context(Interface) grok.baseclass() def show_orte(self, plz=None): orte = [] return {'orte': orte}
class TBSkinViewlet(resourceviewlet.ResourceViewlet): grok.context(Interface) resources = [main_css, main_js] grok.baseclass() def update(self): [x.need() for x in self.resources]
class AdHocDocumentInfo(grok.MultiAdapter): grok.adapts(IPrincipal, IHTTPRequest) grok.implements(IAdHocDocumentInfo) grok.baseclass() def __init__(self, principal, request): self.principal = principal self.request = request def getProductFolder(self): base = grok.getSite()['dokumente'] folder_name = time.strftime('%Y_%m_%d', time.localtime()) if not folder_name in base.keys(): base[folder_name] = AdHocProductFolder() return base[folder_name] def getAddLink(self, id, docart): obj = self.getObject(id) if obj: return grok.url(self.request, obj) datefolder = self.getProductFolder() data = {'form.field.docid': id} addlink = "@@%s" % ( docart.replace(' ', '_')) return grok.url(self.request, datefolder, addlink, data=data) def getObject(self, id): util = getUtility(IAdHocIdReference) return util.queryObject(id)
class ReviewViewlet(grok.Viewlet): grok.viewletmanager(uvcsite.IAboveContent) grok.context(interface.Interface) grok.baseclass() def available(self): if (len(self.values) > 0 and not ICOUser.providedBy(self.request.principal)): return True return False @property def values(self): results = [] homefolder = uvcsite.getHomeFolder(self.request) if homefolder: interaction = self.request.interaction for productfolder in homefolder.values(): if not productfolder.__name__.startswith('__'): if interaction.checkPermission('uvc.ViewContent', productfolder): results = [ x for x in productfolder.values() if IWorkflowState(x).getState() == REVIEW ] return results def render(self): return (u"<p class='alert'> Sie haben (%s) " + u"Dokumente in Ihrer <a href='%s'> ReviewList. </a> </p>") % ( len(self.values), uvcsite.getHomeFolderUrl(self.request, 'review_list'))
class Content(grok.Model): grok.baseclass() state = uvcsite.workflow.State() schema = tuple() def __init__(self, **kwargs): super().__init__() if self.schema: ifields = uvcsite.content.fields.Fields(*self.schema) for key, value in kwargs.items(): ifield = ifields.get(key) if ifield is None: raise AttributeError(f"`{key}` attribute doesn't exist.") field = ifield.bind(self) field.validate(value) field.set(self, value) @property def meta_type(self): return self.__class__.__name__ @property def principal(self): dc = IZopeDublinCore(self) if len(dc.creators) > 0: pid = dc.creators[0] return Principal(pid, pid) return getPrincipal() @property def modtime(self): dc = IZopeDublinCore(self) return dc.modified
class ActionView(grok.View): grok.baseclass() grok.layer(asm.cmsui.interfaces.ICMSSkin) def render(self): self.redirect(self.url(self.context, '@@edit'))
class EditionEditForm(EditForm): grok.baseclass() grok.name('edit') @property def label(self): return u'Edit %s' % self.context.page.type @property def form_fields(self): fields = self.main_fields fields += zope.formlib.form.FormFields( asm.cms.interfaces.IEdition).select('tags') fields['tags'].location = 'Tags' self.group_info['Tags'] = self.context.tags for schema in zope.component.subscribers( (self.context, ), asm.cms.interfaces.IAdditionalSchema): self.group_info[schema.getTaggedValue('label')] = \ schema.queryTaggedValue('description', '') add_fields = list(grok.AutoFields(schema)) for field in add_fields: field.location = schema.getTaggedValue('label') fields += zope.formlib.form.FormFields(*add_fields) return fields
class RetailTraverser(grok.Traverser): """Retail traversers try to map URLs to page *editions* when the URL would normally point to a page. We also hide the editions' real URLs and point them to the pages' URLs. """ grok.baseclass() # This directive is currently ignored due to LP #408819. See workaround # below. grok.layer(asm.cmsui.interfaces.IRetailBaseSkin) def traverse(self, name): if not asm.cmsui.interfaces.IRetailBaseSkin.providedBy(self.request): # Workaround for grok.layer bug return page = self.get_context() subpage = page.get(name) if not asm.cms.interfaces.IPage.providedBy(subpage): return return asm.cms.edition.select_edition(subpage, self.request) def get_context(self): return self.context
class MenuItem(grok.Viewlet): grok.baseclass() grok.context(Interface) title = "" action = "" icon = "" @property def selected(self): request_url = self.request.getURL() normalized_action = self.action if not self.action: return False if self.action.startswith('@@'): normalized_action = self.action[2:] if request_url.endswith('/' + normalized_action): return True if request_url.endswith('/++view++' + normalized_action): return True if request_url.endswith('/@@' + normalized_action): return True if request_url == self.action: return True if request_url.endswith('/@@index'): if request_url[:-8] == self.action: return True return False def render(self): return u""
class AddForm(CMSForm, megrok.pagelet.component.FormPageletMixin, grok.AddForm): grok.baseclass() # Needs to be set by the child class factory = None @grok.action("Add") def createAndAdd(self, **data): obj = self.create(**data) zope.event.notify(zope.lifecycleevent.ObjectCreatedEvent(obj)) self.applyData(obj, **data) self.add(obj) self.redirect(self.url(self.target)) def add(self, obj): name = self.chooseName(obj) self.context[name] = obj def create(self, **data): return self.factory() def chooseName(self, obj): chooser = zope.app.container.interfaces.INameChooser(self.context) return chooser.chooseName('', obj) @property def form_fields(self): return grok.AutoFields(self.factory)
class Menu(collections.abc.Iterable): grok.name('base menu') grok.context(Interface) grok.provides(IMenu) grok.baseclass() def __init__(self, context, request, view): self.context = context self.request = request self.view = view def available(self): return True def __iter__(self): entries = grokcore.component.sort_components(( e for name, e in getAdapters( (self, self.context, self.request, self.view), IMenuEntry))) for e in entries: e.__parent__ = self if zope.security.canAccess(e, 'available') and e.available(): yield e def update(self): self.entries = list(iter(self))
class Form(ApplicationForm, ViewSupportMixin): grok.baseclass() legend = "" @property def id(self): return self.prefix + '-' + self.__class__.__name__.lower()
class ExceptionView(View, zope.errorview.browser.ExceptionView): """Base class for rendering views for uncaught exceptions that occur during the application run-time and are not otherwise rendered. Note that when this class in not subclassed, the default error view from zope.errorview is being rendered. """ grok.baseclass() grok.context(IException) grok.name('index') def update(self): return zope.errorview.browser.ExceptionView.update(self) def render(self): """An error view can either be rendered by an associated template, or it can implement this method to render itself from Python. This is useful if the view's output isn't XML/HTML but something computed in Python (plain text, PDF, etc.) Contrary to regular views, render() does *not* accept any parameters. """ return zope.errorview.browser.ExceptionView.render(self) render.base_method = True
class NavigationItem(grok.Viewlet): grok.viewletmanager(Navigation) grok.require('builder.Authenticated') grok.template('navigationitem') grok.baseclass() title = u'Undefined Title' link = '#'
class UKHBaseAddView(BaseAddView): grok.baseclass() grok.context(Interface) def create(self, data): content = super(UKHBaseAddView, self).create(data) return content
class ExtraViewsViewlet(grok.ViewletManager): grok.order(20) grok.baseclass() grok.view(Interface) grok.name('extra-views') grok.viewletmanager(uvcsite.browser.layout.slots.interfaces.IAboveContent) grok.require("zope.Public") # menu_factory = menus.ExtraViews menu_factory = object() def update(self): super().update() if not len(self.menu.viewlets) or ISimpleForm.providedBy(self.view): self.actions = None else: self.actions = self.compute_actions(self.menu.viewlets) def compute_actions(self, viewlets): for action in viewlets: selected = action.viewName == self.view.__name__ context_url = self.menu.view.url(self.menu.context) url = selected and None or "%s/%s" % (context_url, action.viewName) yield { 'id': action.__name__, 'url': url, 'title': action.title or action.__name__, 'selected': selected, 'class': (selected and 'selected ' + self.menu.menu_class or self.menu.menu_class), }
class AdHocManagement(grok.Adapter): grok.context(IPrincipal) grok.implements(IAdHocManagement) grok.baseclass() def getData(self): return {} def checkRule(self, login): return True def validatePassword(self, given_password, saved_password): if given_password == saved_password: return True return False def getFormulare(self, id=None, type=None): raise NotImplementedError @property def clearname(self): daten = self.getUser() if not daten: return self.context.id username = daten.get('clearname') return username
class Plugin(grok.GlobalUtility): grok.baseclass() grok.provides(IPlugin) title = None description = u"" status = Status(state=flags.States.NOT_INSTALLED) actions = None
class IndexPage(grok.View): grok.name("index") grok.baseclass() grok.context(Interface) grok.require(uvcsite.permissions.View) def render(self): return "Hallo Welt"
class EditFormPage( ViewSupportMixin, LayoutAwareFormPage, grokcore.formlib.EditForm ): """Base edit form. """ grok.baseclass() template = default_form_template
class TabMenu(menu.Tab, grok.ViewletManager): grok.baseclass() template = grok.PageTemplateFile('templates/tab.pt') def render(self): """Return the template with the option 'menus'""" if not self.viewlets: return u'' return self.template.render(self)
class DisplayFormPage( ViewSupportMixin, LayoutAwareFormPage, grokcore.formlib.DisplayForm ): """Base display form. """ grok.baseclass() template = default_display_template
class EndpointsDispatcher(Service): grok.baseclass() endpoints = {} def publishTraverse(self, request, name): endpoint = self.endpoints.get(name, None) if endpoint is not None: return endpoint(self.context)
class FormPage( ViewSupportMixin, LayoutAwareFormPage, grokcore.formlib.Form ): """A form base class. """ grok.baseclass() template = default_form_template
class BasePDF(BaseDataView): grok.baseclass() grok.name('pdf') grok.title('uvcsite.pdf') content_type = "application/pdf" def update(self, filename=None): self.base_file = self.getFile(filename) self.c = canvas.Canvas(self.base_file) self.genpdf() self.c.save()
class MenuRenderer(grok.ContentProvider, collections.abc.Iterable): grok.baseclass() bound_menus = tuple() def __iter__(self): return menus_iterator( self.context, self.request, self.view, *self.bound_menus) def update(self): self.menus = collections.OrderedDict(iter(self))
class ActionItem(ActionItem, grok.Viewlet): """Viewlet which renders as a Action Item """ grok.baseclass() @property def url(self): contextURL = absoluteURL(self.context, self.request) return contextURL + '/' + self.viewURL def render(self): return self.template()
class FormDisplay(uvcsite.Form): grok.context(IAdHocContent) grok.baseclass() grok.name('fd') @property def fields(self): return uvcsite.Fields( *self.context.schema ) #.omit( "title", "docid", "doc_type", "anschreiben") def update(self): ah_css.need()
class FlashMessages(grok.Viewlet): grok.baseclass() grok.order(200) grok.context(Interface) grok.name('uvcsite.messages') grok.viewletmanager(IPageTop) def update(self): received = receive() if received is not None: self.messages = list(received) else: self.messages = []