Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def render(self):
return 'What a beautiful painting.'
class EditCavePainting(grok.View):
grok.context(zope.interface.Interface)
grok.require(EditPermission)
def render(self):
return 'Let\'s make it even prettier.'
class EraseCavePainting(grok.View):
grok.context(zope.interface.Interface)
grok.require(ErasePermission)
def render(self):
return 'Oops, mistake, let\'s erase it.'
class ApproveCavePainting(grok.View):
grok.context(zope.interface.Interface)
grok.require(ApprovePermission)
def render(self):
return 'Painting owners cannot approve their paintings.'
@grok.require(TouchMammoth)
def GET(self):
return self.context.name
import grok
import zope.interface
class PublicView(grok.View):
grok.context(zope.interface.Interface)
grok.require('zope.Public')
def render(self):
return ', '.join(self.request.principal.groups)
class ProtectedView(grok.View):
grok.context(zope.interface.Interface)
grok.require('grok.test')
def render(self):
return ', '.join(self.request.principal.groups)
@grok.require('zope.ManageContent')
def POST(self):
return "POST3"
import grok
import zope.interface
class MammothRPC(grok.XMLRPC):
grok.context(zope.interface.Interface)
def stomp(self):
return 'Manfred stomped.'
@grok.require('zope.ManageContent')
def dance(self):
return 'Manfred doesn\'t like to dance.'
class CavemanRPC(grok.XMLRPC):
grok.context(zope.interface.Interface)
grok.require('zope.ManageContent')
def hunt(self):
return 'ME GROK LIKE MAMMOTH!'
@grok.require('zope.View')
def eat(self):
return 'MMM, MANFRED TASTE GOOD!'
@grok.require(grok.Public)
def rest(self):
return 'ME GROK TIRED!'
And of course you can access the protected view.
>>> browser.open("http://localhost/@@protectedview")
>>> 'zope.Authenticated' in browser.contents
True
"""
import grok
import zope.interface
class PublicView(grok.View):
grok.context(zope.interface.Interface)
grok.require('zope.Public')
def render(self):
return ', '.join(self.request.principal.groups)
class ProtectedView(grok.View):
grok.context(zope.interface.Interface)
grok.require('grok.test')
def render(self):
return ', '.join(self.request.principal.groups)
@grok.require('zope.View')
def eat(self):
return 'MMM, MANFRED TASTE GOOD!'
@grok.require('zope.ManageContent')
def dance(self):
return {'Manfred doesn\'t like to dance.': ''}
def update(self):
apps = zope.component.getAllUtilitiesRegisteredFor(
grok.interfaces.IApplication)
self.applications = ("%s.%s" % (x.__module__, x.__name__)
for x in apps)
# Go to the first page immediately.
self.redirect(self.url('applications'))
class Applications(GAIAView):
"""View for application management.
"""
grok.name('applications')
grok.require('grok.ManageApplications')
def getDocOfApp(self, apppath, headonly = True):
doctor = docgrok.docgrok_handle(apppath)
result = doctor.getDoc(headonly)
if result is None:
result = ""
return result
def update(self):
from ZODB import broken
from zope.app.broken.broken import IBroken
# Available apps...
apps = zope.component.getAllUtilitiesRegisteredFor(
grok.interfaces.IApplication)
@grok.require('some.permission')
def doSomethingVerySecret(self):
pass