class IPSTImportFromEcomptesSchema(model.Schema): ecomptes_xml = schema.Bytes( title=_c(u"XML document exported from eComptes"), description=u'', required=True, )
def handleApply(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage else: try: parsed_xml = self.parse_xml(data) except XMLSyntaxError: IStatusMessage(self.request).addStatusMessage( _c(u'The imported document is not recognized as a valid eComptes export.' ), 'error', ) else: self.update_pst(parsed_xml) IStatusMessage(self.request).addStatusMessage( _c(u'The XML document has been successfully imported.'), 'info', )
class IOperationalObjective(IProject): """ OperationalObjective schema, field ordering """ representative_responsible = LocalRolesField( title=_(u"Representative responsible"), # description=_(u"Choose principals that will be representative responsible for this project."), value_type=schema.Choice( vocabulary= u'imio.project.pst.content.operational.representative_responsible_vocabulary', ), required=True, min_length=1, ) form.widget('representative_responsible', AjaxChosenMultiFieldWidget, populate_select=True) administrative_responsible = LocalRolesField( title=_(u"Administrative responsible"), # description=_(u"Choose principals that will be administrative responsible for this project."), value_type=schema.Choice( vocabulary=u'imio.project.core.content.project.manager_vocabulary', ), required=True, min_length=1, ) form.widget('administrative_responsible', AjaxChosenMultiFieldWidget, populate_select=True) manager = LocalRolesField( title=_c(u"Manager"), # description=_c(u"Choose principals that will manage this project."), value_type=schema.Choice( vocabulary='imio.project.core.content.project.manager_vocabulary'), required=True, min_length=1, ) form.widget('manager', AjaxChosenMultiFieldWidget, populate_select=True)
class IPSTProjectSpace(IProjectSpace): """ PST Project schema """ strategicobjective_fields = schema.List( title=_c(u"${type} fields display", mapping={'type': _('StrategicObjective')}), description=_( u'Warning ! Completion of these fields requires a good knowledge of the TAL language. ' u'Be sure to get help from the product support team.'), required=False, value_type=DictRow(title=_(u'Field'), schema=IStrategicObjectiveFieldsSchema, required=False), ) directives.widget('strategicobjective_fields', DataGridFieldFactory, display_table_css_class='listing', allow_reorder=True, auto_append=False) operationalobjective_fields = schema.List( title=_c(u"${type} fields display", mapping={'type': _('OperationalObjective')}), description=_( u'Warning ! Completion of these fields requires a good knowledge of the TAL language. ' u'Be sure to get help from the product support team.'), required=False, value_type=DictRow(title=_(u'Field'), schema=IOperationalObjectiveFieldsSchema, required=False), ) directives.widget('operationalobjective_fields', DataGridFieldFactory, display_table_css_class='listing', allow_reorder=True, auto_append=False) pstaction_fields = schema.List( title=_c(u"${type} fields display", mapping={'type': _('PSTAction')}), description=_( u'Warning ! Completion of these fields requires a good knowledge of the TAL language. ' u'Be sure to get help from the product support team.'), required=False, value_type=DictRow(title=_(u'Field'), schema=IPSTActionFieldsSchema, required=False), ) directives.widget('pstaction_fields', DataGridFieldFactory, display_table_css_class='listing', allow_reorder=True, auto_append=False) # this field will be hidden pstsubaction_fields = schema.List( title=_c(u"${type} fields display", mapping={'type': _('PSTSubAction')}), required=False, value_type=DictRow(title=_(u'Field'), schema=IPSTActionFieldsSchema, required=False), ) directives.widget('pstsubaction_fields', DataGridFieldFactory, display_table_css_class='listing', allow_reorder=True, auto_append=False) strategicobjectives_columns = schema.List( title=_(u"StrategicObjective columns"), # description=_c(u'Put fields on the right to display it. Flags are : ...'), value_type=schema.Choice( vocabulary=StrategicObjectivesColumnsVocabulary), ) operationalobjectives_columns = schema.List( title=_(u"OperationalObjective columns"), # description=_c(u'Put fields on the right to display it. Flags are : ...'), value_type=schema.Choice( vocabulary=OperationalObjectivesColumnsVocabulary), ) pstactions_columns = schema.List( title=_(u"PSTAction columns"), # description=_c(u'Put fields on the right to display it. Flags are : ...'), value_type=schema.Choice(vocabulary=PstactionColumnsVocabulary), ) tasks_columns = schema.List( title=_(u"Tasks columns"), # description=_c(u'Put fields on the right to display it. Flags are : ...'), value_type=schema.Choice(vocabulary=TasksColumnsVocabulary), ) strategicobjective_budget_states = schema.List( title=_c(u"${type} budget globalization states", mapping={'type': _('StrategicObjective')}), description=_c( u'Put states on the right for which you want to globalize budget fields.' ), required=False, value_type=schema.Choice( vocabulary=u'imio.project.pst.SOReviewStatesVocabulary'), ) operationalobjective_budget_states = schema.List( title=_c(u"${type} budget globalization states", mapping={'type': _('OperationalObjective')}), # description=_c(u'Put states on the right for which you want to globalize budget fields.'), required=False, value_type=schema.Choice( vocabulary=u'imio.project.pst.OOReviewStatesVocabulary'), ) pstaction_budget_states = schema.List( title=_c(u"${type} budget globalization states", mapping={'type': _('PSTAction')}), # description=_c(u'Put states on the right for which you want to globalize budget fields.'), required=False, value_type=schema.Choice( vocabulary=u'imio.project.pst.PSTActionReviewStatesVocabulary'), ) # this field will be hidden pstsubaction_budget_states = schema.List( title=_c(u"${type} budget globalization states", mapping={'type': _('PSTSubAction')}), # description=_c(u'Put states on the right for which you want to globalize budget fields.'), required=False, value_type=schema.Choice( vocabulary=u'imio.project.pst.PSTActionReviewStatesVocabulary'), ) directives.omitted('project_fields') directives.omitted('project_budget_states') # when pstaction_fields modified pstsubaction_fields is updated with his values directives.omitted('pstsubaction_fields') directives.omitted('pstsubaction_budget_states') @invariant def validateSettings(data): mandatory_check(data, field_constraints) position_check(data, field_constraints)
'strategicobjective': [('IDublinCore.title', 1)], 'operationalobjective': [('IDublinCore.title', 1)], 'pstaction': [('IDublinCore.title', 1)], }, 'empty': { 'strategicobjective': [], 'operationalobjective': [], 'pstaction': [], }, } StrategicObjectivesColumnsVocabulary = SimpleVocabulary([ SimpleTerm(value=u'select_row', title=_z(u'select_row')), SimpleTerm(value=u'pretty_link', title=_z(u'pretty_link')), SimpleTerm(value=u'review_state', title=_z(u'header_review_state')), SimpleTerm(value=u'categories', title=_c(u'Categories')), SimpleTerm(value=u'CreationDate', title=_z(u'header_CreationDate')), SimpleTerm(value=u'ModificationDate', title=_z(u'header_ModificationDate')), SimpleTerm(value=u'history_actions', title=_z(u'history_actions')) ]) OperationalObjectivesColumnsVocabulary = SimpleVocabulary([ SimpleTerm(value=u'select_row', title=_z(u'select_row')), SimpleTerm(value=u'pretty_link', title=_z(u'pretty_link')), SimpleTerm(value=u'parents', title=_z(u'header_parents')), SimpleTerm(value=u'review_state', title=_z(u'header_review_state')), SimpleTerm(value=u'manager', title=_z(u'header_manager')), SimpleTerm(value=u'planned_end_date', title=_z(u'header_planned_end_date')), SimpleTerm(value=u'priority', title=_z(u'header_priority')),
class PSTImportFromEcomptes(Form): label = _c(u"Import data from eComptes") fields = Fields(IPSTImportFromEcomptesSchema) ignoreContext = True def parse_xml(self, data): schema_file_path = dirname( __file__) + '/../model/PST_eComptes_Export_201805V1.xsd' schema_root = etree.parse(open(schema_file_path, 'rb')) schema = etree.XMLSchema(schema_root) parser = etree.XMLParser(schema=schema) raw_xml = data.get('ecomptes_xml') parsed_xml = etree.fromstring( raw_xml, parser) # if invalid, raises XMLSyntaxError return parsed_xml def update_pst(self, ecomptes_xml): modifications = {} all_articles_xml = ecomptes_xml.findall('.//Articles') for articles_xml in all_articles_xml: if not articles_xml.getchildren(): continue element_xml = articles_xml.getparent() uid = element_xml.get('ElementId') element_dx = api.content.get(UID=uid) if element_dx: element_dx_articles = [] for article_xml in articles_xml: year = int(article_xml.xpath("Exercice/text()")[0]) # elementtree must be encoded and decoded to get unicode and not object service = article_xml.xpath("Service/text()")[0].encode( 'utf8').decode('utf8') btype = article_xml.xpath("Type/text()")[0].encode( 'utf8').decode('utf8') article = article_xml.xpath( "CodeArticle/text()")[0].encode('utf8').decode('utf8') title = article_xml.xpath("Libelle/text()")[0].encode( 'utf8').decode('utf8') amount = float(article_xml.xpath("Montant/text()")[0]) element_dx_articles.append({ 'year': year, 'service': service, 'btype': btype, 'article': article, 'title': title, 'amount': amount, # 'comment': u'', Removed from schema }) element_dx.analytic_budget = sorted( element_dx_articles, cmp=lambda x, y: cmp( (x['year'], y['service'], y['btype'], x['article']), (y['year'], x['service'], x['btype'], y['article']))) modifications[element_dx.absolute_url_path()] = element_dx all_projections_xml = ecomptes_xml.findall('.//Projections') for projections_xml in all_projections_xml: if not projections_xml.getchildren(): continue element_xml = projections_xml.getparent() uid = element_xml.get('ElementId') element_dx = api.content.get(UID=uid) if element_dx: projections = [] for projection_xml in projections_xml: # elementtree must be encoded and decoded to get unicode and not object service = projection_xml.xpath("Service/text()")[0].encode( 'utf8').decode('utf8') btype = projection_xml.xpath("Type/text()")[0].encode( 'utf8').decode('utf8') group = projection_xml.xpath("GroupeEco/text()")[0].encode( 'utf8').decode('utf8') title = projection_xml.xpath("Libelle/text()")[0].encode( 'utf8').decode('utf8') exercices_xml = projection_xml.find('.//Exercices') for exercice_xml in exercices_xml or []: year = int(exercice_xml.get('Valeur')) amount = float(exercice_xml.xpath("Montant/text()")[0]) projections.append({ 'service': service, 'btype': btype, 'group': group, 'title': title, 'year': year, 'amount': amount, }) element_dx.projection = projections modifications[element_dx.absolute_url_path()] = element_dx for path in reversed(modifications.keys()): modified(modifications[path]) @button.buttonAndHandler(_c(u'Import'), name='import') def handleApply(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage else: try: parsed_xml = self.parse_xml(data) except XMLSyntaxError: IStatusMessage(self.request).addStatusMessage( _c(u'The imported document is not recognized as a valid eComptes export.' ), 'error', ) else: self.update_pst(parsed_xml) IStatusMessage(self.request).addStatusMessage( _c(u'The XML document has been successfully imported.'), 'info', )