Esempio n. 1
0
 def walkList(self):
     # Add i18n-specific messages
     for name, field in self.appyType.fields:
         label = '%s_%s_%s' % (self.classDescr.name, self.fieldName, name)
         msg = PoMessage(label, '', name)
         msg.produceNiceDefault()
         self.generator.labels.append(msg)
Esempio n. 2
0
 def walkList(self):
     # Add i18n-specific messages
     for name, field in self.appyType.fields:
         label = "%s_%s_%s" % (self.classDescr.name, self.fieldName, name)
         msg = PoMessage(label, "", name)
         msg.produceNiceDefault()
         self.generator.labels.append(msg)
Esempio n. 3
0
 def walkString(self):
     """How to generate an Appy String?"""
     if self.appyType.isSelect and (type(self.appyType.validator) in (list, tuple)):
         # Generate i18n messages for every possible value if the list
         # of values is fixed.
         for value in self.appyType.validator:
             msgLabel = "%s_%s_list_%s" % (self.classDescr.name, self.fieldName, value)
             poMsg = PoMessage(msgLabel, "", value)
             poMsg.produceNiceDefault()
             self.generator.labels.append(poMsg)
Esempio n. 4
0
 def walkString(self):
     '''How to generate an Appy String?'''
     if self.appyType.isSelect and \
        (type(self.appyType.validator) in (list, tuple)):
         # Generate i18n messages for every possible value if the list
         # of values is fixed.
         for value in self.appyType.validator:
             msgLabel = '%s_%s_list_%s' % (self.classDescr.name,
                                           self.fieldName, value)
             poMsg = PoMessage(msgLabel, '', value)
             poMsg.produceNiceDefault()
             self.generator.labels.append(poMsg)
Esempio n. 5
0
 def produceMessage(self, msgId, isLabel=True):
     '''Gets the default label, description or help (depending on p_msgType)
        for i18n message p_msgId.'''
     default = ' '
     produceNice = False
     if isLabel:
         produceNice = True
         default = self.fieldName
         # Some attributes need a specific predefined message
         if isinstance(self.classDescr, ToolClassDescriptor):
             default = self.getToolFieldMessage(self.fieldName)
             if default != self.fieldName: produceNice = False
     msg = PoMessage(msgId, '', default)
     if produceNice:
         msg.produceNiceDefault()
     return msg
Esempio n. 6
0
 def walkRef(self):
     """How to generate a Ref?"""
     # Update the list of referers
     self.generator.addReferer(self)
     # Add the widget label for the back reference
     back = self.appyType.back
     refClassName = getClassName(self.appyType.klass, self.applicationName)
     if back.hasLabel:
         backLabel = "%s_%s" % (refClassName, self.appyType.back.attribute)
         poMsg = PoMessage(backLabel, "", self.appyType.back.attribute)
         poMsg.produceNiceDefault()
         self.generator.labels.append(poMsg)
     # Add the label for the confirm message if relevant
     if self.appyType.addConfirm:
         label = "%s_%s_addConfirm" % (self.classDescr.name, self.fieldName)
         msg = PoMessage(label, "", PoMessage.CONFIRM)
         self.generator.labels.append(msg)
Esempio n. 7
0
 def produceMessage(self, msgId, isLabel=True):
     """Gets the default label, description or help (depending on p_msgType)
        for i18n message p_msgId."""
     default = " "
     produceNice = False
     if isLabel:
         produceNice = True
         default = self.fieldName
         # Some attributes need a specific predefined message
         if isinstance(self.classDescr, ToolClassDescriptor):
             default = self.getToolFieldMessage(self.fieldName)
             if default != self.fieldName:
                 produceNice = False
     msg = PoMessage(msgId, "", default)
     if produceNice:
         msg.produceNiceDefault()
     return msg
Esempio n. 8
0
 def walkRef(self):
     '''How to generate a Ref?'''
     # Update the list of referers
     self.generator.addReferer(self)
     # Add the widget label for the back reference
     back = self.appyType.back
     refClassName = getClassName(self.appyType.klass, self.applicationName)
     if back.hasLabel:
         backLabel = "%s_%s" % (refClassName, self.appyType.back.attribute)
         poMsg = PoMessage(backLabel, '', self.appyType.back.attribute)
         poMsg.produceNiceDefault()
         self.generator.labels.append(poMsg)
     # Add the label for the confirm message if relevant
     if self.appyType.addConfirm:
         label = '%s_%s_addConfirm' % (self.classDescr.name, self.fieldName)
         msg = PoMessage(label, '', PoMessage.CONFIRM)
         self.generator.labels.append(msg)
Esempio n. 9
0
 def walkPod(self):
     # Add i18n-specific messages
     if self.appyType.askAction:
         label = '%s_%s_askaction' % (self.classDescr.name, self.fieldName)
         msg = PoMessage(label, '', PoMessage.POD_ASKACTION)
         self.generator.labels.append(msg)
         self.classDescr.labelsToPropagate.append(msg)
     # Add the POD-related fields on the Tool
     self.generator.tool.addPodRelatedFields(self)
Esempio n. 10
0
 def generateClass(self, classDescr):
     '''Is called each time an Appy class is found in the application, for
        generating the corresponding Archetype class.'''
     k = classDescr.klass
     print 'Generating %s.%s (gen-class)...' % (k.__module__, k.__name__)
     if not classDescr.isAbstract():
         self.tool.addWorkflowFields(classDescr)
     # Determine base Zope class
     isFolder = classDescr.isFolder()
     baseClass = isFolder and 'Folder' or 'SimpleItem'
     icon = isFolder and 'folder.gif' or 'object.gif'
     parents = 'BaseMixin, %s' % baseClass
     classDoc = classDescr.klass.__doc__ or 'Appy class.'
     repls = self.repls.copy()
     classDescr.generateSchema()
     repls.update({
       'parents': parents, 'className': classDescr.klass.__name__,
       'genClassName': classDescr.name, 'baseMixin':'BaseMixin',
       'classDoc': classDoc, 'applicationName': self.applicationName,
       'methods': classDescr.methods, 'icon':icon})
     fileName = '%s.py' % classDescr.name
     # Create i18n labels (class name and plural form)
     poMsg = PoMessage(classDescr.name, '', classDescr.klass.__name__)
     poMsg.produceNiceDefault()
     self.labels.append(poMsg)
     poMsgPl = PoMessage('%s_plural' % classDescr.name, '',
         classDescr.klass.__name__+'s')
     poMsgPl.produceNiceDefault()
     self.labels.append(poMsgPl)
     # Create i18n labels for searches
     for search in classDescr.getSearches(classDescr.klass):
         searchLabel = '%s_search_%s' % (classDescr.name, search.name)
         labels = [searchLabel, '%s_descr' % searchLabel]
         if search.group:
             grpLabel = '%s_searchgroup_%s' % (classDescr.name, search.group)
             labels += [grpLabel, '%s_descr' % grpLabel]
         for label in labels:
             default = ' '
             if label == searchLabel: default = search.name
             poMsg = PoMessage(label, '', default)
             poMsg.produceNiceDefault()
             if poMsg not in self.labels:
                 self.labels.append(poMsg)
     # Generate the resulting Zope class.
     self.copyFile('Class.pyt', repls, destName=fileName)
Esempio n. 11
0
 def generateWorkflow(self, wfDescr):
     '''This method creates the i18n labels related to the workflow described
        by p_wfDescr.'''
     k = wfDescr.klass
     print 'Generating %s.%s (gen-workflow)...' % (k.__module__, k.__name__)
     # Identify workflow name
     wfName = WorkflowDescriptor.getWorkflowName(wfDescr.klass)
     # Add i18n messages for states
     for name in dir(wfDescr.klass):
         if not isinstance(getattr(wfDescr.klass, name), gen.State): continue
         poMsg = PoMessage('%s_%s' % (wfName, name), '', name)
         poMsg.produceNiceDefault()
         self.labels.append(poMsg)
     # Add i18n messages for transitions
     for name in dir(wfDescr.klass):
         transition = getattr(wfDescr.klass, name)
         if not isinstance(transition, gen.Transition): continue
         if transition.show:
             poMsg = PoMessage('%s_%s' % (wfName, name), '', name)
             poMsg.produceNiceDefault()
             self.labels.append(poMsg)
         if transition.show and transition.confirm:
             # We need to generate a label for the message that will be shown
             # in the confirm popup.
             label = '%s_%s_confirm' % (wfName, name)
             poMsg = PoMessage(label, '', PoMessage.CONFIRM)
             self.labels.append(poMsg)
         if transition.notify:
             # Appy will send a mail when this transition is triggered.
             # So we need 2 i18n labels: one for the mail subject and one for
             # the mail body.
             subjectLabel = '%s_%s_mail_subject' % (wfName, name)
             poMsg = PoMessage(subjectLabel, '', PoMessage.EMAIL_SUBJECT)
             self.labels.append(poMsg)
             bodyLabel = '%s_%s_mail_body' % (wfName, name)
             poMsg = PoMessage(bodyLabel, '', PoMessage.EMAIL_BODY)
             self.labels.append(poMsg)
Esempio n. 12
0
 def generateWorkflow(self, wfDescr):
     '''This method creates the i18n labels related to the workflow described
        by p_wfDescr.'''
     k = wfDescr.klass
     print 'Generating %s.%s (gen-workflow)...' % (k.__module__, k.__name__)
     # Identify workflow name
     wfName = WorkflowDescriptor.getWorkflowName(wfDescr.klass)
     # Add i18n messages for states
     for name in dir(wfDescr.klass):
         if not isinstance(getattr(wfDescr.klass, name), gen.State):
             continue
         poMsg = PoMessage('%s_%s' % (wfName, name), '', name)
         poMsg.produceNiceDefault()
         self.labels.append(poMsg)
     # Add i18n messages for transitions
     for name in dir(wfDescr.klass):
         transition = getattr(wfDescr.klass, name)
         if not isinstance(transition, gen.Transition): continue
         if transition.show:
             poMsg = PoMessage('%s_%s' % (wfName, name), '', name)
             poMsg.produceNiceDefault()
             self.labels.append(poMsg)
         if transition.show and transition.confirm:
             # We need to generate a label for the message that will be shown
             # in the confirm popup.
             label = '%s_%s_confirm' % (wfName, name)
             poMsg = PoMessage(label, '', PoMessage.CONFIRM)
             self.labels.append(poMsg)
         if transition.notify:
             # Appy will send a mail when this transition is triggered.
             # So we need 2 i18n labels: one for the mail subject and one for
             # the mail body.
             subjectLabel = '%s_%s_mail_subject' % (wfName, name)
             poMsg = PoMessage(subjectLabel, '', PoMessage.EMAIL_SUBJECT)
             self.labels.append(poMsg)
             bodyLabel = '%s_%s_mail_body' % (wfName, name)
             poMsg = PoMessage(bodyLabel, '', PoMessage.EMAIL_BODY)
             self.labels.append(poMsg)
Esempio n. 13
0
 def generateClass(self, classDescr):
     '''Is called each time an Appy class is found in the application, for
        generating the corresponding Archetype class.'''
     k = classDescr.klass
     print 'Generating %s.%s (gen-class)...' % (k.__module__, k.__name__)
     if not classDescr.isAbstract():
         self.tool.addWorkflowFields(classDescr)
     # Determine base Zope class
     isFolder = classDescr.isFolder()
     baseClass = isFolder and 'Folder' or 'SimpleItem'
     icon = isFolder and 'folder.gif' or 'object.gif'
     parents = 'BaseMixin, %s' % baseClass
     classDoc = classDescr.klass.__doc__ or 'Appy class.'
     repls = self.repls.copy()
     classDescr.generateSchema()
     repls.update({
         'parents': parents,
         'className': classDescr.klass.__name__,
         'genClassName': classDescr.name,
         'baseMixin': 'BaseMixin',
         'classDoc': classDoc,
         'applicationName': self.applicationName,
         'methods': classDescr.methods,
         'icon': icon
     })
     fileName = '%s.py' % classDescr.name
     # Create i18n labels (class name and plural form)
     poMsg = PoMessage(classDescr.name, '', classDescr.klass.__name__)
     poMsg.produceNiceDefault()
     self.labels.append(poMsg)
     poMsgPl = PoMessage('%s_plural' % classDescr.name, '',
                         classDescr.klass.__name__ + 's')
     poMsgPl.produceNiceDefault()
     self.labels.append(poMsgPl)
     # Create i18n labels for searches
     for search in classDescr.getSearches(classDescr.klass):
         searchLabel = '%s_search_%s' % (classDescr.name, search.name)
         labels = [searchLabel, '%s_descr' % searchLabel]
         if search.group:
             grpLabel = '%s_searchgroup_%s' % (classDescr.name,
                                               search.group)
             labels += [grpLabel, '%s_descr' % grpLabel]
         for label in labels:
             default = ' '
             if label == searchLabel: default = search.name
             poMsg = PoMessage(label, '', default)
             poMsg.produceNiceDefault()
             if poMsg not in self.labels:
                 self.labels.append(poMsg)
     # Generate the resulting Zope class.
     self.copyFile('Class.pyt', repls, destName=fileName)
Esempio n. 14
0
 def walkAppyType(self):
     '''Walks into the Appy type definition and gathers data about the
        i18n labels.'''
     # Manage things common to all Appy types
     # - optional ?
     if self.appyType.optional:
         self.generator.tool.addOptionalField(self)
     # - edit default value ?
     if self.appyType.editDefault:
         self.generator.tool.addDefaultField(self)
     # - put an index on this field?
     if self.appyType.indexed and (self.fieldName != 'title'):
         self.classDescr.addIndexMethod(self)
     # i18n labels
     messages = self.generator.labels
     if not self.appyType.label:
         # Create labels for generating them in i18n files, only if required.
         i18nPrefix = "%s_%s" % (self.classDescr.name, self.fieldName)
         if self.appyType.hasLabel:
             messages.append(self.produceMessage(i18nPrefix))
         if self.appyType.hasDescr:
             descrId = i18nPrefix + '_descr'
             messages.append(self.produceMessage(descrId, isLabel=False))
         if self.appyType.hasHelp:
             helpId = i18nPrefix + '_help'
             messages.append(self.produceMessage(helpId, isLabel=False))
     # Create i18n messages linked to pages and phases, only if there is more
     # than one page/phase for the class.
     ppMsgs = []
     if len(self.classDescr.getPhases()) > 1:
         # Create the message for the name of the phase
         phaseName = self.appyType.page.phase
         msgId = '%s_phase_%s' % (self.classDescr.name, phaseName)
         ppMsgs.append(PoMessage(msgId, '', produceNiceMessage(phaseName)))
     if len(self.classDescr.getPages()) > 1:
         # Create the message for the name of the page
         pageName = self.appyType.page.name
         msgId = '%s_page_%s' % (self.classDescr.name, pageName)
         ppMsgs.append(PoMessage(msgId, '', produceNiceMessage(pageName)))
     for poMsg in ppMsgs:
         if poMsg not in messages:
             messages.append(poMsg)
             self.classDescr.labelsToPropagate.append(poMsg)
     # Create i18n messages linked to groups
     group = self.appyType.group
     if group and not group.label:
         group.generateLabels(messages, self.classDescr, set())
     # Manage things which are specific to String types
     if self.appyType.type == 'String':
         self.walkString()
         # Manage things which are specific to Actions
     elif self.appyType.type == 'Action':
         self.walkAction()
         # Manage things which are specific to Ref types
     elif self.appyType.type == 'Ref':
         self.walkRef()
         # Manage things which are specific to Pod types
     elif self.appyType.type == 'Pod':
         self.walkPod()
         # Manage things which are specific to List types
     elif self.appyType.type == 'List':
         self.walkList()
Esempio n. 15
0
 def walkAction(self):
     '''Generates the i18n-related label.'''
     if self.appyType.confirm:
         label = '%s_%s_confirm' % (self.classDescr.name, self.fieldName)
         msg = PoMessage(label, '', PoMessage.CONFIRM)
         self.generator.labels.append(msg)