示例#1
0
    def render(self, context):
        new_context = {}

        # Run through the dictionary and evaluate it
        for key, value_name in self.dictionary_info.iteritems():
            new_context_value = None

            # Try it as a variable first
            try:
                v = djangot.Variable(value_name)
                new_context_value = v.resolve(context)
            except:
                new_context_value = None

            # And as an actual python value second
            if new_context_value is None:
                try:
                    new_context_value = eval(value_name)
                except:
                    new_context_value = None

            new_context[key] = new_context_value

        # Render the template
        final_template = template.load(self.template_path)
        return final_template.render(template.Context(new_context))
示例#2
0
    def render(self, context):
        new_context = {}

        # Run through the dictionary and evaluate it
        for key, value_name in self.dictionary_info.iteritems():
            new_context_value = None

            # Try it as a variable first            
            try:
                v = djangot.Variable(value_name)
                new_context_value = v.resolve(context)
            except:
                new_context_value = None

            # And as an actual python value second
            if new_context_value is None:
                try:
                    new_context_value = eval(value_name)
                except:
                    new_context_value = None

            new_context[key] = new_context_value

        # Render the template
        final_template = template.load(self.template_path)
        return final_template.render(template.Context(new_context))
  def testRenderKMLTemplateWithEmptyCache(self):
    self.mox.StubOutWithMock(template, 'register_template_library')
    self.mox.StubOutWithMock(template, 'load')
    self.mox.StubOutWithMock(template, 'Context')
    mock_template = self.mox.CreateMockAnything()
    mock_cache = {}
    dummy_file = 'dummy'
    dummy_args = object()
    dummy_context = object()
    dummy_result = object()
    self.stubs.Set(model, '_kml_template_cache', mock_cache)

    template.register_template_library('template_functions.kml')
    template.load('kml_templates/dummy').AndReturn(mock_template)
    template.Context(dummy_args).AndReturn(dummy_context)
    mock_template.render(dummy_context).AndReturn(dummy_result)
    self.mox.ReplayAll()
    self.assertEqual(model._RenderKMLTemplate(dummy_file, dummy_args),
                     dummy_result)
    self.assertEqual(mock_cache[dummy_file], mock_template)
示例#4
0
文件: render.py 项目: wcpolpc/KADVD
def render_block_to_string(template_name, block, dictionary=None, context_instance=None):
    """
    Loads the given template_name and renders the given block with the given dictionary as
    context. Returns a string.
    """
    dictionary = dictionary or {}
    t = template.load(template_name)
    if context_instance:
        context_instance.update(dictionary)
    else:
        context_instance = Context(dictionary)
    t.render(context_instance)
    
    return render_template_block(t, block, context_instance)
示例#5
0
    def get(self, spaceName, pageUrl):
        currentSpace = spaceservice.getSpace(spaceName)
        if currentSpace:
            currentUser = self.getCurrentUser()
            requestWrapper = RequestWrapper(currentUser, self.request)

            currentPage = spaceservice.getPage(currentSpace, pageUrl);
            pageRenderer = renderer.PageRenderer(currentPage, requestWrapper, self.response)
            themeTemplate = template.load(os.path.join('template','theme', currentSpace.theme.name + '.html'))
            
            self.response.out.write(themeTemplate.render(template.Context({'page': pageRenderer})))

            if requestWrapper.uri:
                self.redirect(requestWrapper.uri)
        else:
            self.response.out.write(configuration.getMessage('space.not.found'))
示例#6
0
文件: render.py 项目: wcpolpc/KADVD
def direct_block_to_template(request, template_name, block, extra_context=None, mimetype=None, **kwargs):
    """
    Render a given block in a given template with any extra URL parameters in the context as
    ``{{ params }}``.
    """
    if extra_context is None:
    	extra_context = {}
    dictionary = {'params': kwargs}
    for key, value in extra_context.items():
        if callable(value):
            dictionary[key] = value()
        else:
            dictionary[key] = value
    c = RequestContext(request, dictionary)
    t = template.load(template_name)
    t.render(c)
    return HttpResponse(render_template_block(t, block, c), mimetype=mimetype)
示例#7
0
 def get_template(self, template):
   path = os.path.join(self.searchpath, template)
   return gae_template.load(path)
示例#8
0
  def get(self):
    params = {}

    t = template.load(os.path.join(os.path.dirname(__file__), "index.html"))
    self.response.out.write(t.render(RequestContext(self.request, params)))
示例#9
0
        return template.render(path, {'page': self})

    def processColumn(self):
        components = componentservice.getComponents(self.page, self.currentColumn)
        result = ''
        for component in components:
            componentRenderer = ComponentRenderer(component, self.request, self.response)
            result += componentTemplate.render(template.Context({'component': componentRenderer}))
        self.currentColumn += 1
        return result


class ComponentRenderer:
    def __init__(self, component, request, response):
        self.component = component
        self.request = request
        self.response = response

    def componentId (self):
        return self.component.key()

    def styleClass(self):
        return self.component.styleClass

    def process(self):
        component = __import__('component.' + self.component.componentType.name)
        return component.process(self.request, self.response)


componentTemplate = template.load(os.path.join('template', 'component.html'))
示例#10
0
    def get(self):
        params = {}

        t = template.load(os.path.join(os.path.dirname(__file__),
                                       "index.html"))
        self.response.out.write(t.render(RequestContext(self.request, params)))
示例#11
0
 def get_template(self, template):
     path = os.path.join(self.searchpath, template)
     return gae_template.load(path)