Por nada! Fico feliz que funcionou :)


Em seg, 11 de mar de 2019 às 18:09, Alexandre Chagas <
alexandre....@gmail.com> escreveu:

> Obrigado Davi, alem de esclarecer e ter funcionado... Muito rico esses
> links, entendi a mudança e mais uma vez obrigado :D
>
> Em seg, 11 de mar de 2019 às 12:02, Davi Lima <davili...@gmail.com>
> escreveu:
>
>> No Dexterity, alguns campos não vivem diretamente na classe do tipo de
>> conteúdo, em vez disso tal código é compartilhado por múltiplos tipos de
>> conteúdo através dos Behaviors, que adaptam a classe base para prover novas
>> funcionalidades.
>>
>> Por esse motivo, no caso do corpo do texto, não se usa mais o setText no
>> objeto de conteúdo, em vez disso você precisa fazer algo como:
>>
>> from plone.app.textfield import RichTextValue
>> nn.text = RichTextValue(variavelComSeuTexto, 'text/html', 'text/html')
>>
>>
>> Veja esta issue: https://github.com/plone/plone.api/issues/300
>>
>> Para saber quais campos vêm de onde, veja
>> https://docs.plone.org/external/plone.app.dexterity/docs/reference/fields.html
>>
>> E aqui para entender melhor o RichTextValue:
>> https://docs.plone.org/external/plone.app.dexterity/docs/advanced/rich-text-markup-transformations.html
>>
>> []s
>> Davi
>>
>> Em seg, 11 de mar de 2019 às 15:35, Alexandre Chagas <
>> alexandre....@gmail.com> escreveu:
>>
>>> Pessoal,
>>>
>>> Estou fazendo uma carga de dados lendo um arquivo CSV com External
>>> Methods.
>>>
>>> Nas versões SEM o IDG o script funcionou perfeitamente, O problema é
>>> quando tento rodar com o IDG instalado.
>>>
>>> Um colega da lista esclareceu que alguns métodos não são mais utilizados
>>> com as novas versões de tipos Dexterity.
>>>
>>> A exemplo? setCreationDate fora substituído por “creation_date”,
>>> funcionou perfeitamente, mas continuo com o mesmo problema para carregar o
>>> corpo de texto, “setText”
>>>
>>> Executando no modo debug (Plone+IDG), aparece apenas erro de atributo:
>>>
>>> >>>
>>> 2019-03-11 11:13:30 ERROR Zope.SiteErrorLog 1552313610.660.354521920732
>>> http://10.1.10.26:8082/portal/ANA/noticias-antigas/migrarnoticias
>>>
>>> Traceback (innermost last):
>>>   Module ZPublisher.Publish, line 138, in publish
>>>   Module ZPublisher.mapply, line 77, in mapply
>>>   Module ZPublisher.Publish, line 48, in call_object
>>>   Module Products.ExternalMethod.ExternalMethod, line 237, in __call__
>>>    - __traceback_info__: ((<Folder at /portal/ANA/noticias-antigas>,),
>>> {}, None)
>>>   Module
>>> /opt/Plone-4.3.11-portal-ana/zeocluster/parts/client1/Extensions/importcsv3.py,
>>> line 49, in import_data
>>>
>>> AttributeError: setText
>>>
>>> <<<<
>>>
>>> Estudando a classe “DexterityContent”, vi o “format” como possível
>>> substituto para “setText”. Apesar do código rodar sem erros, o corpo de
>>> texto não é carregado.
>>>
>>> ///
>>>
>>> class DexterityContent(DAVResourceMixin, PortalContent, PropertyManager,
>>> Contained):
>>>     """Base class for Dexterity content    """
>>> .......
>>>     title = u''
>>>     description = u''
>>>     subject = ()
>>>     creators = ()
>>>     contributors = ()
>>>     effective_date = None
>>>     expiration_date = None
>>>     format = 'text/html'
>>>     language = ''
>>>     rights = ''
>>>
>>> ///
>>>
>>> Meu código, tosco e de iniciante é este:
>>>
>>> import csv, sys, string, re
>>> from DateTime import DateTime
>>> from zope.component import queryUtility, createObject
>>> from plone.i18n.normalizer.interfaces import IIDNormalizer
>>>
>>> def import_data(self):
>>>
>>>      reader = csv.reader(open('/tmp/noticias5.csv'), delimiter=';',
>>> quotechar='"', doublequote=$
>>>      fim = "fim."
>>>      quant = 0
>>>
>>>      for row in reader:
>>>            if row[0] != 'id':
>>>               id = self.generateUniqueId('Document')
>>>               stat=row
>>>               self.invokeFactory('Document', id)
>>>               nn = getattr(self, id)
>>>               x_titulo = row[1]
>>>               print x_titulo
>>>               data = row[3]
>>>               print data
>>>               dia = str(int(data[:2]))
>>>               if int(dia) < 10:
>>>                  dia = "0"+dia
>>>               mes = str(int(data[3:5]))
>>>               if int(mes) < 10:
>>>                  mes = "0"+mês
>>>               ano = str(int(data[6:10]))
>>>               datafinal = ano+"/"+mes+"/"+dia
>>>               print datafinal
>>>               autor = row[5]
>>>               if autor == "":
>>>                  autor = "ASCOM/ANA"
>>>               nn.setCreators(autor)
>>>               texto = row[6]
>>>               nn.setEffectiveDate(DateTime(datafinal))
>>>               nn.setModificationDate(DateTime(row[4]))
>>>               nn.creation_date = DateTime(row[3])
>>>               nn.setTitle(row[1])
>>>               nn.setDescription(row[2])
>>>               nn.setFormat(texto)
>>>
>>> #              nn.format = texto
>>> #              nn.setText(row[6])
>>> #              nn.setText(row[6], mimetype='text/html')
>>>               nn.portal_workflow.doActionFor(nn,"publish", comment="")
>>>               nn.reindexObject()
>>>               quant = quant + 1
>>>               print quant
>>>      return fim
>>>
>>>
>>>
>>> Por favor, alguém poderia apontar onde estou errando?
>>>
>>> Pois não estou conseguindo carregar o corpo de texto.
>>>
>>> Em sex, 8 de mar de 2019 às 14:39, Davi Lima <davili...@gmail.com>
>>> escreveu:
>>>
>>>> Por nada.
>>>>
>>>> Você pode inspecionar os objetos fazendo:
>>>>
>>>> ./bin/instance debug
>>>>
>>>> Em seguida, por exemplo:
>>>>
>>>> portal = app['Plone']
>>>> fp = portal['front-page']
>>>> [x for x in dir(fp) if x.startswith('set')]
>>>> help(fp.setFormat)
>>>>
>>>> Mais infos em:
>>>>
>>>>    - https://docs.plone.org/develop/plone/misc/commandline.html
>>>>
>>>> []s
>>>> Davi
>>>>
>>>> Em qui, 7 de mar de 2019 às 20:05, Alexandre Chagas <
>>>> alexandre....@gmail.com> escreveu:
>>>>
>>>>> Obrigado Davi ;)
>>>>>
>>>>> Em qui, 7 de mar de 2019 às 15:48, Davi Lima <davili...@gmail.com>
>>>>> escreveu:
>>>>>
>>>>>> Para simplificar, o metodo setCreationDate foi removido em tipos
>>>>>> Dexterity. Tente alterar diretamente:
>>>>>>
>>>>>> *nn.creation_date = DateTime(row[3])*
>>>>>>
>>>>>> []s
>>>>>> Davi
>>>>>>
>>>>>> Em qui, 7 de mar de 2019 às 18:53, Alexandre Chagas <
>>>>>> alexandre....@gmail.com> escreveu:
>>>>>>
>>>>>>> Olá Pessoal,
>>>>>>>
>>>>>>> Estou fazendo uma migração de registros por meio de um arquivo CSV,
>>>>>>> e está acontecendo algo que não tem lógica.
>>>>>>>
>>>>>>> O mesmo código Python com “External Methods” funciona numa
>>>>>>> instalação e na outra aparece erro de atributo. Por favor, se alguém 
>>>>>>> puder
>>>>>>> apontar onde estou errando!
>>>>>>>
>>>>>>> Meu código é este: (não reparem o código super tosco, mas foi aonde
>>>>>>> consegui chegar sem saber python)
>>>>>>>
>>>>>>>
>>>>>>> *import csv, sys, string, re*
>>>>>>> *from DateTime import DateTime*
>>>>>>> *from zope.component import queryUtility, createObject*
>>>>>>> *from plone.i18n.normalizer.interfaces import IIDNormalizer*
>>>>>>> *def import_data(self):*
>>>>>>> *     reader = csv.reader(open('/tmp/noticias5000-v2-completo.csv'),
>>>>>>> delimiter=';', quotechar='"', doublequote=Fa$*
>>>>>>> *     fim = "fim."*
>>>>>>> *     quant = 0*
>>>>>>> *     for row in reader:*
>>>>>>> *           if row[0] != 'id':*
>>>>>>> *              id = self.generateUniqueId('Document')*
>>>>>>> *              stat=row*
>>>>>>> *              self.invokeFactory('Document', id)*
>>>>>>> *              nn = getattr(self, id)*
>>>>>>>
>>>>>>> *              x_titulo = row[1]*
>>>>>>> *              print x_titulo*
>>>>>>>
>>>>>>> *              data = row[3]*
>>>>>>> *              print data*
>>>>>>> *              dia = str(int(data[:2]))*
>>>>>>> *              if int(dia) < 10:*
>>>>>>> *                 dia = "0"+dia*
>>>>>>> *              mes = str(int(data[3:5]))*
>>>>>>> *              if int(mes) < 10:*
>>>>>>> *                 mes = "0"+mes*
>>>>>>> *              ano = str(int(data[6:10]))*
>>>>>>> *              datafinal = ano+"/"+mes+"/"+dia*
>>>>>>> *              print datafinal*
>>>>>>>
>>>>>>> *              autor = row[5]*
>>>>>>> *              if autor == "":*
>>>>>>> *                 autor = "ASCOM/ANA"*
>>>>>>>
>>>>>>> *              nn.setCreators(autor)*
>>>>>>> *              nn.setEffectiveDate(DateTime(datafinal))*
>>>>>>> *              nn.setModificationDate(DateTime(row[4]))*
>>>>>>> *              nn.setCreationDate(DateTime(row[3]))*
>>>>>>> *              nn.setTitle(row[1])*
>>>>>>> *              nn.setDescription(row[2])*
>>>>>>> *              nn.setText(row[6])*
>>>>>>> *              nn.portal_workflow.doActionFor(nn,"publish",
>>>>>>> comment="")*
>>>>>>> *              nn.reindexObject()*
>>>>>>>
>>>>>>> *              quant = quant + 1*
>>>>>>> *              print quant*
>>>>>>> *     return fim*
>>>>>>>
>>>>>>> *Na versão Plone, sem o IDG consigo efetuar a migração de dados.Sem
>>>>>>> erro algum, *
>>>>>>>
>>>>>>> *Versão*
>>>>>>> *• Plone 4.3.18 (4320)*
>>>>>>> *• CMF 2.2.10*
>>>>>>> *• Zope 2.13.28*
>>>>>>> *• Python 2.7.12 (default, Feb 7 2019, 11:36:40) [GCC 4.7.2]*
>>>>>>> *• PIL 3.3.1 (Pillow)*
>>>>>>>
>>>>>>> *E nessa versão Plone com o IDG, aparece erro de parâmetro:*
>>>>>>> *Versão*
>>>>>>> *. Portal Padrão 1.1.5.1*
>>>>>>> *. Plone 4.3.9 (4313)*
>>>>>>> *. CMF 2.2.9*
>>>>>>> *. Zope 2.13.24*
>>>>>>> *. Python 2.7.12 (default, Jul 27 2017, 09:49:26) [GCC 4.7.2]*
>>>>>>> *. PIL 3.3.1 (Pillow)*
>>>>>>>
>>>>>>> MSG DE ERRO:
>>>>>>>
>>>>>>> 2019-03-07 14:21:48 ERROR Zope.SiteErrorLog
>>>>>>> 1551979308.610.397350171831
>>>>>>> http://10.1.10.26:8082/portal/ANA/noticias-antigas/migrarnoticias
>>>>>>> Traceback (innermost last):
>>>>>>>   Module ZPublisher.Publish, line 138, in publish
>>>>>>>   Module ZPublisher.mapply, line 77, in mapply
>>>>>>>   Module ZPublisher.Publish, line 48, in call_object
>>>>>>>   Module Products.ExternalMethod.ExternalMethod, line 237, in
>>>>>>> __call__
>>>>>>>    - __traceback_info__: ((<Folder at
>>>>>>> /portal/ANA/noticias-antigas>,), {}, None)
>>>>>>>   Module
>>>>>>> /opt/Plone-4.3.11-portal-ana/zeocluster/parts/client1/Extensions/importcsv3.py,
>>>>>>> line 43, in import_data
>>>>>>> AttributeError: setCreationDate
>>>>>>> ///
>>>>>>>
>>>>>>> O que pode estar acontecendo? Agradeço muito qualquer ajuda.
>>>>>>>
>>>>>>> --
>>>>>>> *Alexandre Chagas*
>>>>>>>
>>>>>>> --
>>>>>>> Comunidade Plone no Governo
>>>>>>> Site: http://www.softwarelivre.gov.br/plone
>>>>>>> Wiki: http://colab.interlegis.leg.br/wiki/PloneGovBr
>>>>>>> Histórico:
>>>>>>> http://colab.interlegis.leg.br/search/?type=thread&order=latest&list=plonegov-br
>>>>>>> Lista: https://listas.interlegis.gov.br/mailman/listinfo/plonegov-br
>>>>>>
>>>>>> --
>>>>>> Comunidade Plone no Governo
>>>>>> Site: http://www.softwarelivre.gov.br/plone
>>>>>> Wiki: http://colab.interlegis.leg.br/wiki/PloneGovBr
>>>>>> Histórico:
>>>>>> http://colab.interlegis.leg.br/search/?type=thread&order=latest&list=plonegov-br
>>>>>> Lista: https://listas.interlegis.gov.br/mailman/listinfo/plonegov-br
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> *Alexandre Chagas*
>>>>>
>>>>> --
>>>>> Comunidade Plone no Governo
>>>>> Site: http://www.softwarelivre.gov.br/plone
>>>>> Wiki: http://colab.interlegis.leg.br/wiki/PloneGovBr
>>>>> Histórico:
>>>>> http://colab.interlegis.leg.br/search/?type=thread&order=latest&list=plonegov-br
>>>>> Lista: https://listas.interlegis.gov.br/mailman/listinfo/plonegov-br
>>>>
>>>> --
>>>> Comunidade Plone no Governo
>>>> Site: http://www.softwarelivre.gov.br/plone
>>>> Wiki: http://colab.interlegis.leg.br/wiki/PloneGovBr
>>>> Histórico:
>>>> http://colab.interlegis.leg.br/search/?type=thread&order=latest&list=plonegov-br
>>>> Lista: https://listas.interlegis.gov.br/mailman/listinfo/plonegov-br
>>>
>>>
>>>
>>> --
>>> *Alexandre Chagas*
>>>
>>> --
>>> Comunidade Plone no Governo
>>> Site: http://www.softwarelivre.gov.br/plone
>>> Wiki: http://colab.interlegis.leg.br/wiki/PloneGovBr
>>> Histórico:
>>> http://colab.interlegis.leg.br/search/?type=thread&order=latest&list=plonegov-br
>>> Lista: https://listas.interlegis.gov.br/mailman/listinfo/plonegov-br
>>
>> --
>> Comunidade Plone no Governo
>> Site: http://www.softwarelivre.gov.br/plone
>> Wiki: http://colab.interlegis.leg.br/wiki/PloneGovBr
>> Histórico:
>> http://colab.interlegis.leg.br/search/?type=thread&order=latest&list=plonegov-br
>> Lista: https://listas.interlegis.gov.br/mailman/listinfo/plonegov-br
>
>
>
> --
> *Alexandre Chagas*
>
> --
> Comunidade Plone no Governo
> Site: http://www.softwarelivre.gov.br/plone
> Wiki: http://colab.interlegis.leg.br/wiki/PloneGovBr
> Histórico:
> http://colab.interlegis.leg.br/search/?type=thread&order=latest&list=plonegov-br
> Lista: https://listas.interlegis.gov.br/mailman/listinfo/plonegov-br
-- 
Comunidade Plone no Governo
Site: http://www.softwarelivre.gov.br/plone
Wiki: http://colab.interlegis.leg.br/wiki/PloneGovBr
Histórico: 
http://colab.interlegis.leg.br/search/?type=thread&order=latest&list=plonegov-br
Lista: https://listas.interlegis.gov.br/mailman/listinfo/plonegov-br

Responder a