0001-workflows-encode-model-file-in-base64-in-import-expo.patch
tests/test_workflow_import.py | ||
---|---|---|
214 | 214 | |
215 | 215 |
export_to = ExportToModel() |
216 | 216 |
export_to.label = 'test' |
217 |
upload = Upload('/foo/bar', content_type='text/rtf')
|
|
217 |
upload = Upload('/foo/bar', content_type='application/vnd.oasis.opendocument.text')
|
|
218 | 218 |
upload.fp = StringIO.StringIO() |
219 |
upload.fp.write('HELLO WORLD')
|
|
219 |
upload.fp.write('''PK\x03\x04\x14\x00\x00\x08\x00\x00\'l\x8eG^\xc62\x0c\'\x00''')
|
|
220 | 220 |
upload.fp.seek(0) |
221 | 221 |
export_to.model_file = UploadedFile(publisher.WcsPublisher.APP_DIR, None, upload) |
222 | 222 |
st1.items.append(export_to) |
wcs/wf/export_to_model.py | ||
---|---|---|
14 | 14 |
# You should have received a copy of the GNU General Public License |
15 | 15 |
# along with this program; if not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 |
import base64 |
|
17 | 18 |
from StringIO import StringIO |
18 | 19 |
from xml.etree import ElementTree as ET |
19 | 20 |
import zipfile |
... | ... | |
331 | 332 |
el = ET.SubElement(xml_item, 'model_file') |
332 | 333 |
ET.SubElement(el, 'base_filename').text = self.model_file.base_filename |
333 | 334 |
ET.SubElement(el, 'content_type').text = self.model_file.content_type |
334 |
ET.SubElement(el, 'content').text = self.model_file.get_file().read() |
|
335 |
ET.SubElement(el, 'b64_content').text = base64.encodestring( |
|
336 |
self.model_file.get_file().read()) |
|
335 | 337 | |
336 | 338 |
def model_file_init_with_xml(self, elem, charset, include_id=False): |
337 | 339 |
if elem is None: |
338 | 340 |
return |
339 | 341 |
base_filename = elem.find('base_filename').text |
340 | 342 |
content_type = elem.find('content_type').text |
341 |
content = elem.find('content').text |
|
343 |
if elem.find('b64_content') is not None: |
|
344 |
content = base64.decodestring(elem.find('b64_content').text) |
|
345 |
if elem.find('content') is not None: |
|
346 |
content = elem.find('content').text |
|
342 | 347 | |
343 | 348 |
ids = (self.parent.parent.id, self.parent.id, self.id) |
344 | 349 |
filename = 'export_to_model-%s-%s-%s.upload' % ids |
345 |
- |