Example #1
0
    def handle_associate( self, action, data ):
        """
        associate a search result with the context.
        """
        # reset viewlet state to listing of associated objects
        self.state = 'listing'

        # first we need to dereference the selection column values into
        # objects to associate.
        values = core.getSelectedObjects( self.selection_column,
                                     self.request,
                                     self.domain_model )

        # add objects to the association
        association = proxy.removeSecurityProxy( getattr( self.context, self.property_name ) )

        for v in values:
            if v not in association:
                association.append( v )

        # pluralize properly
        if len(values) > 1:
            self.status = "%s Associated"%(self.domain_model.__name__.title()+'s')
        else:
            self.status = "%s Associated"%self.domain_model.__name__.title()

        # reset selection column
        self.form_reset = True
Example #2
0
    def handle_delete( self, action, data):
        """
        delete the selected items from the m2m relationship.
        """
        # reset form state
        self.state = 'listing'
        
        # first we need to dereference the selection column values into
        # objects to disassociate.
        values = core.getSelectedObjects( self.selection_column,
                                     self.request,
                                     self.domain_model )

        if not values:
            self.status = "No %s Selected"%( self.domain_model.__name__.title()+'s')
            return
        # remove objects from association
        association = getattr( self.context, self.property_name )
        for v in values:
            if v in association:
                association.remove( v )
                
        # pluralize properly
        if len(values) > 1:
            self.status = "%s Removed"%(self.domain_model.__name__.title()+'s')
        else:
            self.status = "%s Removed"%self.domain_model.__name__.title()