badfrog ha scritto:
> On Sep 5, 6:16 am, Jorge Godoy <[EMAIL PROTECTED]> wrote:
>   
>> On Wednesday 05 September 2007 05:00:38 Diez B. Roggisch wrote:
>>
>>     
>>> But to be brutally honest: IMHO your whole approach is flawed. Because
>>> there is no such thing as a generic search. Making complex queries is
>>> always difficult to get right, especially when several clauses are involved
>>> etc. So I'd say - except from getting to know the tools of course - it's
>>> dead-end road you're walking there.
>>>       
>> I'd go for the traditional search box + radio button for where to search /
>> limit the search.
>>     
>
> Thanks... I appreciate the comments.
>
> Jorge -- That was the idea -- a list containing allowable search
> fieldnames + a textbox to type something in. Controller has an
> exposed"find" method which determines the field and value to search
> for based on parameters from the request. What I'm trying to avoid is
> the necessity to do something like
>
> if searchBy == "field1":
>    foo.select(field1=search)
> elif searchBy == "field2":
>    foo.select(field2=search)
>
> or to have methods like
> searchByField1
> searchByField2
>
> which all themselves would contain painfully similar foo.select calls.
> Doesn't seem very DRY to me. :)
>
>
>   
What you are searching is work of your Model not of controller.
I've done something similar but in my controller, in this manner i've 
only 1 search method for each class.
I've implemented hybrid system in SQLAlchemy for use of generative and 
explicit condition, but ithink you solution is similar to this


I hope this useful
Glauco





    @classmethod
    def search( self, select_clause=None, limit=None,       offset=None,\
                      order_by=[],        use_labels=False, add_columns=[],\
                      empty=False,        add_entity=[],    **kw  ):
        """
            DOC TXT
        """
       by_where_clause = {'azienda_stato_record':'A'}    # FIXED 
CONDITION DEFAULT VALUE
       where_clause = []
        for k,v in kw.items():
            if k in ('azienda_id_asl',
                     'azienda_id',
                     'azienda_bdn_id',
                     'azienda_inattivo',
                     'azienda_stato_record',
                     'anagrafica_id_comune'):
                if v:
                    by_where_clause[ k ] = v
            elif k == 'azienda_codice_aziendale' and v:
                where_clause.append( 
func.lower(self.c.codice_aziendale).like('%'+v.lower()+'%') )
            elif..............
            # i've something like 10 or more variable condition here

        return self._db_execute( select_clause=select_clause,
                                 limit=limit,
                                 offset=offset,
                                 order_by=order_by,
                                 use_labels=use_labels,
                                 add_columns=add_columns,
                                 add_entity=add_entity,
                                 by_where_clause=by_where_clause,
                                 where_clause=where_clause)











-- 
+------------------------------------------------------------+
                                  Glauco Uri - Programmatore
                                    glauco(at)allevatori.com 
                               
  Sfera Carta Software(r)      [EMAIL PROTECTED]
  Via Bazzanese,69  Casalecchio di Reno(BO) - Tel. 051591054 
+------------------------------------------------------------+



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to