1- # $Id: client.py,v 1.6 2002-09-02 07:46:55 richard Exp $
1+ # $Id: client.py,v 1.7 2002-09-03 02:58:11 richard Exp $
22
33__doc__ = """
44WWW request handler (also used in the stand-alone server).
1010from roundup import roundupdb , date , hyperdb , password
1111from roundup .i18n import _
1212
13- from roundup .cgi .templating import RoundupPageTemplate
13+ from roundup .cgi .templating import getTemplate , HTMLRequest
1414from roundup .cgi import cgitb
15+
1516from PageTemplates import PageTemplate
1617
1718class Unauthorised (ValueError ):
@@ -280,13 +281,11 @@ def serve_static_file(self, file):
280281 def template (self , name , ** kwargs ):
281282 ''' Return a PageTemplate for the named page
282283 '''
283- pt = RoundupPageTemplate (self )
284- # make errors nicer
285- pt .id = name
286- pt .write (open (os .path .join (self .instance .TEMPLATES , name )).read ())
287- # XXX handle PT rendering errors here nicely
284+ pt = getTemplate (self .instance .TEMPLATES , name )
285+ # XXX handle PT rendering errors here more nicely
288286 try :
289- return pt .render (** kwargs )
287+ # let the template render figure stuff out
288+ return pt .render (self , None , None , ** kwargs )
290289 except PageTemplate .PTRuntimeError , message :
291290 return '<strong>%s</strong><ol>%s</ol>' % (message ,
292291 '<li>' .join (pt ._v_errors ))
@@ -777,6 +776,9 @@ def searchAction(self):
777776 Set the form ":filter" variable based on the values of the
778777 filter variables - if they're set to anything other than
779778 "dontcare" then add them to :filter.
779+
780+ Also handle the ":queryname" variable and save off the query to
781+ the user's query list.
780782 '''
781783 # generic edit is per-class only
782784 if not self .searchPermission ():
@@ -790,6 +792,32 @@ def searchAction(self):
790792 if not self .form [key ].value : continue
791793 self .form .value .append (cgi .MiniFieldStorage (':filter' , key ))
792794
795+ # handle saving the query params
796+ if self .form .has_key (':queryname' ):
797+ queryname = self .form [':queryname' ].value .strip ()
798+ if queryname :
799+ # parse the environment and figure what the query _is_
800+ req = HTMLRequest (self )
801+ url = req .indexargs_href ('' , {})
802+
803+ # handle editing an existing query
804+ try :
805+ qid = self .db .query .lookup (queryname )
806+ self .db .query .set (qid , klass = self .classname , url = url )
807+ except KeyError :
808+ # create a query
809+ qid = self .db .query .create (name = queryname ,
810+ klass = self .classname , url = url )
811+
812+ # and add it to the user's query multilink
813+ queries = self .db .user .get (self .userid , 'queries' )
814+ queries .append (qid )
815+ self .db .user .set (self .userid , queries = queries )
816+
817+ # commit the query change to the database
818+ self .db .commit ()
819+
820+
793821 def searchPermission (self ):
794822 ''' Determine whether the user has permission to search this class.
795823
@@ -1004,13 +1032,10 @@ def parsePropsFromForm(db, cl, form, nodeid=0, num_re=re.compile('^\d+$')):
10041032 'value' : value , 'classname' : link }
10051033 elif isinstance (proptype , hyperdb .Multilink ):
10061034 value = form [key ]
1007- if hasattr (value , 'value' ):
1008- # Quite likely to be a FormItem instance
1009- value = value .value
10101035 if not isinstance (value , type ([])):
10111036 value = [i .strip () for i in value .split (',' )]
10121037 else :
1013- value = [i .strip () for i in value ]
1038+ value = [i .value . strip () for i in value ]
10141039 link = cl .properties [key ].classname
10151040 l = []
10161041 for entry in map (str , value ):
0 commit comments