def render_rootURL(self, ctx, data): """ Add the WebSite's root URL as a child of the given tag. The root URL is the location of the resource beneath which all standard Mantissa resources (such as the private application and static content) is available. This can be important if a page is to be served at a location which is different from the root URL in order to make links in static XHTML templates resolve correctly (for example, by adding this value as the href of a <base> tag). """ site = ISiteURLGenerator(self._siteStore()) return ctx.tag[site.rootURL(IRequest(ctx))]
def __init__(self, webapp, fragment, pageComponents, username): """ Top-level container for Mantissa application views. @param webapp: a C{PrivateApplication}. @param fragment: The C{Element} or C{Fragment} to display as content. @param pageComponents a C{_PageComponent}. This page draws its HTML from the 'shell' template in the preferred theme for the store. If loaded in a browser that does not support Athena, the page provided by the 'athena-unsupported' template will be displayed instead. @see: L{PrivateApplication.preferredTheme} """ userStore = webapp.store siteStore = userStore.parent MantissaLivePage.__init__(self, ISiteURLGenerator(siteStore), getattr(fragment, 'iface', None), fragment, jsModuleRoot=None, docFactory=webapp.getDocFactory('shell')) _ShellRenderingMixin.__init__(self, webapp, pageComponents, username) _FragmentWrapperMixin.__init__(self, fragment, pageComponents) self.unsupportedBrowserLoader = ( webapp.getDocFactory("athena-unsupported"))
def setUp(self): """ Set up a store with a valid offering to test against. """ self.store = Store() installOffering(self.store, baseOffering, {}) self.site = ISiteURLGenerator(self.store)
def makeLivePage(self): """ Create a MantissaLivePage instance for testing. """ siteStore = Store(filesdir=self.mktemp()) Mantissa().installSite(siteStore, self.hostname.decode('ascii'), u"", False) return MantissaLivePage(ISiteURLGenerator(siteStore))
def setUp(self): """ Set up a store with a valid offering to test against. """ SiteTestsMixin.setUp(self) self.store = self.siteStore self.site = ISiteURLGenerator(self.store) self.resource = IResource(self.store)
def encryptedRoot(self, hostname=None): """ Return a string representing the HTTPS URL which is at the root of this site. @param hostname: An optional unicode string which, if specified, will be used as the hostname in the resulting URL, regardless of the C{hostname} attribute of this item. """ warnings.warn( "Use ISiteURLGenerator.rootURL instead of WebSite.encryptedRoot.", category=DeprecationWarning, stacklevel=2) if self.store.parent is not None: generator = ISiteURLGenerator(self.store.parent) else: generator = ISiteURLGenerator(self.store) return generator.encryptedRoot(hostname)
def test_stylesheetLocation(self): """ L{XHTMLDirectoryTheme.head} returns a link tag which gives the location of the stylesheet given by I{stylesheetLocation} if there is one. """ siteStore = Store(filesdir=self.mktemp()) Mantissa().installSite(siteStore, u"example.com", u"", False) site = ISiteURLGenerator(siteStore) self.theme.stylesheetLocation = ['foo', 'bar'] request = FakeRequest() link = self.theme.head(request, site) self.assertEqual(link.tagName, 'link') self.assertEqual(link.attributes['rel'], 'stylesheet') self.assertEqual(link.attributes['type'], 'text/css') self.assertEqual( site.rootURL(request).child('foo').child('bar'), link.attributes['href'])
def rootURL(self, request): """ Simple utility function to provide a root URL for this website which is appropriate to use in links generated in response to the given request. @type request: L{twisted.web.http.Request} @param request: The request which is being responded to. @rtype: L{URL} @return: The location at which the root of the resource hierarchy for this website is available. """ warnings.warn( "Use ISiteURLGenerator.rootURL instead of WebSite.rootURL.", category=DeprecationWarning, stacklevel=2) if self.store.parent is not None: generator = ISiteURLGenerator(self.store.parent) else: generator = ISiteURLGenerator(self.store) return generator.rootURL(request)
def maybeEncryptedRoot(self, hostname=None): """ Returning a string representing the HTTPS URL which is at the root of this site, falling back to HTTP if HTTPS service is not available. @param hostname: An optional unicode string which, if specified, will be used as the hostname in the resulting URL, regardless of the C{hostname} attribute of this item. """ warnings.warn( "Use ISiteURLGenerator.rootURL instead of " "WebSite.maybeEncryptedRoot", category=DeprecationWarning, stacklevel=2) if self.store.parent is not None: generator = ISiteURLGenerator(self.store.parent) else: generator = ISiteURLGenerator(self.store) root = generator.encryptedRoot(hostname) if root is None: root = generator.cleartextRoot(hostname) return root
def _renderHead(self, result): """ Go through all the gyrations necessary to get the head contents produced by the page rendering process. """ site = ISiteURLGenerator(self.siteStore) t = tags.invisible() ctx = WovenContext(tag=t) req = FakeRequest() ctx.remember(req, IRequest) expected = [ th.head(req, site) for th in self.pageFactory._preferredThemes() ] head = result.render_head(ctx, None) return t, expected
def test_headRenderer(self): """ The I{head} renderer gets the head section for each installed theme by calling their C{head} method with the request being rendered and adds the result to the tag it is passed. """ headCalls = [] customHead = object() class CustomHeadTheme(object): priority = 0 themeName = "custom" def head(self, request, site): headCalls.append((request, site)) return customHead def getDocFactory(self, name, default): return default tech = FakeOfferingTechnician() tech.installOffering( Offering(name=u'fake', description=u'', siteRequirements=[], appPowerups=[], installablePowerups=[], loginInterfaces=[], themes=[CustomHeadTheme()])) self.siteStore.inMemoryPowerUp(tech, IOfferingTechnician) # Flush the cache, which is global, else the above fake-out is # completely ignored. theThemeCache.emptyCache() page = self.createPage(self.username) tag = div() ctx = context.WebContext(tag=tag) request = FakeRequest() ctx.remember(request, inevow.IRequest) result = page.render_head(ctx, None) self.assertEqual(result.tagName, 'div') self.assertEqual(result.attributes, {}) self.assertIn(customHead, result.children) self.assertEqual(headCalls, [(request, ISiteURLGenerator(self.siteStore))])
def render_head(self, ctx, data): req = IRequest(ctx) userStore = self.webapp.store siteStore = userStore.parent site = ISiteURLGenerator(siteStore) l = self.pageComponents.themes _reorderForPreference(l, self.webapp.preferredTheme) extras = [] for theme in l: extra = theme.head(req, site) if extra is not None: extras.append(extra) headMethod = getattr(self.fragment, 'head', None) if headMethod is not None: extra = headMethod() if extra is not None: extras.append(extra) return ctx.tag[extras]
def rootURL(self, request): """ Return the root URL as reported by C{self.website}. """ return ISiteURLGenerator(self.siteStore).rootURL(request)