Beispiel #1
0
   def get( self, requestedCssFilename ):
      logging.debug("Requested CSS Path: "+requestedCssFilename);
      # Build the Path to the CSS and check if we already have rendered it and is sitting in Memcache ready to use
      if config.url_prefix != '':
        requestedCssFilename =  requestedCssFilename[len(config.url_prefix):]# Strip off prefix 
      cssPath = os.path.join( os.path.dirname( __file__), 'themes/%s/%s' % (config.theme, requestedCssFilename) );
      if ( not os.path.exists(cssPath) ):
         logging.error("CSS not found: "+cssPath);
         self.error(404); # Client Error 4xx - 404 Not Found
         return;
      
      cssRenderingResult = None;
      # Check if Memcaching is enabled
      if ( config.memcaching ):
         cssRenderingResult = memcache.get(cssPath);
      
      # In case the Memcache didn't contain the CSS rendered
      if ( cssRenderingResult is None ):      
         logging.debug("Rendering CSS: "+cssPath);   
         # Render the CSS
         cssRenderingResult = template.render(cssPath, { 'config' : config });

         # Minify ONLY IF NOT Debugging
         if ( config.logging_level != logging.DEBUG ):
            logging.info("Minifying CSS: "+requestedCssFilename);
            # Minify CSS
            try:
               cssRenderingResult = cssmin.minify(cssRenderingResult);
            except:
               logging.warning("CSS Minification failed: " + requestedCssFilename); 
         
         # Save in Memcache
         memcache.set(cssPath, cssRenderingResult);
         
      # Setting Content-Type as "text/javascript"
      self.response.headers['Content-Type'] = 'text/css'
      logging.debug("Serving Minified CSS: "+cssPath);
      # Rendering the Result
      self.response.out.write( cssRenderingResult );
Beispiel #2
0
    def get(self, requestedCssFilename):
        logging.debug("Requested CSS Path: " + requestedCssFilename)
        # Build the Path to the CSS and check if we already have rendered it and is sitting in Memcache ready to use
        cssPath = os.path.join(os.path.dirname(__file__), "themes/%s/%s" % (config.theme, requestedCssFilename))
        if not os.path.exists(cssPath):
            logging.error("CSS not found: " + cssPath)
            self.error(404)
            # Client Error 4xx - 404 Not Found
            return

        cssRenderingResult = None
        # Check if Memcaching is enabled
        if config.memcaching:
            cssRenderingResult = memcache.get(cssPath)

        # In case the Memcache didn't contain the CSS rendered
        if cssRenderingResult is None:
            logging.debug("Rendering CSS: " + cssPath)
            # Render the CSS
            cssRenderingResult = template.render(cssPath, {"config": config})

            # Minify ONLY IF NOT Debugging
            if config.logging_level != logging.DEBUG:
                logging.info("Minifying CSS: " + requestedCssFilename)
                # Minify CSS
                try:
                    cssRenderingResult = cssmin.minify(cssRenderingResult)
                except:
                    logging.warning("CSS Minification failed: " + requestedCssFilename)

            # Save in Memcache
            memcache.set(cssPath, cssRenderingResult)

        # Setting Content-Type as "text/javascript"
        self.response.headers["Content-Type"] = "text/css"
        logging.debug("Serving Minified CSS: " + cssPath)
        # Rendering the Result
        self.response.out.write(cssRenderingResult)
Beispiel #3
0
  def get(self, requestedCssFilename):
    logging.debug("Requested CSS Path: "+requestedCssFilename)
    # Build the Path to the CSS and check if we already have rendered it and is sitting in Memcache ready to use
    cssPath = os.path.join( os.path.dirname( __file__ ), 'themes/%s/%s' % (config.theme, requestedCssFilename) )
    if not os.path.exists(cssPath):
      logging.error("CSS not found: "+cssPath)
      # Client Error 4xx - 404 Not Found
      self.response.set_status(404)
      return

    cssRenderingResult = None
    # Check if Memcaching is enabled
    if config.memcaching:
      cssRenderingResult = memcache.get(cssPath)

    # In case the Memcache didn't contain the CSS rendered
    if cssRenderingResult is None:
      logging.debug("Rendering CSS: "+cssPath)
      # Render the CSS
      cssRenderingResult = template.render(cssPath, {'config' : config})

      # Minify ONLY IF NOT Debugging
      if config.logging_level != logging.DEBUG:
        logging.debug("Minifying CSS: "+requestedCssFilename)
        # Minify CSS
        cssRenderingResult = cssmin.minify(cssRenderingResult)

      # Save in Memcache
      memcache.set(cssPath, cssRenderingResult)

    # Setting Content-Type as "text/css"
    self.response.headers['Content-Type'] = 'text/css'
    now = datetime.datetime.now().replace(second=0, microsecond=0)
    self.response.headers['Last-Modified'] = now.strftime(HTTP_DATE_FMT)
    #self.response.headers['Expires'] = now
    logging.debug("Serving Minified CSS: " + cssPath)
    # Rendering the Result
    self.response.out.write(cssRenderingResult)