def generateWorkflow(self, wfDescr): '''This method does not generate the workflow definition, which is done in self.generateWorkflows. This method just 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 Plone workflow name wfName = WorkflowDescriptor.getWorkflowName(wfDescr.klass) # Add i18n messages for states and transitions for sName in wfDescr.getStateNames(): poMsg = PoMessage('%s_%s' % (wfName, sName), '', sName) poMsg.produceNiceDefault() self.labels.append(poMsg) for tName, tLabel in wfDescr.getTransitionNames(withLabels=True): poMsg = PoMessage('%s_%s' % (wfName, tName), '', tLabel) poMsg.produceNiceDefault() self.labels.append(poMsg) for transition in wfDescr.getTransitions(): if transition.notify: # Appy will send a mail when this transition is triggered. # So we need 2 i18n labels for every DC transition corresponding # to this Appy transition: one for the mail subject and one for # the mail body. tName = wfDescr.getNameOf(transition) # Appy name tNames = wfDescr.getTransitionNamesOf(tName, transition) # DC # name(s) for tn in tNames: subjectLabel = '%s_%s_mail_subject' % (wfName, tn) poMsg = PoMessage(subjectLabel, '', PoMessage.EMAIL_SUBJECT) self.labels.append(poMsg) bodyLabel = '%s_%s_mail_body' % (wfName, tn) poMsg = PoMessage(bodyLabel, '', PoMessage.EMAIL_BODY) self.labels.append(poMsg)
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)
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
def walkRef(self): '''How to generate a Ref?''' relationship = '%s_%s_rel' % (self.classDescr.name, self.fieldName) self.fieldType = 'ReferenceField' self.widgetType = 'ReferenceWidget' self.fieldParams['relationship'] = relationship if self.appyType.isMultiValued(): self.fieldParams['multiValued'] = True # Update the list of referers self.generator.addReferer(self, relationship) # Add the widget label for the back reference refClassName = getClassName(self.appyType.klass, self.applicationName) 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)
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), 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, Transition): continue poMsg = PoMessage('%s_%s' % (wfName, name), '', name) poMsg.produceNiceDefault() self.labels.append(poMsg) if 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)
def generateClass(self, classDescr): '''Is called each time an Appy class is found in the application, for generating the corresponding Archetype class and schema.''' k = classDescr.klass print 'Generating %s.%s (gen-class)...' % (k.__module__, k.__name__) if not classDescr.isAbstract(): self.tool.addWorkflowFields(classDescr) # Determine base archetypes schema and class baseClass = 'BaseContent' baseSchema = 'BaseSchema' if classDescr.isFolder(): baseClass = 'OrderedBaseFolder' baseSchema = 'OrderedBaseFolderSchema' parents = ['BaseMixin', baseClass] imports = [] implements = [baseClass] for baseClass in classDescr.klass.__bases__: if self.determineAppyType(baseClass) == 'class': bcName = getClassName(baseClass) parents.remove('BaseMixin') parents.insert(0, bcName) implements.append(bcName) imports.append('from %s import %s' % (bcName, bcName)) baseSchema = '%s.schema' % bcName break parents = ','.join(parents) implements = '+'.join(['(getattr(%s,"__implements__",()),)' % i \ for i in implements]) classDoc = classDescr.klass.__doc__ if not classDoc: classDoc = 'Class generated with appy.gen.' # If the class is abstract I will not register it register = "registerType(%s, '%s')" % (classDescr.name, self.applicationName) if classDescr.isAbstract(): register = '' repls = self.repls.copy() classDescr.generateSchema() repls.update({ 'imports': '\n'.join(imports), 'parents': parents, 'className': classDescr.klass.__name__, 'global_allow': 1, 'genClassName': classDescr.name, 'baseMixin':'BaseMixin', 'classDoc': classDoc, 'applicationName': self.applicationName, 'fields': classDescr.schema, 'methods': classDescr.methods, 'implements': implements, 'baseSchema': baseSchema, 'static': '', 'register': register, 'toolInstanceName': self.toolInstanceName}) fileName = '%s.py' % classDescr.name # Create i18n labels (class name, description and plural form) poMsg = PoMessage(classDescr.name, '', classDescr.klass.__name__) poMsg.produceNiceDefault() self.labels.append(poMsg) poMsgDescr = PoMessage('%s_edit_descr' % classDescr.name, '', ' ') self.labels.append(poMsgDescr) 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 Archetypes class and schema. self.copyFile('Class.py', repls, destName=fileName)