Last active
March 17, 2023 14:54
-
-
Save espenmn/83fc5dbcb776df9345f5daf0c0f05434 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #python 3 | |
| import pandas as pd | |
| #import openpyxl | |
| from zope.lifecycleevent import modified | |
| import plone.api | |
| from zope.component.hooks import setSite | |
| setSite(app['mysite']) | |
| #user will choose this | |
| excelfile = '/path/to/excel.xlsx' | |
| from pandas import * | |
| df = pd.read_excel(excelfile) | |
| my_dict = df.to_dict(orient='index') | |
| # Iterate the loop to read the cell values | |
| #in case we just want to rerun some | |
| #for i in range(0, len(my_dict)): | |
| #just doing 3 to test that it works | |
| for i in range(0, 3 ): | |
| old_id = my_dict[i].get('ID old') | |
| brains = app.myapp.portal_catalog(id=old_id) | |
| if brains: | |
| obj = brains[0].getObject() | |
| for key, value in my_dict[i].items(): | |
| setattr(obj, key.lower().replace(" ", ""), value) | |
| #import pdb; pdb.set_trace() | |
| if plone.api.content.get_state(obj) == 'published': | |
| plone.api.content.transition(obj=obj, transition='reject') | |
| modified(obj) | |
| #import transaction ; | |
| #transaction.commit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment