Esempio n. 1
0
  def render(self, template_name, passed_vars, response_code = 200, 
          response_type=False, prettyPrint=False, template_set='app', template_theme=None):
    """Main render helper function. Wraps other rendering functions
    
    """
    if not response_type:
      response_type = self.request.response_type()

    prettyPrint = bool(self.request.get('prettyPrint', False))
    
    if hasmethod(self, 'template_wrapper'):
      passed_vars = self.template_wrapper(variables = passed_vars)
          
    if response_type in ['xml', 'json']:
      serial_f = getattr(sketch.serialize, response_type)
      content = serial_f(passed_vars, pretty = prettyPrint)
      self.response.headers['Content-Type'] = "application/%s; charset=utf-8" % (response_type)
    else:
      sketch.jinja.setup(self.config.paths.templates)
      passed_vars = self.get_template_vars(passed_vars)
      passed_vars = self.get_plugin_vars(passed_vars)
      # fixing..
      
      if hasattr(self, 'template_folder'):
        template_theme = getmethattr(self, 'template_folder')
      
      content = sketch.jinja.render(template_name, passed_vars, template_theme=template_theme, template_set=template_set)
    
    self.render_content(content, response_code)
Esempio n. 2
0
  def get_template_vars(self, template_vars):
    if type(template_vars) != dict:
      template_vars = {'_vars': template_vars}
      
    additional = {
      # 'session': self.session,
      # 'user': False,

        # 'title': 'test'
        # 'title': self.conf_get('title')
    }

    # if 'auth' in self.session:
    #   additional['loggedin'] = True
    #   additional['username'] = self.session.get('username', '')
    #   additional['user'] = self.user
    # 
    # if self.message:
    #   additional['message'] = self.message
    #   additional['message_type'] = self.message_type
    #   additional['message_class'] = self.message_class

    if hasmethod(self, 'template_wrapper'):
      template_vars = self.template_wrapper(variables=template_vars)
      
    additional = self.get_javascripts(additional)
    additional = self.get_styles(additional)

    return dict(template_vars, **additional)