示例#1
0
    def _on_template_clicked(self, arg):
        try:
            with open(".\\templates\\" + self.template_entry.get_text(),
                      'r') as f:
                template = f.read()
        except:
            md = gtk.MessageDialog(self, gtk.DIALOG_DESTROY_WITH_PARENT,
                                   gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE,
                                   "Unable to find specified template.")
            md.run()
            md.destroy()

        else:
            self.te = TemplateEngine(template)
            for block in self.te.blocks:
                exec """self.block_%s_label = gtk.Label('%s')
self.txtbox_%s = CustomTextView('%s')
self.vbox.pack_start(self.block_%s_label, expand=False)
self.vbox.pack_start(self.txtbox_%s, expand=True)
self.txtbox_list.append(self.txtbox_%s)""" % (block, block, block, block,
                                              block, block,
                                              block) in globals(), locals()

            self.preview_btn = gtk.Button("Preview")
            self.submit_btn = gtk.Button("Submit email")

            self.preview_btn.connect("clicked", self._on_preview_clicked)
            self.submit_btn.connect("clicked", self._on_submit_clicked)

            self.vbox.pack_start(self.preview_btn, expand=False)
            self.vbox.pack_start(self.submit_btn, expand=False)

            self.show_all()
示例#2
0
 def generate_setup(self):
     """Create the setup script"""
     template_engine = TemplateEngine()
     template_context = {}
     template_context["scripts"] = self.__setup_scripts
     template_context["images"] = self.__images
     with open(self.__filename, "w") as script_file:
         script_file.write(
             template_engine.render_template("templates/setup/setup.sh.tpl",
                                             template_context))
     os.chmod(
         self.__filename,
         stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH | stat.S_IRUSR
         | stat.S_IRGRP | stat.S_IROTH | stat.S_IWUSR | stat.S_IWGRP)
示例#3
0
    def get(self):

       user = users.get_current_user()

       

       if not user:
          self.redirect(users.create_login_url(self.request.uri))
       else:

           template_values = {
              'user': user.email()
           }
    
           template_engine = TemplateEngine()
           self.response.out.write(template_engine.render('home.html', template_values))
示例#4
0
    def do_get(self, request):
        super().do_get(request)
        # print("self.path", self.path)
        # if self.path in ["blog", "blog/", "/", ""]:
        #     self.response = Response(main.protocolVersion, States.OK)
        #     self.response.body = replace_engine.set_top_page(main.DOCUMENT_ROOT + "/blog_top.html")
        #     self.ext = "html"

        #     return self.response

        head, tail = os.path.split(self.path)
        print("tail",tail)
        self.root, self.ext = os.path.splitext(tail)
        self.ext = self.ext.lstrip(".")
        print(self.ext)
        print(bool(self.ext))
        if self.ext:
            normal = NormalController()
            return normal.do_get(request)

        if tail and not tail == "blog":
            print("in article")
            article = articles.get_articles(tail)

            if article:
                engine = TemplateEngine(article, "template")
                self.response = Response(main.protocolVersion, States.OK)
                self.response.body = engine.render()
                self.ext = "html"

            else:
                self.response = self.not_found()

        else:
            print("in blog_top")
            self.response = Response(main.protocolVersion, States.OK)
            self.response.body = replace_engine.set_top_page(os.path.join(main.DOCUMENT_ROOT, "blog_top.html"))
            self.ext = "html"

            # return self.response
            # self.response = Response(main.protocolVersion, States.Not_Found)
            # self.response.body = os.path.join(main.DOCUMENT_ROOT, "blog.html")
            # self.ext = "html"

        return self.response
示例#5
0
from template_engine import TemplateEngine

if __name__ == '__main__':
    with open('template-responses.txt', 'r') as templates_responses:
        templates = []
        for template in templates_responses.readlines():
            templates.append(tuple(template.split('|')))
        engine = TemplateEngine(templates)
        while True:
            message = input()
            print(engine.process_question(message))
示例#6
0
    def get(self):

        template_engine = TemplateEngine()
        self.response.out.write(template_engine.render('main.html', []))
示例#7
0
 def get_setup(self):
     context = {}
     template_engine = TemplateEngine()
     setup_data = template_engine.render_template("templates/software/docker-compose-setup.sh.tpl",
                                                  context)
     return setup_data