Displaying a field/widget value of an EasyForm (plugin.registration) out of its template?

Hi,

thank you for being understanding (I am not a developer) ... but I would like to display the number of "available_seats" of an easyform (plugin.registration) at the level of its parent folder but I can't do it this way :

           <dl class="portlet">
               <span tal:define="presentiel nocall:context/reservations|nothing;
                                 max_attendees python:getattr(presentiel, 'max_attendees', None);
                                 show_seats_left presentiel/show_seats_left|nothing;
                                 available_seats presentiel/view/form/field/available_seats|nothing">
                  <span tal:content="show_seats_left" /> : 
                  <span tal:content="available_seats" /> /
                  <span tal:content="max_attendees" />
               </span>
           </dl>

(inspired by how this data is retrieved elsewhere: https://github.com/collective/collective.easyformplugin.registration/blob/master/src/collective/easyformplugin/registration/browser/registration_form.pt) ...

What else can I try? @jensens ?

Thanks!

Hey,

what is "presentiel"? An object? A View?

It I understand the code right you want to show the result of a function from your parent object, because "available_seats" is a function.

I guess my try would be to write a function myself for the template I want to fill with an equivalent function like this:

I guess you would have to rewrite it to use the parent instead of context though.

Kind regards

traverse to the view like so:

regview nocall:context/reservations/@@view;
available_seats regview/available_seats;

Hi Janina,

"presentiel" here designates the object "reservations" which is the id of an EasyForm added in an EventFolderishObject

Thanks for the advice, then I'll do my best to make it happen if I can't find another easier way given my skills ...

Hi @jensens

Super nice to have posted so fast, but inserting this following code in a 'myview' template ... a LocationError occurs :cry:

<metal:block fill-slot="content-core">
        XXX - this text comes below title and description

               <!-- THIS WORKS IF NECESSARY
               <p>
                 ${python: 'Il y a {0} places en tout'.format(getattr(context.reservations, 'max_attendees', None))}
               </p>
               -->

               <!-- THIS NOT : LocationError -->
               <span tal:define="regview nocall:context/reservations/@@view;
                                 available_seats regview/available_seats;">
                  <span tal:content="available_seats" /> /
               </span>


               <!-- THIS DOESN'T WORK NEITHER
               <p>
                 ${python: 'Il y a {0} places disponibles'.format(reservations.unrestrictedTraverse('@@view').available_seats())}
               </p>
               -->

</metal:block>

The TraceBack ...

Traceback (innermost last):
  Module ZPublisher.Publish, line 138, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 48, in call_object
  Module Shared.DC.Scripts.Bindings, line 322, in __call__
  Module Shared.DC.Scripts.Bindings, line 359, in _bindAndExec
  Module Products.PageTemplates.ZopePageTemplate, line 338, in _exec
  Module Products.PageTemplates.ZopePageTemplate, line 435, in pt_render
  Module Products.PageTemplates.PageTemplate, line 87, in pt_render
  Module zope.pagetemplate.pagetemplate, line 137, in pt_render
  Module five.pt.engine, line 98, in __call__
  Module z3c.pt.pagetemplate, line 163, in render
  Module chameleon.zpt.template, line 261, in render
  Module chameleon.template, line 191, in render
  Module chameleon.template, line 171, in render
  Module bd8df01c3287ccba37c37bffa626bab8.py, line 230, in render
  Module cdcb329ae3b23aa0055939a7689705a9.py, line 1167, in render_master
  Module cdcb329ae3b23aa0055939a7689705a9.py, line 364, in render_content
  Module bd8df01c3287ccba37c37bffa626bab8.py, line 167, in __fill_content_core
  Module five.pt.expressions, line 135, in __call__
  Module five.pt.expressions, line 126, in traverse
  Module zope.traversing.adapters, line 142, in traversePathElement
   - __traceback_info__: (<Products.Five.metaclass.MyFormWrapper object at 0x0000000018531B08>, 'available_seats')
  Module zope.traversing.adapters, line 56, in traverse
   - __traceback_info__: (<Products.Five.metaclass.MyFormWrapper object at 0x0000000018531B08>, 'available_seats', ())
LocationError: (<Products.Five.metaclass.MyFormWrapper object at 0x0000000018531B08>, 'available_seats')

 - Expression: "regview/available_seats"
 - Filename:   /www/RERS-Alpha/portal_skins/custom/myview
 - Location:   (line 21: col 52)
 - Arguments:  repeat: {...} (0)
           template: <ImplicitAcquisitionWrapper myview at 0x19dd4138L>
           modules: <instance - at 0x5c42608L>
           here: <ImplicitAcquisitionWrapper permanence-du-16-novembre-2020 at 0x19305b88L>
           user: <ImplicitAcquisitionWrapper - at 0x19dd4458L>
           nothing: <NoneType - at 0x768fea98L>
           container: <ImplicitAcquisitionWrapper RERS-Alpha at 0x18ccea98L>
           default: <object - at 0x57650a0L>
           request: <instance - at 0x1a06db88L>
           wrapped_repeat: <SafeMapping - at 0x19dd4ea8L>
           traverse_subpath: <list - at 0x1a06eb08L>
           loop: {...} (0)
           context: <ImplicitAcquisitionWrapper permanence-du-16-novembre-2020 at 0x19305b88L>
           translate: <function translate at 0x1a040748L>
           root: <ImplicitAcquisitionWrapper Zope at 0x19139f98L>
           options: {...} (1)
           target_language: <NoneType - at 0x768fea98L>

All theory is gray....
Probably the wrong view was fetched with @@view. Without more context difficult to debug via this forum.

thank you anyway for looking into my problem, so i will focus on python. I still have to find the way to code this ... and call the result from the template

Regards,

Hello,

just to let you know that I found a solution to retrieve the data stored in this context (the available_seats being more difficult to retrieve in python than the other attributes), thanks to the contribution shared and the track proposed by @tkimnguyen at https://community.plone.org/t/does-anyone-have-any-suggestions-of-bringing-saveddata-count-to-another-part-of-a-plone-site-using-collective-easyform / 7066/4

Best regards,