I'm using the Plone API to create objects on an (standalone) instance of Plone 5.1 (using the standard installer). In my script to create the objects, I need to add a datetime to the "effective" property ('Publication Date') in the object to be created. In order to do so, I needed to install the datetime module, which I did via pip in the /bin folder. That went all well and good. However, when I ran the code, I got an error message.
Here are the import statements in my python script:
from bs4 import BeautifulSoup
import urllib
import os, json
from datetime import datetime
from plone import api
import transaction
from plone.app.textfield.value import RichTextValue
import plone.app.event
... thereafter, I set the effective field to datetime.now() or whatever the input data requires.
This is what I get when I run the code...
c@lancer:/opt/plone/zinstance/bin$ sudo -u plone_daemon ./instance --object-path="/test" run ./TexAG_Uploader.py
Traceback (most recent call last):
File "/opt/plone/zinstance/parts/instance/bin/interpreter", line 293, in
exec(_val)
File "", line 1, in
File "/opt/plone/buildout-cache/eggs/Zope2-2.13.27-py2.7.egg/Zope2/init.py", line 60, in
from Zope2.Startup.run import configure
File "/opt/plone/buildout-cache/eggs/Zope2-2.13.27-py2.7.egg/Zope2/Startup/init.py", line 27, in
from zope.event import notify
ImportError: No module named event
I would have thought that import plone.app.event would have fixed this problem, but it didn't. Does anyone know what I need to import/install/copy to fix this problem? Obviously, I'm missing a module called event, but which code has that particular event module? I just need to know what to import.
There is more here than meets the eye. Something about installing the datetime module via pip throws Plone for a loop.
I am (want to?) use Plone API to load tens of thousands of documents that are in (individual) json files. As I mentioned in my last post, I need to change the effective property (which is a datetime object). I ran into the problem of the datetime module being missing when running the python script. To remedy that problem, I ran pip2.7 install datetime as plone_buildout. E.g.,
Like I said, it installed successfully, but that was all it took to knock the Plone installation out of commission.
Note, as an experiment, and just to make everything as pristine as possible, I started out with an Ubuntu 16.04 (sever) clean install, and then installed Plone (5.1) from the unified installer (standalone, because I'm doing development, with all recommended dependencies per the Plone installation instructions). Then, just to make sure all was well, I started Plone and created a Plone site. All was well. No problems.
Next, I ran the pip2.7 install datetime and restarted Plone. A process stared, but I could no longer access my Plone site (e.g., http://localhost:8080/ did not return a response).
I'm at a loss to know what went wrong. Can someone duplicate this experiment and confirm the same problem?
I don't follow exaclty why you are having problems with importing the event module, but something else that for me signals a "where there's smoke there's a fire", you describe that you have to import the datetime module to set datetimes on Plone objects. Not really:
Are you aware that you should not use datetime.datetime but DateTime? Some of Zope's first internal data structures predate modern python (standard libraries), they just weren't there yet. You can find more information here:
Well it isn't that simple. An Event start and end date has to be a non-naive python datetime. I hate that this is mixed, but due to migration problems we never managed to harmonize this to use the python implementation all over the place. That's if you work with an old code base.
Lunga1: That was the first thing that I (it seemed like the obvious thing to do), but it didn't work. (It could never find the "event" module.) That problem arose when I installed datetime (not DateTime). Consequently, the "missing" event module was a consequence of installing datetime and using that instead of DateTime.
Just to clarify, datetime its a python module, it comes with python you dont need to install it. DateTime it is a zope library/module it was created before python had its own datetime. They don't replace each other.
Plone its build on top of Zope, and nowadays some attributes are datetime and some DateTime.
As in the other post you asked about how to set some fields, i wrote there that code
from DateTime import DateTime
DateTime(datetime.datetime.now())
Some DateTime fields are effective, creation, modification and expiration dates. While, as Jens said, event dates are python aware datetime. Also take a look at the link Fred provided if you need conversions between each other