49
50
from zope.publisher.interfaces.browser import IBrowserPublisher
50
51
from zope.publisher.interfaces.xmlrpc import IXMLRPCRequest
51
52
from zope.security.interfaces import Unauthorized
53
from zope.traversing.interfaces import ITraversable
53
55
from canonical.config import config
54
56
from canonical.launchpad.helpers import intOrZero
342
344
return len(self.items) > 1 and not has_major_heading
348
"""Keeps templates that are registered as pages from being URL accessable.
350
The standard pattern in LP is to register templates that contain macros as
351
views on all objects:
355
name="+main-template-macros"
356
template="../templates/base-layout-macros.pt"
357
permission="zope.Public"
360
Without this class, that pattern would make the template URL traversable
361
from any object. Therefore requests like these would all "work":
363
http://launchpad.net/+main-template-macros
364
http://launchpad.net/ubuntu/+main-template-macros
365
http://launchpad.net/ubuntu/+main-template-macros
366
https://blueprints.launchpad.dev/ubuntu/hoary/+main-template-macros
368
Obviously, those requests wouldn't do anything useful and would instead
371
It would be nice to use a different pattern for macros instead, but we've
372
grown dependent on some of the peculiatrities of registering macro
373
templates in this way.
375
This class was created in order to prevent macro templates from being
376
accessable via URL without having to make nontrivial changes to the many,
377
many templates that use macros. To use the class add a "class" parameter
378
to macro template registrations:
382
name="+main-template-macros"
383
template="../templates/base-layout-macros.pt"
384
class="lp.app.browser.launchpad.Macro"
385
permission="zope.Public"
388
implements(IBrowserPublisher, ITraversable)
390
def __init__(self, context, request):
391
self.context = context
393
def traverse(self, name, furtherPath):
394
return self.index.macros[name]
396
def browserDefault(self, request):
399
def publishTraverse(self, request, name):
400
raise NotFound(self.context, self.__name__)
403
raise NotFound(self.context, self.__name__)
345
406
class MaintenanceMessage:
346
407
"""Display a maintenance message if the control file is present and
347
408
it contains a valid iso format time.