Code

query "editing" now working, minus filling the form in with the query params
authorrichard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2>
Tue, 10 Sep 2002 03:57:50 +0000 (03:57 +0000)
committerrichard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2>
Tue, 10 Sep 2002 03:57:50 +0000 (03:57 +0000)
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1118 57a73879-2fb5-44c3-a270-3262357dd7e2

roundup/cgi/templating.py
roundup/templates/classic/html/query.item

index 904ee97d13af43b92e4804e702f85d7eacad43ae..f133edbe32d7781e71fb4ae6cae8c4d9c39f0f2c 100644 (file)
@@ -360,13 +360,8 @@ class HTMLClass:
         # new template, using the specified classname and request
         pt = getTemplate(self._db.config.TEMPLATES, self.classname, name)
 
-        # XXX handle PT rendering errors here nicely
-        try:
-            # use our fabricated request
-            return pt.render(self._client, self.classname, req)
-        except PageTemplate.PTRuntimeError, message:
-            return '<strong>%s</strong><ol>%s</ol>'%(message,
-                cgi.escape('<li>'.join(pt._v_errors)))
+        # use our fabricated request
+        return pt.render(self._client, self.classname, req)
 
 class HTMLItem:
     ''' Accesses through an *item*
@@ -568,6 +563,20 @@ class HTMLItem:
         l.append('</table>')
         return '\n'.join(l)
 
+    def renderQueryForm(self):
+        ''' Render this item, which is a query, as a search form.
+        '''
+        # create a new request and override the specified args
+        req = HTMLRequest(self._client)
+        req.classname = self._klass.get(self._nodeid, 'klass')
+        req.updateFromURL(self._klass.get(self._nodeid, 'url'))
+
+        # new template, using the specified classname and request
+        pt = getTemplate(self._db.config.TEMPLATES, req.classname, 'search')
+
+        # use our fabricated request
+        return pt.render(self._client, req.classname, req)
+
 class HTMLUser(HTMLItem):
     ''' Accesses through the *user* (a special case of item)
     '''
@@ -1035,6 +1044,11 @@ class HTMLRequest:
         self.classname = client.classname
         self.template = client.template
 
+        self._post_init()
+
+    def _post_init(self):
+        ''' Set attributes based on self.form
+        '''
         # extract the index display information from the form
         self.columns = []
         if self.form.has_key(':columns'):
@@ -1096,7 +1110,25 @@ class HTMLRequest:
         else:
             self.startwith = 0
 
+    def updateFromURL(self, url):
+        ''' Parse the URL for query args, and update my attributes using the
+            values.
+        ''' 
+        self.form = {}
+        for name, value in cgi.parse_qsl(url):
+            if self.form.has_key(name):
+                if isinstance(self.form[name], type([])):
+                    self.form[name].append(cgi.MiniFieldStorage(name, value))
+                else:
+                    self.form[name] = [self.form[name],
+                        cgi.MiniFieldStorage(name, value)]
+            else:
+                self.form[name] = cgi.MiniFieldStorage(name, value)
+        self._post_init()
+
     def update(self, kwargs):
+        ''' Update my attributes using the keyword args
+        '''
         self.__dict__.update(kwargs)
         if kwargs.has_key('columns'):
             self.show = ShowDict(self.columns)
index 681d75b6b50cb0d7cd1bdf91535a3654d451ee5c..2b5a64842b70cbee9a514f25d1a4817ca6d4ae9e 100755 (executable)
@@ -1,24 +1,2 @@
-<table class="form">
-<tr>
-  <th>Class</th>
-  <td tal:content="structure context/klass/field"></td>
-</tr>
-
-<tr>
-  <th>Name</th>
-  <td tal:content="structure context/name/field"></td>
-</tr>
-
-<tr>
-  <td colspan=2>
-   hrm. filterspec here...
-   <display call="filterspec('klass','url')">
-  </td>
-</tr>
-
-<tr>
-  <td>&nbsp;</td>
-  <td tal:content="structure context/submit">submit button here</td>
-</tr>
-</table>
+<span tal:content="structure context/renderQueryForm" />