Ticket #11838 (closed PLIP: fixed)

Opened 5 years ago

Last modified 4 years ago

Add z3c support to plone.app.portlets

Reported by: ggozad Owned by: ggozad
Priority: minor Milestone: 4.3
Component: General Version: 4.2
Keywords: portlets Cc: optilude, alecm, ggozad@…

Description

Proposer: Yiorgis Gozadinos
Seconder: Martin Aspeli

Motivation

Currently portlet add/edit forms can only be done using formlib. Now that z3c.form is included in Plone, it would be nice to be able to use it for portlets as well.

Proposal & Implementation

AddForm/EditForm will be provided in plone.app.portlets the same way they exist for formlib (see plone.app.portlets.browser.formhelper.py). Current portlets are not going to be converted so as to maintain backwards compatibility. Any such conversions could be part of #10359 or similar PLIP.

Deliverables

The following need to be produced:

  • AddForm and EditForm classes
  • Unit tests
  • Documentation

Localization is not necessary as the one from formlib can be reused.

Risks

There is no risk associated with the proposal and it does not affect any existing functionality.

Participants

Yiorgis Gozadinos, ggozad

Progress

Some of the work is done already as part of an internal Jarn project. Can be reused as is mostly.

Change History

comment:1 Changed 5 years ago by mj

Yiorgis, we'd love to see this in the next Plone release (4.2), and I've been assigned as your framework champion for this ticket.

I know we marked this PLIP as 4.x because you do not have time to write tests for this, but perhaps we can recruit some help on the Plone-dev list, if others are interested in this functionality and are willing to put in the work to get it into 4.2.

The freeze deadline for 4.2 has been set to June 30th, but the framework team will need time to review, and we'll need to allow time for adjustments based on the reviews as well.

comment:2 Changed 5 years ago by eleddy

  • Milestone changed from 4.x to 4.3

Approved. Go forth and implement! martijn will be your plip champion.

comment:3 Changed 5 years ago by rossp

The FWT has wrapped up work on 4.2 and can start work on 4.3 whenever we have PLIPs to review. So can you as proposers or implementers please check in on your PLIPs and let us know what the status is and when we can expect issues to be addressed and implementations complete so we can review them for merge in 4.3.

comment:4 Changed 5 years ago by ggozad

There's not much to do, I would expect the PLIP to be done by September

comment:5 Changed 4 years ago by ggozad

  • Status changed from new to closed
  • Resolution set to please review

I think this is more or less ok, please review and let me know if there any required changes.

comment:6 Changed 4 years ago by alecm

  • Cc alecm added

comment:7 Changed 4 years ago by rossp

  • Status changed from closed to reopened
  • Version set to 4.2
  • Resolution please review deleted

Adding my review here since I'm not sure where we're doing reviews these days.

Summary: +1 for merge

This is a very simple PLIP so I'm not going to use the full review boilerplate. I reviewed the branch in github and the implementation looks solid and correct. I left one comment in github that it would be nice to see test coverage for actually editing a portlet. Aside from that everyhing looks good. Since the scope is so small and the risk of interactions is so minimal, I vote we merge this sooner rather than later.

comment:8 Changed 4 years ago by eleddy

4.3 branch is cut - please merge at will!

comment:9 Changed 4 years ago by sunew

There is a problem with the current implementation (plone.app.portlets branch plip11838-z3c-portlets). More advanced fields/widgets, for instance RelationField and related widgets, do not work on the addform. (Edit forms are fine).

Solution inspired by plone.dexterity is to call form.applyChanges(self, content, data). But this can only happen with knowledge of the Assignment class to use.

I wrote a custom create method for my portlet like this:

class AddForm(z3cformhelper.AddForm):
    """
    """
    fields = field.Fields(IEmployeeReferencePortlet)

    label = _(u"Add Employee Reference Portlet")
    description = _(u"description_add_ref_portlet", default=u"This portlet display info about the employee"
                                                         "referenced from the portlet.")
    
    def create(self, data):
        # adapted from plone.dexterity.browser.add.DefaultAddForm to make advanced fields like RelationField work.
        content = Assignment(**data)
        container = aq_inner(self.context)

        # Acquisition wrap temporarily to satisfy things like vocabularies
        # depending on tools
        if IAcquirer.providedBy(content):
            content = content.__of__(container)

        form.applyChanges(self, content, data)

        return aq_base(content)

It would be great if this could be done in the parent class in plone.app.portles.z3cformhelper.

comment:10 Changed 4 years ago by sunew

Better version implemented in plone.app.portlets, and a pull request sent.

comment:11 Changed 4 years ago by eleddy

  • Cc ggozad@… added
  • Status changed from reopened to confirmed

Yiorgis - are you still up for merging this ticket? Cut off date for merge is June 11 for 4.3. Thanks!

comment:12 Changed 4 years ago by ggozad

Yeah sure. I will review @sunew's pull request and merge. Does it need another review after the pull request merge?

comment:13 Changed 4 years ago by miohtama

I tested the changes against 4.1/ 4.2 and have a problem with having proper acquisition chain for Assigment in the renderer. (note: This might not be the case for the latest 4.3).

Assignment object looks like this on the EditForm

    self.context
    <Assignment at /Plone/fi/info/++contextportlets++plone.rightcolumn/assignment>

Assignment on Renderer

    (Pdb) self.data
    <Acquisition.ImplicitAcquisitionWrapper object at 0x10f4f9410>
    (Pdb) self.data.aq_base
    <imageportlet.portlets.Assignment object at 0x1101c3050>

Assignment on the Renderer do not have a proper acquisition chain, or URL mapping. Thus, widgets requiring this functionality, like BLOBs will be defunct. They need URLs containing the widget part like:

            //localhost:9966/Plone/fi/info/++contextportlets++plone.rightcolumn/assignment/edit/++widget++form.widgets.image/@@download/Screen+Shot+2012-06-07+at+10.41.38+AM.png

This seems to be a deeper problem in the Plone portlets architecture - the column where the portlet is renderer is not being passed for the renderer? This means that we lack the information to construct a proper acquisition chain.

comment:14 Changed 4 years ago by miohtama

For now, I simply hacked around the issue by storing a reference path to the portlet column in when the portlet assignment is created:

 https://github.com/miohtama/imageportlet/blob/master/imageportlet/portlets.py#L112

Then Renderer maps all references to this URL by hand.

I think the proper solution would be having assignments mapped in Plone URL spaces properly, so that z3c.form widgets would have their own absolute_url(). Not sure what kind of implications this would have.

comment:15 Changed 4 years ago by kleist

  • Component changed from Infrastructure to General

comment:16 Changed 4 years ago by esteele

  • Status changed from confirmed to closed
  • Resolution set to fixed
Note: See TracTickets for help on using tickets.