0

I have created two content types in Plone 4.3 via Dexterity and created a Plone Product on the file system.

The types are

  • Supplier
  • item

Items can only exist in inside Supplier, and I can manually create new items without

I'd like to be able to create a bunch of items if I upload a CSV file while creating a supplier. Any way dexterity supports this (trigger, custom view...)?

Peter B
  • 59
  • 1
  • 7

1 Answers1

2

You'd have to handle that in a custom view. There is no pre-existing code to handle that.

For simple cases, just read the uploaded file with the csv module and use the rows to create items in the Supplier container:

from plone.dexterity.utils import createContentInContainer
import csv

reader = csv.reader(uploadedfile)

for row in reader:
    createContentInContainer(supplier, 'your.package.item', title=row[0], ...)

For more complex operations, you could build a transmogrifier pipeline with the transmogrify.dexterity to convert CSV-data to dexterity objects, but that is probably overkill here.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • How do I handle the post trigger? Meaning I type in the info for supplier and hit submit (like custom adapters in PloneFormGen)? – Peter B Apr 16 '13 at 14:48
  • @PeterB: With a [custom view](http://developer.plone.org/reference_manuals/external/plone.app.dexterity/custom-views.html) I'd say. – Martijn Pieters Apr 16 '13 at 14:51
  • I have now found a solution based on your suggestion with a custom view. Thanks for your help – Peter B Apr 20 '13 at 13:13