Skip to content

Instantly share code, notes, and snippets.

@maethu
Last active September 11, 2018 10:12
Show Gist options
  • Save maethu/41eeb51cf18087cc0f9bfc7533eecbb7 to your computer and use it in GitHub Desktop.
Save maethu/41eeb51cf18087cc0f9bfc7533eecbb7 to your computer and use it in GitHub Desktop.
>>> plone = app.platform
>>> from zope.component.hooks import setSite
>>> setSite(plone)
>>> from plone import api
>>> import csv
>>> from StringIO import StringIO
>>> handler = open('user.csv', 'r')
>>> data = handler.read().decode("utf-8-sig").encode("utf-8")
>>> csv_data = csv.DictReader(StringIO(data), delimiter=';')
>>> for item in csv_data:
... props = dict(fullname='{} {}'.format(item['vorname'], item['nachname']))
... try:
... api.user.create(username=item['benutzername'], email=item['email'], password=item['passwort'], properties=props)
... except:
... print "Cannot create {}".format(item['benutzername'])
...
>>> import transaction
>>> transaction.commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment