I am trying to create an event content type that has 3 extra variables to the event type that comes with Plone.
I noticed that the event content variables come from the following behaviors:
The form is coming out fine but I am having issues displaying the variables that come from the behavior elements. For my other custom dexterity field, such as policy_program, I could display the value by doing:
<span tal:content="context/policy_program" />
I am having issues displaying the behavior elements e.g. the event URL, etc. Any advise would be most appreciated. Thank you.
You need to adapt the event object to the related interface of the behavior and access the attributes from the adopted object.
contact_name = plone.app.event.dx.behaviors.IEventContact(your_event).contact_name
It is inappropriate to access the attributes from behaviours directly through the context object
contact_name = your_event.contact_name
Andreas, thank you so much. Please excuse my ignorance but where do I put that import statement? In the interface.py file, model .xml file or in the template .pt file? Please advise. Thank you.
this is Python obviously and belongs somewhere somehow in your own brower view.
Yikes, what does this mean? Does this go into the configure.zcml file? Right now, I have the following in my configure.zcml file:
Is it really necessary to teach you basic browser view functionality?
Yes, I am afraid so. That is the whole reason why I am asking for help.
You find more info here:
Usually, browser views are defined something like this:
The views.py could be something like:
## -*- coding: utf-8 -*-
from Products.Five import BrowserView
#and everything else you need to import
return 'some thing'
Then, you can do this in you 'template.pt'
For the events there are some 'special stuff', so maybe you can subclass the event view ? You need to google it / read the docs ( or ask someone that knows this better than me )
Please read the docs.
Browser views are a fundamental concept of Plone and wonder why we need to teach this to someone or look up the docs for you with your year long experience with Plone.
Thanks so much for the link. Yeah, that behavioral elements for events is throwing me for a loop. I am going to check out your suggestion and see where it leads me. If worse come to the worse, I am going to just create my own custom event content type and try not to mess with the "special stuff" that comes with the event content type. Thanks so much.
Well, Andreas. First of all, I don't program browser views often. So even if I have used Plone for quite some time, that is no indication that I understand all the ins-and-outs of browser views. I have used browser views many times in the past. However, not so in having to pull up fields that don't even appear in my model xml files. Because of that it did not even occur to me that it relates to browser views. I thought it dealt with something else. Second of all, I am not going to say I know something when I don't, and I am not shy to say that I don't understand something when I don't. It is better to be honest than to play bluff. So there it is. Espen gave me that link yesterday and I am looking through it now. Thank you for sending that same link to me today as well. It is very much appreciated.
I think we could all do with a reminder that not everyone in this forum is a hardcore Python developer. One of the great strengths (in my opinion) of Plone is that it can be customized by non-developers. Every one of us has strengths and areas in which we need help, so please be kind to each other.
I remember my own confusion at how one accesses values of fields that are defined by behaviours. Let me see if I can dig up some examples.
I think what's happening here is that you'd like to be able to use TAL to get the value of the field defined by a behaviour, but I don't think that's directly doable in TAL because you need to apply the behaviour to the content item first, kind of as described in https://docs.plone.org/external/plone.app.dexterity/docs/grok/behaviors/testing-behaviors.html?highlight=behavior
from collective.gtags.behaviors import ITags
doc = Document('doc')
tags_adapter = ITags(doc, None)
# now you can get values of fields defined by the ITags behaviour:
my_tags = tags_adapter.tags
Someone please correct me on this: I don't think this is doable in TAL, so you have to create a browser view that will contain this code in a method, and then in the browser view's template you can call that method. Continuing the above example, if what you wanted was those tags you could define a method called
my_tags that returns those tags, and then your TAL expression could call it with something like this: