Commit 26e3c68b authored by Arnaud Fontaine's avatar Arnaud Fontaine

ZODB Components: Preparation of erp5_base migration from FS: Fix pylint...

ZODB Components: Preparation of erp5_base migration from FS: Fix pylint no-name-in-module on newTempXXX (04b49859).
parent 062d17ca
......@@ -16,8 +16,8 @@ if exchange_line.getBasePrice() in (None, 0, 0.0):
# We have to looking for other currency exchanges lines
# Note: SupplyCell is the class of Currency Exchange Line portal type objects
# But in reality, anything should do.
from Products.ERP5Type.Document import newTempSupplyCell as newTemp
temp_object = newTemp(context.getPortalObject(),'temp_object')
temp_object = context.getPortalObject().newContent(temp_object=True,
portal_type='Supply Cell', id='temp_object')
start_date = exchange_line.getStartDate()
temp_kw = {'category_list':['resource/%s' % exchange_line.getParentValue().getRelativeUrl(),
'price_currency/%s' % exchange_line.getPriceCurrency()],
......
......@@ -26,11 +26,10 @@ if to_currency is not None:
if start_date is None:
from DateTime import DateTime
start_date = DateTime()
from Products.ERP5Type.Document import newTempBase
# Note: SupplyCell is the class of Currency Exchange Line portal type objects
# But in reality, anything should do.
from Products.ERP5Type.Document import newTempSupplyCell as newTemp
temp_object = newTemp(context.getPortalObject(),'temp_object')
temp_object = context.getPortalObject().newContent(temp_object=True,
portal_type='Supply Cell', id='temp_object')
temp_kw = {'category_list':['resource/%s' % from_currency,
'price_currency/%s' % to_currency],
'start_date':start_date
......
from Products.ERP5Type.Document import newTempFile
from Products.ERP5OOo.OOoUtils import OOoParser
import string
......@@ -16,8 +15,8 @@ def getSpreadsheet(file):
if not (content_type.startswith('application/vnd.sun.xml')
or content_type.startswith('application/vnd.oasis.opendocument')):
from Products.ERP5Type.Document import newTempOOoDocument
tmp_ooo = newTempOOoDocument(context, file.filename)
tmp_ooo = context.newContent(temp_object=True, portal_type='OOo Document',
id=file.filename)
tmp_ooo.edit(data=file.read(), content_type=content_type)
tmp_ooo.convertToBaseFormat()
ignored, import_file_content = tmp_ooo.convert('ods')
......@@ -51,7 +50,7 @@ if len(listbox) == 0:
# Start a session and store the content of the file
session_id = context.browser_id_manager.getBrowserId(create=1)
session = context.portal_sessions[session_id]
temp_file = newTempFile(context, session_id)
temp_file = context.newContent(temp_object=True, portal_type='File', id=session_id)
temp_file.edit(spreadsheet_mapping=spreadsheets)
#create a temporary file_name
......
......@@ -290,9 +290,6 @@ def TestResult_sendEmailNotification(self, mail_to=None, mail_from=None,
extend_attachment(tb.splitlines())
extend_attachment(tb_list[-1].split(END)[0].splitlines())
from Products.ERP5Type.Document import newTempUrl
send_mail = newTempUrl(self, '_').send
attachment_list = []
if traceback_attachment:
if include_diff:
......@@ -318,6 +315,7 @@ def TestResult_sendEmailNotification(self, mail_to=None, mail_from=None,
mime_type='text/plain',
content=content))
send_mail = self.newContent(temp_object=True, portal_type='Url', id='_').send
for mail_to in mail_to_list:
send_mail(from_url=mail_from,
to_url=mail_to,
......
......@@ -240,8 +240,7 @@ class File(Document, CMFFile):
content_type.startswith("image/"):
# The file should behave like it is an Image for convert
# the content to target format.
from Products.ERP5Type.Document import newTempImage
return newTempImage(self, self.getId(),
return self.newContent(temp_object=True, portal_type='Image', id=self.getId(),
data=self.getData(),
content_type=content_type,
filename=self.getFilename())._convert(format, **kw)
......
......@@ -604,7 +604,6 @@ class PDFTypeInformation(ERP5TypeInformation):
"""
Returns the background image for a given page
"""
from Products.ERP5Type.Document import newTempImage
import_pdf_file = self.getDefaultPdfFormValue()
#depend on preferences, best xlargeheight = 1131
mime, image_data = import_pdf_file.convert(format = 'jpg',
......@@ -614,7 +613,8 @@ class PDFTypeInformation(ERP5TypeInformation):
display = 'xlarge')
if image_data is None:
return
page_image = newTempImage(self, "page_%s" % page)
page_image = self.newContent(temp_object=True, portal_type='Image',
id="page_%s" % page)
page_image.setData(image_data)
self.REQUEST.RESPONSE.setHeader('Content-Type', mime)
return page_image
......
......@@ -280,9 +280,8 @@ class ExplanationCache:
# asComposedDocument() and business_process.getParentValue() is not a
# module where newContent() allows creation of Business Processes.
# XXX-JPS is this really OK with union business processes
from Products.ERP5Type.Document import newTempBusinessProcess
new_business_process = newTempBusinessProcess(
self.explanation, 'closure_business_process')
new_business_process = self.explanation.newContent(temp_object=True,
portal_type='Business Process', id='closure_business_process')
for i, x in enumerate(business_link_list):
id = 'closure_path_%s' % i
new_business_process._setOb(id, x.asContext(id=id))
......@@ -302,8 +301,8 @@ class ExplanationCache:
return new_business_process
# Build Union Business Process
from Products.ERP5Type.Document import newTempBusinessProcess
new_business_process = newTempBusinessProcess(self.explanation, 'union_business_process')
new_business_process = self.explanation.newContent(temp_object=True,
portal_type='Business Process', id='union_business_process')
i = 0
for business_link in self.getBusinessLinkValueList():
i += 1
......
......@@ -273,9 +273,8 @@ class DomainTool(BaseTool):
mapped_value = None
else:
# Generate tempDeliveryCell
from Products.ERP5Type.Document import newTempSupplyCell
mapped_value = newTempSupplyCell(self.getPortalObject(),
'new_mapped_value')
mapped_value = self.getPortalObject().newContent(temp_object=True,
portal_type='Supply Cell', id='new_mapped_value')
mapped_value_property_dict = {}
# Look for each property the first predicate which defines the
# property
......@@ -318,7 +317,6 @@ class DomainTool(BaseTool):
if predicate_list is None:
predicate_list = self.searchPredicateList(context, test=test, **kw)
if predicate_list:
from Products.ERP5Type.Document import newTempSupplyCell
mapped_value_property_dict = defaultdict(list)
# Look for each property the first predicate with unique criterion
# categories which defines the property
......@@ -327,8 +325,8 @@ class DomainTool(BaseTool):
value = predicate.getProperty(mapped_value_property)
if value is not None:
mapped_value_property_dict[mapped_value_property].append(value)
mapped_value = newTempSupplyCell(self.getPortalObject(),
'multivalued_mapped_value')
mapped_value = self.getPortalObject().newContent(temp_object=True,
portal_type='Supply Cell', id='multivalued_mapped_value')
mapped_value._setMappedValuePropertyList(
mapped_value_property_dict.keys())
mapped_value.__dict__.update(mapped_value_property_dict)
......
......@@ -597,8 +597,8 @@ class TestBase(ERP5TypeTestCase, ZopeTestCase.Functional):
Create a temp object_instance which will be tested.
"""
portal = self.getPortal()
from Products.ERP5Type.Document import newTempOrganisation
tmp_object = newTempOrganisation(portal, "a_wonderful_id")
tmp_object = portal.newContent(temp_object=True,
portal_type='Organisation', id="a_wonderful_id")
sequence.edit(
object_instance=tmp_object,
current_title='',
......@@ -635,8 +635,8 @@ class TestBase(ERP5TypeTestCase, ZopeTestCase.Functional):
Create a temp object_instance which will be tested.
"""
portal = self.getPortal()
from Products.ERP5Type.Document import newTempAmount
tmp_object = newTempAmount(portal, "another_wonderful_id")
tmp_object = portal.newContent(temp_object=True, portal_type='Amount',
id="another_wonderful_id")
sequence.edit(
object_instance=tmp_object,
current_title='',
......@@ -913,8 +913,8 @@ class TestBase(ERP5TypeTestCase, ZopeTestCase.Functional):
est to edit a temp object.
"""
portal = self.getPortal()
from Products.ERP5Type.Document import newTempOrganisation
tmp_object = newTempOrganisation(portal, "a_wonderful_id")
tmp_object = portal.newContent(temp_object=True, portal_type='Organisation',
id="a_wonderful_id")
tmp_object.edit(title='new title')
self.assertEqual('new title', tmp_object.getTitle())
......
......@@ -914,11 +914,11 @@ class TestERP5Base(ERP5TypeTestCase):
self.assertEqual('image/png', image.getContentType())
self.assertEqual((320, 250), (image.getWidth(), image.getHeight()))
from Products.ERP5Type.Document import newTempImage
def convert(**kw):
image_type, image_data = image.convert('jpg', display='thumbnail', **kw)
self.assertEqual('image/jpeg', image_type)
thumbnail = newTempImage(self.portal, 'thumbnail', data=image_data)
thumbnail = self.portal.newContent(temp_object=True, portal_type='Image',
id='thumbnail', data=image_data)
self.assertEqual(image_type, thumbnail.getContentType())
self.assertEqual((128, 100), (thumbnail.getWidth(),
thumbnail.getHeight()))
......
......@@ -136,18 +136,16 @@ class PDFParser:
security.declarePublic('getPageImage')
def getPageImage(self, page, format, resolution, quality):
"""
Return an instance of newTempImage containing the pape page of
the pdf file
Return a temporary Image object containing the pape page of the pdf file
width, height: attributes in pixel (px)
format: jpg, png, etc...
resolution: resolution of produced image for exemple 600
quality: quality of produced image for exemple 200 raisonable quality
more hight is quality more time it takes to be gererated
"""
from Products.ERP5Type.Document import newTempPDFDocument
from Products.ERP5Type.Document import newTempImage
temp_pdf_document_name = "tmp%s.pdf" % str(random.random()).split('.')[-1]
temp_pdf_document = newTempPDFDocument(self, temp_pdf_document_name)
temp_pdf_document = self.newContent(temp_object=True,
portal_type='PDF Document', id=temp_pdf_document_name)
temp_pdf_document.setData(self.getData())
display = 'xlarge'
mime, image_data = temp_pdf_document.convert(format = format,
......@@ -157,7 +155,8 @@ class PDFParser:
display = display)
page_image = None
if image_data is not None:
page_image = newTempImage(self, "page_%s" % page)
page_image = self.newContent(temp_object=True, portal_type='Image',
id="page_%s" % page)
page_image.setData(page_image)
return page_image
......
......@@ -303,8 +303,8 @@ class FormPrintout(Implicit, Persistent, RoleManager, Item, PropertyManager):
'inline;filename="%s%s"' % \
(filename, guess_extension(content_type) or ''))
return printout
from Products.ERP5Type.Document import newTempOOoDocument
tmp_ooo = newTempOOoDocument(self, self.title_or_id())
tmp_ooo = self.newContent(temp_object=True, portal_type='OOo Document',
id=self.title_or_id())
tmp_ooo.edit(data=printout,
base_data=printout,
filename=self.title_or_id(),
......
......@@ -54,7 +54,6 @@ except ImportError:
SUPPORTS_WEBDAV_LOCKS = 0
from Products.ERP5.Document.Document import ConversionError
import Products.ERP5Type.Document
from lxml import etree
from lxml.etree import Element
......@@ -347,7 +346,7 @@ class OOoTemplate(ZopePageTemplate):
# If this is not a File, build a new file with this content
if not isinstance(picture, File):
tmp_picture = Products.ERP5Type.Document.newTempImage(self, 'tmp')
tmp_picture = self.newContent(temp_object=True, portal_type='Image', id='tmp')
tmp_picture.setData(picture())
picture = tmp_picture
......@@ -557,8 +556,8 @@ class OOoTemplate(ZopePageTemplate):
else:
filename = self._getFileName()
from Products.ERP5Type.Document import newTempOOoDocument
tmp_ooo = newTempOOoDocument(self, self.title_or_id())
tmp_ooo = self.newContent(temp_object=True, portal_type='OOo Document',
id=self.title_or_id())
tmp_ooo.edit(data=ooo,
filename=filename,
content_type=mimetype,)
......
......@@ -589,8 +589,7 @@ class TestDocument(TestDocumentMixin):
def testTempOOoDocument_get_size(self):
# test get_size on temporary OOoDocument
from Products.ERP5Type.Document import newTempOOoDocument
doc = newTempOOoDocument(self.portal, 'tmp')
doc = self.portal.newContent(temp_object=True, portal_type='OOo Document', id='tmp')
doc.edit(data='OOo')
self.assertEqual(len('OOo'), doc.get_size())
......@@ -603,8 +602,7 @@ class TestDocument(TestDocumentMixin):
def testTempOOoDocument_hasData(self):
# test hasData on TempOOoDocument
from Products.ERP5Type.Document import newTempOOoDocument
doc = newTempOOoDocument(self.portal, 'tmp')
doc = self.portal.newContent(temp_object=True, portal_type='OOo Document', id='tmp')
self.assertFalse(doc.hasData())
doc.edit(file=makeFileUpload('import_data_list.ods'))
self.assertTrue(doc.hasData())
......
# -*- coding: utf-8 -*-
from Products.PortalTransforms.libtransforms.commandtransform import commandtransform
from Products.PortalTransforms.interfaces import idatastream
from Products.ERP5Type.Document import newTempOOoDocument
from Products.ERP5.Document.Document import ConversionError
from Acquisition import aq_base
from zope.interface import implements
......
......@@ -211,37 +211,6 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
def test_03_NewTempObject(self):
portal = self.portal
# WARNING: `newTemp<PortalType>(self, ID)` is deprecated in favor of
# `self.newContent(portal_type=<PortalType>, temp_object=True, id=ID)`
from Products.ERP5Type.Document import newTempPerson
o = newTempPerson(portal, 1.2)
o.setTitle('toto')
self.assertEqual(o.getTitle(), 'toto')
self.assertEqual(str(o.getId()), str(1.2))
from Products.ERP5Type.Document import newTempOrganisation
o = newTempOrganisation(portal, -123)
o.setTitle('toto')
self.assertEqual(o.getTitle(), 'toto')
self.assertEqual(str(o.getId()), str(-123))
# Try to edit with any property and then get it with getProperty
o = newTempOrganisation(portal,'a')
o.edit(tutu='toto')
self.assertEqual(o.getProperty('tutu'), 'toto')
# Same thing with an integer
o = newTempOrganisation(portal,'b')
o.edit(tata=123)
self.assertEqual(o.getProperty('tata'), 123)
# Make sure this is a Temp Object
self.assertEqual(o.isTempObject(), 1)
# Create a subobject and make sure it is a Temp Object
a = o.newContent(portal_type = 'Telephone')
self.assertEqual(a.isTempObject(), 1)
# Test newContent with the temp_object parameter
o = portal.person_module.newContent(id=987, portal_type="Person", temp_object=1)
o.setTitle('bar')
......@@ -255,6 +224,14 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
self.assertEqual(b.isTempObject(), 1)
self.assertEqual(b.getId(), str(2))
# Try to edit with any property and then get it with getProperty
o.edit(tutu='toto')
self.assertEqual(o.getProperty('tutu'), 'toto')
# Same thing with an integer
o.edit(tata=123)
self.assertEqual(o.getProperty('tata'), 123)
# Test newContent with the temp_object parameter and without ID
o = portal.person_module.newContent(portal_type="Person", temp_object=1)
o.setTitle('bar')
......@@ -294,12 +271,6 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
# check we can create temp object without specific roles/permissions
self.logout()
self.loginWithNoRole()
## newTemp<PORTAL_TYPE>
o = newTempOrganisation(portal.organisation_module,'b')
self.assertEqual(o.isTempObject(), 1)
a = o.newContent(portal_type = 'Telephone')
self.assertEqual(a.isTempObject(), 1)
self.assertEqual(a, guarded_getattr(o, a.getId()))
## newContent
o = portal.organisation_module.newContent(portal_type='Organisation',
temp_object=1)
......@@ -1864,8 +1835,7 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
portal.portal_types.resetDynamicDocuments()
# Create a new temporary person object.
from Products.ERP5Type.Document import newTempPerson
o = newTempPerson(portal, 'temp_person_1')
o = portal.newContent(temp_object=True, portal_type='Person', id='temp_person_1')
self.assertTrue(o.isTempObject())
self.assertEqual(o.getOriginalDocument(), None)
......@@ -1906,7 +1876,7 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
self.assertEqual(o.getValidationState(), 'validated')
# Create a new temporary person object.
o = newTempPerson(portal, 'temp_person_2')
o = portal.newContent(temp_object=True, portal_type='Person', id='temp_person_2')
self.assertTrue(o.isTempObject())
# This should call methods generated for the persistent object.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment