示例#1
0
 def render_GET(self, httprequest):
     u"""
     The <code>render_GET</code> method is called by Twisted to handle the GET <attr>httprequest</attr>. The
     site instance is called with <code>b.build()</code>. The result (this can be HTML, JSON or binary data) is
     answered. The application needs to have the the right MIME type in the output.
     """
     site = self.getSite(httprequest)  # Site is Theme instance
     # b.setMimeTypeEncoding(httprequest)
     try:
         # If there is a matching file in the site root/files folder, then answer this.
         filePath = self.getFilePath(site)
         result = self.resolveByFile(site, filePath)
         if site.e.form['force'] or result is None or self.INITCSS:
             if site.e.request.path.endswith('.css'):
                 builder = CssBuilder(e=site.e)
                 site.build(
                     builder
                 )  # Build from entire site theme, not just from template.
                 builder.save(site, path=filePath)  # Compile Sass to Css
                 result = builder.getResult()
                 self.INITCSS = False  # Mark that the initialize CSS on startup has been done.
             else:
                 site.reset(
                 )  # Allow the theme to reset values for every page request, depending on url parameters.
                 builder = HtmlBuilder(e=site.e)
                 template = site.getMatchingTemplate(builder)
                 template.build(builder)
                 result = builder.getResult()
         return result
     except Exception, e:
         t = traceback.format_exc()
         httprequest.setHeader('content-type', 'text/html')
         return self.renderError(e, t)
示例#2
0
 def render_GET(self, httprequest):
     u"""
     The <code>render_GET</code> method is called by Twisted to handle the GET <attr>httprequest</attr>. The
     site instance is called with <code>b.build()</code>. The result (this can be HTML, JSON or binary data) is
     answered. The application needs to have the the right MIME type in the output.
     """
     site = self.getSite(httprequest)  # Site is Theme instance
     # b.setMimeTypeEncoding(httprequest)
     try:
         # If there is a matching file in the site root/files folder, then answer this.
         filePath = self.getFilePath(site)
         result = self.resolveByFile(site, filePath)
         if site.e.form["force"] or result is None or self.INITCSS:
             if site.e.request.path.endswith(".css"):
                 builder = CssBuilder(e=site.e)
                 site.build(builder)  # Build from entire site theme, not just from template.
                 builder.save(site, path=filePath)  # Compile Sass to Css
                 result = builder.getResult()
                 self.INITCSS = False  # Mark that the initialize CSS on startup has been done.
             else:
                 site.reset()  # Allow the theme to reset values for every page request, depending on url parameters.
                 builder = HtmlBuilder(e=site.e)
                 template = site.getMatchingTemplate(builder)
                 template.build(builder)
                 result = builder.getResult()
         return result
     except Exception, e:
         t = traceback.format_exc()
         httprequest.setHeader("content-type", "text/html")
         return self.renderError(e, t)
示例#3
0
    def render_POST(self, httprequest):
        u"""
        The <code>render_POST</code> method is called by Twisted to handle the POST <attr>httprequest</attr>. The
        site instance is called with <code>b.build()</code>. The result (this can be HTML, JSON or binary data) is
        answered. The application is supposed to have the the right MIME type in the output. The data of the post is
        located in the file object <code>httprequest.content</code>. The data can be read by <code>
        httprequest.content.read()</code>.
        
        """
        site = self.getSite(httprequest)  # Site is Theme instance
        site.handlePost()
        # b.setMimeTypeEncoding(httprequest)

        if isinstance(httprequest.content, StringIO.OutputType):
            # Probably JSON.
            json = httprequest.content.getvalue()
            # print json
            # b.buildJSON(json)
        try:
            # If there is a matching file in the site root folder, then answer this.
            result = self.resolveByFile(site, self.getFilePath(site))
            if result is None:
                if site.e.request.path.endswith('.css'):
                    builder = CssBuilder(e=site.e)
                    site.build(
                        builder
                    )  # Build from entire site theme, not just from template.
                    builder.save()  # Compile Sass to Css
                    result = builder.getResult()
                else:
                    builder = HtmlBuilder(e=site.e)
                    template = site.getMatchingTemplate(builder)
                    template.build(builder)
                    result = builder.getResult()
            return result
        except Exception, e:
            t = traceback.format_exc()
            return self.renderError(e, t)
示例#4
0
    def render_POST(self, httprequest):
        u"""
        The <code>render_POST</code> method is called by Twisted to handle the POST <attr>httprequest</attr>. The
        site instance is called with <code>b.build()</code>. The result (this can be HTML, JSON or binary data) is
        answered. The application is supposed to have the the right MIME type in the output. The data of the post is
        located in the file object <code>httprequest.content</code>. The data can be read by <code>
        httprequest.content.read()</code>.
        
        """
        site = self.getSite(httprequest)  # Site is Theme instance
        site.handlePost()
        # b.setMimeTypeEncoding(httprequest)

        if isinstance(httprequest.content, StringIO.OutputType):
            # Probably JSON.
            json = httprequest.content.getvalue()
            # print json
            # b.buildJSON(json)
        try:
            # If there is a matching file in the site root folder, then answer this.
            result = self.resolveByFile(site, self.getFilePath(site))
            if result is None:
                if site.e.request.path.endswith(".css"):
                    builder = CssBuilder(e=site.e)
                    site.build(builder)  # Build from entire site theme, not just from template.
                    builder.save()  # Compile Sass to Css
                    result = builder.getResult()
                else:
                    builder = HtmlBuilder(e=site.e)
                    template = site.getMatchingTemplate(builder)
                    template.build(builder)
                    result = builder.getResult()
            return result
        except Exception, e:
            t = traceback.format_exc()
            return self.renderError(e, t)
示例#5
0
 def buildCss(self, site):
     u"""Build the site to CSS."""
     doIndent = self.getDoIndent() # Boolean flag if indenting should be in output.
     builder = CssBuilder(e=site.e, doIndent=doIndent)
     filePath = builder.getFilePath(site)
     result = self.resolveByFile(site, filePath)
     #if site.e.form[self.C.PARAM_DOCUMENTATION]: # /documentation
     #    site.buildDocumentation(builder) # Build the live documentation page from the site
     #    #builder.save(site, path=filePath) # Compile resulting Sass to Css
     #    #builder.save(site, path=filePath.replace('.css', '_doc.css')) # Compile resulting Sass to Css
     #    result = builder.css #getResult()
     if site.e.form[self.C.PARAM_FORCE] or site.e.form[self.C.PARAM_DOCUMENTATION] or result is None:
         # Forced or no cached CSS or building documentation,
         # so try to build is and save it in the cache.
         site.build(builder) # Build from entire site theme, not just from template. Result is stream in builder.
         builder.save(site, path=filePath) # Compile resulting Sass to Css
         result = builder.getResult() # Get the resulting Sass.
     return result, self.C.MIMETYPE_CSS