I am following the tests here: https://github.com/plone/plone.app.referenceablebehavior/blob/master/plone/app/referenceablebehavior/referenceable.txt
I added plone.app.referenceablebehavior to Plone 4.3, created a type TTW and made it referenceable:
Then I created an instance of the type in the site root called "My Referenceable Type Instance", and tried the following in debug mode:
>>> from plone.app.referenceablebehavior.referenceable import IReferenceable
>>> IReferenceable.providedBy(app.Plone['my-referenceable-type-instance'])
False
I would expect the result to be True. Is this a bug, or am I missing something?
[0] My buildout:
[buildout]
extends = https://raw.github.com/pythonpackages/buildout-plone/master/4.3.x-dev
[plone]
eggs +=
plone.app.referenceablebehavior
In a debug session, you need to set the local site manager before attempting this. Try:
>>> from zope.component.hooks import setSite
>>> setSite(app.Plone)
...prior to attempting to check if IReferenceable is provided by the object. The reason that this is necessary is that Dexterity uses something called an Object Specification Descriptor that looks up interfaces dynamically from the Factory Type Information of the type, which is site-specific (you cannot retrieve site-specific configuration without first having the local site configured for lookups).
Related
I'm trying to implement custom XCOM backend.
Those are the steps I did:
Created "include" directory at the main Airflow dir (AIRFLOW_HOME).
Created these "custom_xcom_backend.py" file inside:
from typing import Any
from airflow.models.xcom import BaseXCom
import pandas as pd
class CustomXComBackend(BaseXCom):
#staticmethod
def serialize_value(value: Any):
if isinstance(value, pd.DataFrame):
value = value.to_json(orient='records')
return BaseXCom.serialize_value(value)
#staticmethod
def deserialize_value(result) -> Any:
result = BaseXCom.deserialize_value(result)
result = df = pd.read_json(result)
return result
Set at config file:
xcom_backend = include.custom_xcom_backend.CustomXComBackend
When I restarted webserver I got:
airflow.exceptions.AirflowConfigException: The object could not be loaded. Please check "xcom_backend" key in "core" section. Current value: "include.cust...
My guess is that it not recognizing the "include" folder
But how can I fix it?
*Note: There is no docker. It is installed on a Ubuntu machine.
Thanks!
So I solved it:
Put custom_xcom_backend.py into the plugins directory
set at config file:
xcom_backend = custom_xcom_backend.CustomXComBackend
Restart all airflow related services
*Note: Do not store DataFrames that way (bad practice).
Sources I used:
https://www.youtube.com/watch?v=iI0ymwOij88
I have a .yaml configuration file which looks like:
key: value
hydra:
run:
dir: ./data_fetcher/hydra_outputs/${now:%Y-%m-%d}/${now:%H-%M-%S}
with a python file main.py:
import hydra
#hydra.main(config_path="data_fetcher/config", config_name="config")
def main(cfg: DictConfig):
pass
if __name__ == "__main__":
main()
When running main.py an output directory is created according to the current date and time.
How does Hydra get the current time ? is it possible to change the timezone ?
Hydra is registering a simple OmegaConf custom resolver here with a line like:
register("now", lambda pattern: strftime(pattern, localtime()))
You can register your own custom resolver with a different name before #hydra.main() runs that will do what you want.
Read about custom resolvers in the OmegaConf documentation.
Read about how to get time in a different time zone here.
You can also file a feature request to add support for time zone to the ${now:...} custom resolve in Hydra. a PR would be appreciated.
For example, ${now:...} can support an optional second parameter for the time zone.
I've got a product installed in one Plone Site, this product change the visibility of a field of the Event content type.
It use IBrowserLayerAwareExtender to restrain the change to only the Plone Site where the product is installed.
This work on the development server on which buildout is made with the develop.cfg option, but in production, the layer is not respected, and all others Plone Site have this change.
Here is the code:
schemaextender.py:
class EventModifier(object):
"""
Masque certains champs inutiles pour le projet
"""
implements(ISchemaModifier, IBrowserLayerAwareExtender)
adapts(IATEvent)
layer = IBswMonasticLayer
def __init__(self, context):
self.context = context
# noinspection PyMethodMayBeStatic
def fiddle(self, schema):
"""
:param schema:
:return:
"""
schema['attendees'].widget.visible = {'edit': 'invisible', 'view': 'invisible'}
schema['location'].widget.label = _(u'Adresse')
return schema
configure.zcml:
<adapter for="Products.ATContentTypes.interface.IATEvent"
provides="archetypes.schemaextender.interfaces.ISchemaModifier"
factory=".schemaextender.EventModifier"
name="bsw.monastic.schemaextender.EventModifier"/>
Is it a bug or am I missing something ?
IMHO it's weird it works on you dev machine and not in production. I assume the browserlayer is indeed there on the production site.
You can check this by running the following code in a debug session on the server:
>>> from zope.component.hooks import setSite
>>> plone = app.path.to.plone.site
>>> setSite(plone) # Setup component registry
>>> from plone.browserlayer.utils import registered_layers
>>> registered_layers()
[...] # Bunch of layer interface active on the plone site.
I assume it's there, so you should remove it.
If so remove it using from plone.browserlayer.utils import unregister_layer
>>> from plone.browserlayer.utils import unregister_layer
>>> unregister_layer(layername)
>>> import transaction
>>> transaction.commit()
I installed Django and was able to double check that the module was in fact in Python, but when attempting to implement basic commands such as runserver or utilize manage.py; I get DJANGO_SETTEINGS_MODULE error. I already used "set DJANGO_SETTINGS_MODULE = mysite.settings" as advised and inserted mysite.settings into the PATH for Python as some documentation online directed me to.
Now instead of undefined it says no such module exists. I can't find anything else in the documentation and I used my test site name instead of "mysite" without any change. Does anyone know what am I missing? All I can find in the module library for Django in my Python is this code.
from future import unicode_literals
from django.utils.version import get_version
VERSION = (1, 11, 5, 'final', 0)
__version__ = get_version(VERSION)
def setup(set_prefix=True):
"""
Configure the settings (this happens as a side effect of accessing the first setting), configure logging and populate the app registry.
Set the thread-local urlresolvers script prefix if `set_prefix` is True.
"""
from django.apps import apps
from django.conf import settings
from django.urls import set_script_prefix
from django.utils.encoding import force_text
from django.utils.log import configure_logging
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
if set_prefix:
set_script_prefix(
'/' if settings.FORCE_SCRIPT_NAME is None else force_text(settings.FORCE_SCRIPT_NAME)
)
apps.populate(settings.INSTALLED_APPS)
Are you sure you wrote properly the environment variable? I'm asking cause I see you get the error DJANGO_SETTEINGS_MODULE (settings has a misspelling)...
How do I include configuration information from Buildout in my Plone products?
One of the plone products i'm working on reads and writes info to and from the filesystem. It currently does that inside the egg namespace (for example inside plone/product/directory), but that doesn't look quite right to me.
The idea is to configure a place to store that information in a configurable path, just like iw.fss and iw.recipe.fss does.
For example, save that info to ${buildout:directory}/var/mydata.
You could add configuration sections to your zope.conf file via the zope-conf-additional section of the plone.recipe.zope2instance part:
[instance]
recipe = plone.recipe.zope2instance
...
zope-conf-additional =
<product-config foobar>
spam eggs
</product-config>
Any named product-config section is then available as a simple dictionary to any python product that cares to look for it; the above example creates a 'foobar' entry which is a dict with a 'spam': 'eggs' mapping. Here is how you then access that from your code:
from App.config import getConfiguration
config = getConfiguration()
configuration = config.product_config.get('foobar', dict())
spamvalue = configuration.get('spam')