Пример #1
0
def xmlpagegenerator(request, service_id):
    service = get_object_or_404(Service, service_id=service_id)
    metaData = service.meta_data_set.all()[0]
    landingpage = service.landing_page_set.all()[0]
    tutorial_options = landingpage.tutorial_option_set.all().order_by("order")
    first_option_title = tutorial_options[0].title
    first_option_link = tutorial_options[0].link
    template = loader.get_template('landingPage/xmlTemplate.xml')
    if service_id == "virtual-machines":
        frame = loader.get_template('landingPage/VM.html')
    else:
        frame = loader.get_template('landingPage/frame2.html')
    for node in frame.template.nodelist:
        for child_node in node.nodelist:
            if type(child_node) == BlockNode:
                if child_node.name == 'header':
                    html_header = child_node
                elif child_node.name == 'content':
                    html_body = child_node
    header = Template("")
    body = Template("")
    header.nodelist = html_header
    body.nodelist = html_body
    html_header = header.render(Context({"cssLink":"//wacndevelop.blob.core.chinacloudapi.cn/tech-content/css/landingpageframe.css","jqueryLink":"//wacndevelop.blob.core.chinacloudapi.cn/tech-content/js/landingpagejquery-2.1.4.js","jsLink":"//wacndevelop.blob.core.chinacloudapi.cn/tech-content/js/landingpageresponsive.js"}))
    if service_id == "virtual-machines":
        html_body = body.render(Context({"service_name":"虚拟机",
                                "cssLink":BLOB_PATH+"css/landingpageframe.css",
                                "jqueryLink":BLOB_PATH+"js/landingpagejquery-2.1.4.js",
                                "jsLink":BLOB_PATH+"js/landingpageresponsive.js",
                                "imgLink":BLOB_PATH+"media/"}))
    else:
        navigationJson = re.sub(r"(\"https?://(azure.microsoft.com|www.windowsazure.cn|acncontentteam.azurewebsites.net|127.0.0.1:8000|10.168.177.43:8000)(/zh\-cn)?/)|(\"(/zh\-cn)?/)","\"/",landingpage.navigationJson).replace("'", "\\'").replace("\n", "")
        html_body = body.render(Context({"service_name":service.service_name,
                                "subtitle":landingpage.subtitle, 
                                "service_id":service.service_id,
                                "ms_service":landingpage.ms_service,
                                "tutorial_message":landingpage.tutorial_message,
                                "update_search_link":landingpage.update_search_link,
                                "navigationJson":navigationJson,
                                "first_option_title":first_option_title,
                                "first_option_link":first_option_link,
                                "options":tutorial_options,
                                "videoLinks":landingpage.video_link_set.all().order_by("order"),
                                "recentUpdates":landingpage.recent_update_set.all().order_by("order"),
                                "cssLink":BLOB_PATH+"css/landingpageframe.css",
                                "jqueryLink":BLOB_PATH+"js/landingpagejquery-2.1.4.js",
                                "jsLink":BLOB_PATH+"js/landingpageresponsive.js",
                                "imgLink":BLOB_PATH+"media/"}))
    
    xml_text = template.render({"html_header":html_header, "html_body":html_body, "html_title":service.service_name, "metaKeywords":metaData.meta_keywords, "metaDescription":metaData.meta_description})
    #xml_text = re.sub(r"/home/features/([^/|^#|^\"|^\'|^\)|^\s]+)/pricing/?", r"/pricing/details/\1/", xml_text)
    #xml_text = re.sub(r"/home/features/([^/|^#|^\"|^\'|^\)|^\s]+)/calculator/?", r"/pricing/calculator/\1/", xml_text)
    #print(html_body)
    return render_to_response('landingPage/xmlPageGenerator.html',{"xmlContent":xml_text})
Пример #2
0
def xmlpagegenerator(request, service_id):
    service = get_object_or_404(Service, service_id=service_id)
    metaData = service.meta_data_set.all()[0]
    landingpage = service.landing_page_set.all()[0]
    tutorial_options = landingpage.tutorial_option_set.all().order_by("order")
    first_option_title = tutorial_options[0].title
    first_option_link = tutorial_options[0].link
    template = loader.get_template('mooncakeTestEnvironment/xmlTemplate.xml')
    frame = loader.get_template('mooncakeTestEnvironment/frame.html')
    for node in frame.template.nodelist:
        print(node)
        for child_node in node.nodelist:
            print(type(child_node))
            if type(child_node) == BlockNode:
                if child_node.name == 'header':
                    html_header = child_node
                elif child_node.name == 'content':
                    html_body = child_node
    header = Template("")
    body = Template("")
    header.nodelist = html_header
    body.nodelist = html_body
    html_header = header.render(Context({}))
    html_body = body.render(Context({"service_name":service.service_name,
                                "subtitle":landingpage.subtitle, 
                                "tutorial_message":landingpage.tutorial_message,
                                "update_search_link":landingpage.update_search_link,
                                "navigationJson":landingpage.navigationJson.encode("utf-8").decode('unicode-escape').replace("'", "\\'").replace("\n", ""),
                                "first_option_title":first_option_title,
                                "first_option_link":first_option_link,
                                "options":tutorial_options,
                                "videoLinks":landingpage.video_link_set.all().order_by("order"),
                                "recentUpdates":landingpage.recent_update_set.all().order_by("order"),
                                "cssLink":BLOB_PATH+"css/landingpageframe.css",
                                "jqueryLink":BLOB_PATH+"js/landingpagejquery-2.1.4.js",
                                "jsLink":BLOB_PATH+"js/landingpageresponsive.js",
                                "imgLink":BLOB_PATH+"media/"}))
    
    return render_to_response('mooncakeTestEnvironment/xmlPageGenerator.html',{"xmlContent":template.render({"html_header":html_header, "html_body":html_body, "html_title":service.service_name, "metaKeywords":metaData.meta_keywords, "metaDescription":metaData.meta_description})})
Пример #3
0
    def render_template(self, template_string):
        """Used to render an "inner" template, ie one which
        is passed as an argument to spurl"""
        original_autoescape = self.context.autoescape
        self.context.autoescape = False

        template = Template('')
        if settings.TEMPLATE_DEBUG:
            origin = StringOrigin(template_string)
        else:
            origin = None

        template.nodelist = self.compile_string(template_string, origin)

        rendered = template.render(self.context)
        self.context.autoescape = original_autoescape
        return rendered
Пример #4
0
def render_custom_content(body, context_data={}):
    """Renders custom content for the payload using Django templating.

    This will take the custom payload content template provided by
    the user and render it using a stripped down version of Django's
    templating system.

    In order to keep the payload safe, we use a limited Context along with a
    custom Parser that blocks certain template tags. This gives us
    tags like {% for %} and {% if %}, but blacklists tags like {% load %}
    and {% include %}.
    """
    lexer = Lexer(body, origin=None)
    parser = CustomPayloadParser(lexer.tokenize())
    template = Template('')
    template.nodelist = parser.parse()

    return template.render(Context(context_data))
Пример #5
0
    def render_template(self, template_string):
        """Used to render an "inner" template, ie one which
        is passed as an argument to spurl"""
        original_autoescape = self.context.autoescape
        self.context.autoescape = False

        template = Template('')
        template_debug = getattr(
            settings, 'TEMPLATE_DEBUG', template.engine.debug if hasattr(
                template, 'engine') else False)
        if template_debug is True:
            origin = StringOrigin(template_string)
        else:
            origin = None

        template.nodelist = self.compile_string(
            template_string, origin, template_debug)

        rendered = template.render(self.context)
        self.context.autoescape = original_autoescape
        return rendered