def objectResource(obj): """ Adapt L{ImmutableObject) to L{IResource}. """ res = File(obj.content.path) res.type = obj.contentType.encode('ascii') res.encoding = None return res
def __init__(self, system): self.system = system self.putChild('apidocs.css', File(util.templatefile('apidocs.css'))) self.putChild('sorttable.js', File(util.templatefile('sorttable.js'))) self.putChild('pydoctor.js', File(util.templatefile('pydoctor.js'))) self.index = WrapperPage(self.indexPage()) self.putChild('', self.index) self.putChild('index.html', self.index) self.putChild('moduleIndex.html', WrapperPage(summary.ModuleIndexPage(self.system))) self.putChild('classIndex.html', WrapperPage(summary.ClassIndexPage(self.system))) self.putChild('nameIndex.html', WrapperPage(summary.NameIndexPage(self.system)))
def locateChild(self, context, segments): """ Find the offering with the name matching the first segment and return a L{File} for its I{staticContentPath}. """ name = segments[0] try: staticContent = self.staticPaths[name] except KeyError: return NotFound else: resource = File(staticContent.path) resource.processors = self.processors return resource, segments[1:] return NotFound
def makeStylesheetResource(self, path, registry): """ Return a resource for the css at the given path with its urls rewritten based on self.rootURL. """ return StylesheetRewritingResourceWrapper( File(path), self.installedOfferingNames, self.rootURL)
def child_Mantissa(self, ctx): """ Serve files from C{xmantissa/static/} at the URL C{/Mantissa}. """ # Cheating! It *looks* like there's an app store, but there isn't # really, because this is the One Store To Bind Them All. # We shouldn't really cheat here. It would be better to have one real # Mantissa offering that has its static content served up the same way # every other offering's content is served. There's already a # /static/mantissa-static/. This child definition is only still here # because some things still reference this URL. For example, # JavaScript files and any CSS file which uses Mantissa content but is # from an Offering which does not provide a staticContentPath. # See #2469. -exarkun return File(FilePath(__file__).sibling("static").path)
implements(inevow.IResource) def __init__(self, path, content_type='text/plain'): self.path = path self.content_type = content_type def locateChild(self, *args): from nevow import rend return rend.NotFound def renderHTTP(self, ctx): inevow.IRequest(ctx).setHeader('Content-type', self.content_type) return open(self.path).read() defaultCSS = File(util.resource_filename('formless', 'freeform-default.css'), 'text/css') class DefaultRenderer(object): implements(inevow.IRenderer, iformless.ITypedRenderer) complexType = False def rend(self, context, data): return StringRenderer(data) defaultBindingRenderer = DefaultRenderer() class BaseInputRenderer(components.Adapter): implements(inevow.IRenderer, iformless.ITypedRenderer)
__implements__ = inevow.IResource def __init__(self, path, content_type='text/plain'): self.path = path self.content_type = content_type def locateChild(self, *args): from nevow import rend return rend.NotFound def renderHTTP(self, ctx): inevow.IRequest(ctx).setHeader('Content-type', self.content_type) return open(self.path).read() defaultCSS = File(_locateDefaultCSS(), 'text/css') class DefaultRenderer(object): __implements__ = inevow.IRenderer, iformless.ITypedRenderer complexType = False def rend(self, context, data): return StringRenderer(data) defaultBindingRenderer = DefaultRenderer() class BaseInputRenderer(compy.Adapter): __implements__ = inevow.IRenderer, iformless.ITypedRenderer
def child_static(self, ctx): s = FilePath(methanal.__file__).sibling('static') return File(s.path)
def createResource(self): return File(self.staticContentPath)
class SettingsPage(rend.Page): # We deserve a slash addSlash = True # This makes webform_css url answer some default CSS child_webform_css = webform.defaultCSS child_webinterface_css = File( paths.AbsNeighbourFile(__file__, 'webinterface.css'), 'text/css') implements(ISettings) def __getattr__(self, name): global extensions_settings_od if name.startswith('configurable_'): token = name[13:] def configurable_something(ctx): settings, _display = extensions_settings_od[token] return settings return configurable_something raise AttributeError def extensions_settings(self, context, data): """ Project extensions settings Extensions added to Configuration Tree in IDE have their setting rendered here """ global extensions_settings_od res = [] for token in extensions_settings_od: _settings, display = extensions_settings_od[token] res += [tags.h2[display], webform.renderForms(token)] return res docFactory = loaders.stan([ tags.html[ tags.head[tags.title[_("Beremiz Runtime Settings")], tags.link(rel='stylesheet', type='text/css', href=url.here.child("webform_css")), tags.link(rel='stylesheet', type='text/css', href=url.here.child("webinterface_css"))], tags.body[tags.a(href='/')['Back'], tags.h1["Runtime settings:"], webform.renderForms('staticSettings'), tags.h1["Extensions settings:"], webform.renderForms('dynamicSettings'), extensions_settings]] ]) def configurable_staticSettings(self, ctx): return configurable.TypedInterfaceConfigurable(self) def configurable_dynamicSettings(self, ctx): """ Runtime Extensions settings Extensions loaded through Beremiz_service -e or optional runtime features render setting forms here """ return ConfigurableSettings def sendLogMessage(self, level, message, **kwargs): level = LogLevelsDict[level] if _PySrv.plcobj is not None: _PySrv.plcobj.LogMessage(level, "Web form log message: " + message) def locateChild(self, ctx, segments): if segments[0] in customSettingsURLs: return customSettingsURLs[segments[0]](ctx, segments) return super(SettingsPage, self).locateChild(ctx, segments)
config.readConfig('web.cfg') config.setWorkDir('tsweb') logging.initLogging() from tsload.web import webappPath from tsload.web.main import MainPage, AboutPage from tsload.web.login import LoginPage, LogoutPage from tsload.web.agent import AgentPage from tsload.web.profile import ProfilePage main = MainPage() # Static directories main.putChild('bootstrap', File(webappPath('bootstrap'))) main.putChild('css', File(webappPath('css'))) main.putChild('js', File(webappPath('js'))) main.putChild('images', File(webappPath('images'))) # Pages main.putChild('about', AboutPage()) main.putChild('login', LoginPage()) main.putChild('logout', LogoutPage()) main.putChild('agent', AgentPage()) main.putChild('profile', ProfilePage()) site = NevowSite(main, logPath=config.get('logging', 'logaccess')) port = config.getInt('tsweb', 'port')