Exemplo n.º 1
0
    def handle_add(self, action, data):
        """
        sends user to search form.
        """
        self.state = 'add'
        session = Session()
        related_count = session.query(self.domain_model).count()
        if related_count > 20:
            self.form_fields = core.setUpFields(self.domain_model,
                                                mode='search')
        else:
            self.state = 'search'
            query = session.query(self.domain_model)
            context = proxy.removeSecurityProxy(self.context)

            collection = getattr(context, self.property_name)
            if collection:
                mapper = orm.class_mapper(self.domain_model)
                instance_pkey = mapper.primary_key_from_instance
                pkey = mapper.primary_key[0]
                query = query.filter(
                    rdb.not_(
                        pkey.in_([
                            instance_pkey(ob)[0]
                            for ob in getattr(context, self.property_name)
                        ])))
            self.results = query.all()
Exemplo n.º 2
0
    def update( self ):
        # we capture state from the last processed action, so our next action
        # becomes available.
        self.state = self.request.get( "%s.state"%self.property_name, self.state )
        # our previous state when we process searches is the add state, in order
        # to process the form values for the search action, we need to have search
        # widgets setup prior to the handler invocation, so do that here..
        if self.state == 'add':
            self.form_fields = core.setUpFields( self.domain_model, mode='search')
        
        # if we're doing a listing prepopulate state before rendering so we
        # display empty results status, and for a delete do it eagerly so
        # we can check our condition
        if self.state in ( 'listing', 'delete'):
            self.results = getattr( self.context, self.property_name)

        super( Many2ManyEdit, self).update()
        
        # if our state changes to listing
        if not self.results and self.state == 'listing':
            self.results = getattr( self.context, self.property_name)
Exemplo n.º 3
0
 def handle_add( self, action, data ):
     """
     sends user to search form.
     """
     self.state = 'add'
     session = Session()
     related_count = session.query( self.domain_model).count()
     if related_count > 20:
         self.form_fields = core.setUpFields( self.domain_model, mode='search')
     else:
         self.state = 'search'            
         query = session.query( self.domain_model )
         context = proxy.removeSecurityProxy( self.context )
         
         collection = getattr( context, self.property_name)
         if collection:
             mapper = orm.class_mapper( self.domain_model )
             instance_pkey = mapper.primary_key_from_instance
             pkey = mapper.primary_key[0]
             query = query.filter(
                 rdb.not_( pkey.in_( [ instance_pkey(ob)[0] for ob in getattr( context, self.property_name) ] ) )
                 )
         self.results = query.all()
Exemplo n.º 4
0
    def update(self):
        # we capture state from the last processed action, so our next action
        # becomes available.
        self.state = self.request.get("%s.state" % self.property_name,
                                      self.state)
        # our previous state when we process searches is the add state, in order
        # to process the form values for the search action, we need to have search
        # widgets setup prior to the handler invocation, so do that here..
        if self.state == 'add':
            self.form_fields = core.setUpFields(self.domain_model,
                                                mode='search')

        # if we're doing a listing prepopulate state before rendering so we
        # display empty results status, and for a delete do it eagerly so
        # we can check our condition
        if self.state in ('listing', 'delete'):
            self.results = getattr(self.context, self.property_name)

        super(Many2ManyEdit, self).update()

        # if our state changes to listing
        if not self.results and self.state == 'listing':
            self.results = getattr(self.context, self.property_name)