def load(self):
     log.debug("loadTemplates from %s" % self._config.templatesDir)
     for templatePath in self._config.templatesDir.files():
         # Only load .elt files
         if templatePath.basename().splitext()[1] == '.elt':
             template = Template(templatePath)
             if template.isValid():
                 self.addTemplate(template)
    def doImportTemplate(self, filename):
        """ Imports an template from a ELT file

        Checks that it is a valid template file,
        that the directory does not exist (prevent overwriting)
        """
        log.debug("Import template from %s" % filename)

        filename = Path(filename)
        baseFile = filename.basename()
        absoluteTargetDir = self.config.templatesDir / baseFile

        try:
            ZipFile(filename, 'r')
        except IOError:
            raise ImportTemplateError('Can not create dom object')

        if os.path.exists(absoluteTargetDir):

            template = Template(absoluteTargetDir)
            raise ImportTemplateExistsError(template, absoluteTargetDir,
                                            u'Template already exists')
        else:

            filename.copyfile(absoluteTargetDir)
            template = Template(absoluteTargetDir)

            if template.isValid():

                if not self.config.templateStore.addTemplate(template):

                    absoluteTargetDir.remove()
                    raise ImportTemplateExistsError(
                        template, absoluteTargetDir,
                        u'The template name already exists')
            else:

                absoluteTargetDir.remove()
                raise ImportTemplateExistsError(template, absoluteTargetDir,
                                                u'Incorrect template format')

        self.action = ""
 def doEditTemplate(self, template):
     try:
         templateEdit = Package.load(Template(self.config.templatesDir /
                                              template).path,
                                     isTemplate=True)
         self.webServer.root.bindNewPackage(templateEdit,
                                            self.client.session)
         self.client.sendScript((u'eXe.app.gotoUrl("/%s")' % \
                       templateEdit.name).encode('utf8'))
     except:
         self.alert(_(u'Error'), _(u'An unexpected error has occurred'))
    def doDeleteTemplate(self, template):

        # Get the current authoring page

        for mainpages in self.parent.mainpages.values():
            for mainpage in mainpages.values():
                if self.client.handleId in mainpage.authoringPages:
                    authoringPage = mainpage.authoringPages[
                        self.client.handleId]

        try:
            if authoringPage.package.filename == (self.config.templatesDir /
                                                  template):
                self.alert(
                    _('Error'),
                    _(u'It is not possible to delete an opened template.'))
                return
            templateDelete = Template(self.config.templatesDir / template)
            self.__deleteTemplate(templateDelete)
            self.alert(_(u'Correct'), _(u'Template deleted correctly'))
            self.reloadPanel('doList')
        except:
            self.alert(_(u'Error'), _(u'An unexpected error has occurred'))
        self.action = ""
 def doPreExportTemplate(self, template):
     templateExport = Template(self.config.templatesDir / template)
     self.properties = templateExport._renderProperties()
     self.action = 'PreExport'
     self.template = template
 def doPropertiesTemplate(self, template):
     templateProperties = Template(self.config.templatesDir / template)
     self.properties = templateProperties._renderProperties()
     self.action = 'Properties'
     self.template = templateProperties.name
    def doExportTemplate(self, template, filename):

        if filename != '':
            templateExport = Template(self.config.templatesDir / template)
            self.__exportTemplate(templateExport, unicode(filename))
        u'\n'
    ]

    # Open output file and write generation date
    file_w = open(application.config.templatesDir / u'strings.py', 'w');
    file_w.write(u'# Generated on %s\n' % str(datetime.now()))

    file_w.write(u'\ntemplates = {\n')

    # Go through all templates (only take into account .elt files)
    package_index = 0
    for file_name in [f for f in os.listdir(application.config.templatesDir) if os.path.splitext(f)[1] == '.elt']:
        print(u'Extracting messages from %s...' % (application.config.templatesDir / file_name))

        # Load the template as a package
        template = Template(application.config.templatesDir / file_name)
        package = Package.load(application.config.templatesDir / file_name, newLoad=True);

        # Write template header comment and definition start
        file_w.write(put_tabs(1))
        file_w.write(u'# Template: %s\n' % file_name)
        file_w.write(put_tabs(1))
        file_w.write(u'\'template_%i\': {\n' % package_index)

        # Template name
        file_w.write(put_tabs(2))
        file_w.write(u'\'template_name\': _(u\'%s\'),\n' % normalize_text(template.name))
        # Template author
        if template.author != u'':
            file_w.write(put_tabs(2))
            file_w.write(u'\'template_author\': _(u\'%s\'),\n' % normalize_text(template.author))
Exemple #9
0
    file_w = open(application.config.templatesDir / u'strings.py', 'w')
    file_w.write(u'# Generated on %s\n' % str(datetime.now()))

    file_w.write(u'\ntemplates = {\n')

    # Go through all templates (only take into account .elt files)
    package_index = 0
    for file_name in [
            f for f in os.listdir(application.config.templatesDir)
            if os.path.splitext(f)[1] == '.elt'
    ]:
        print(u'Extracting messages from %s...' %
              (application.config.templatesDir / file_name))

        # Load the template as a package
        template = Template(application.config.templatesDir / file_name)
        package = Package.load(application.config.templatesDir / file_name,
                               newLoad=True)

        # Write template header comment and definition start
        file_w.write(put_tabs(1))
        file_w.write(u'# Template: %s\n' % file_name)
        file_w.write(put_tabs(1))
        file_w.write(u'\'template_%i\': {\n' % package_index)

        # Template name
        file_w.write(put_tabs(2))
        file_w.write(u'\'template_name\': _(u\'%s\'),\n' %
                     normalize_text(template.name))
        # Template author
        if template.author != u'':