Code

Fixes to the search form and saving queries.
authorgmcm <gmcm@57a73879-2fb5-44c3-a270-3262357dd7e2>
Wed, 31 Jul 2002 22:40:50 +0000 (22:40 +0000)
committergmcm <gmcm@57a73879-2fb5-44c3-a270-3262357dd7e2>
Wed, 31 Jul 2002 22:40:50 +0000 (22:40 +0000)
Fixes to  sorting in back_metakit.py.

git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@942 57a73879-2fb5-44c3-a270-3262357dd7e2

roundup/backends/back_metakit.py
roundup/cgi_client.py
roundup/htmltemplate.py

index 7d173c1856b134de95d2ea647e688bdf5d3ad5f1..46d82ea3c5f5a44b7a813cfc4fbf355692254632 100755 (executable)
@@ -46,6 +46,8 @@ class _Database(hyperdb.Database):
             except KeyError:
                 x = 0
             return x
+        elif classname == 'transactions':
+            return self.dirty
         return self.getclass(classname)
     def getclass(self, classname):
         return self.classes[classname]
@@ -479,10 +481,11 @@ class Class:
         row._isdel = 1
         if self.do_journal:
             self.db.addjournal(self.classname, nodeid, _RETIRE, {})
-        iv = self.getindexview(1)
-        ndx = iv.find(k=getattr(row, self.keyname),i=row.id)
-        if ndx > -1:
-            iv.delete(ndx)
+        if self.keyname:
+            iv = self.getindexview(1)
+            ndx = iv.find(k=getattr(row, self.keyname),i=row.id)
+            if ndx > -1:
+                iv.delete(ndx)
         self.db.dirty = 1
         self.fireReactors('retire', nodeid, None)
     def history(self, nodeid):
@@ -732,7 +735,24 @@ class Class:
                 try:
                     prop = getattr(v, propname)
                 except AttributeError:
+                    print "MK has no property %s" % propname
                     continue
+                propclass = self.ruprops.get(propname, None)
+                if propclass is None:
+                    propclass = self.privateprops.get(propname, None)
+                    if propclass is None:
+                        print "Schema has no property %s" % propname
+                        continue
+                if isinstance(propclass, hyperdb.Link):
+                    linkclass = self.db.getclass(propclass.classname)
+                    lv = linkclass.getview()
+                    lv = lv.rename('id', propname)
+                    v = v.join(lv, prop, 1)
+                    if linkclass.getprops().has_key('order'):
+                        propname = 'order'
+                    else:
+                        propname = linkclass.labelprop()
+                    prop = getattr(v, propname)
                 if isreversed:
                     rev.append(prop)
                 sortspec.append(prop)
index b24f0fd7955105fc351e6096498505b493439e31..b5da4150a5dbf20ccf08f4795dba2d210b244e94 100644 (file)
@@ -15,7 +15,7 @@
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 # 
-# $Id: cgi_client.py,v 1.152 2002-07-31 22:04:14 richard Exp $
+# $Id: cgi_client.py,v 1.153 2002-07-31 22:40:50 gmcm Exp $
 
 __doc__ = """
 WWW request handler (also used in the stand-alone server).
@@ -764,6 +764,7 @@ function help_window(helpurl, width, height) {
             filterspec = self.index_filterspec(filter, queries.get(self.nodeid, 'klass'))
             if self.form.has_key('search_text'):
                 search_text = self.form['search_text'].value
+                search_text = urllib.quote(search_text)
             else:
                 search_text = ''
             if self.form.has_key(':pagesize'):
@@ -782,15 +783,9 @@ function help_window(helpurl, width, height) {
             url += '&:pagesize=%s' % pagesize
             if search_text:
                 url += '&search_text=%s' % search_text
-            qname = self.form['name'].value
-            chgd = []
-            if qname != queries.get(self.nodeid, 'name'):
-                chgd.append('name')
             if url != queries.get(self.nodeid, 'url'):
-                chgd.append('url')
-            if chgd:
-                queries.set(self.nodeid, name=qname, url=url)
-                message = _('%(changes)s edited ok')%{'changes': ', '.join(chgd)}
+                queries.set(self.nodeid, url=url)
+                message = _('url edited ok')
             else:
                 message = _('nothing changed')
         else:
@@ -1357,7 +1352,7 @@ function help_window(helpurl, width, height) {
         # re-open the database for real, using the user
         self.opendb(self.user)
         password = cl.get(uid, 'password')
-        self.set_cookie(self.user, self.form['password'].value)
+        self.set_cookie(self.user, password)
         return 1
 
     def set_cookie(self, user, password):
@@ -1696,6 +1691,9 @@ def parsePropsFromForm(db, cl, form, nodeid=0, num_re=re.compile('^\d+$')):
 
 #
 # $Log: not supported by cvs2svn $
+# Revision 1.152  2002/07/31 22:04:14  richard
+# cleanup
+#
 # Revision 1.151  2002/07/30 21:37:43  richard
 # oops, thanks Duncan Booth for spotting this one
 #
index 6ad188b46bbb6150855f9f2f461a838284d9e10f..4fd620b4a6e6d2b1e85310f89b77a1eaeb89fd57 100644 (file)
@@ -15,7 +15,7 @@
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 # 
-# $Id: htmltemplate.py,v 1.107 2002-07-30 05:27:30 richard Exp $
+# $Id: htmltemplate.py,v 1.108 2002-07-31 22:40:50 gmcm Exp $
 
 __doc__ = """
 Template engine.
@@ -832,13 +832,15 @@ class TemplateFunctions:
         for k,v in query.items():
             query[k] = v[0].split(',')
         pagesize = query.get(':pagesize',['25'])[0]
+        search_text = query.get('search_text', [''])[0]
+        search_text = urllib.unquote(search_text)
         for k,v in query.items():
             if k[0] != ':':
                 filterspec[k] = v
         ixtmplt = IndexTemplate(self.client, self.templates, classname)
         qform = '<form onSubmit="return submit_once()" action="%s%s">\n'%(
             self.classname,self.nodeid)
-        qform += ixtmplt.filter_form(query.get('search_text', ''),
+        qform += ixtmplt.filter_form(search_text,
                                      query.get(':filter', []),
                                      query.get(':columns', []),
                                      query.get(':group', []),
@@ -931,6 +933,10 @@ class IndexTemplate(TemplateFunctions):
 
     def buildurl(self, filterspec, search_text, filter, columns, sort, group, pagesize):
         d = {'pagesize':pagesize, 'pagesize':pagesize, 'classname':self.classname}
+        if search_text:
+            d['searchtext'] = 'search_text=%s&' % search_text
+        else:
+            d['searchtext'] = ''
         d['filter'] = ','.join(map(urllib.quote,filter))
         d['columns'] = ','.join(map(urllib.quote,columns))
         d['sort'] = ','.join(map(urllib.quote,sort))
@@ -940,7 +946,7 @@ class IndexTemplate(TemplateFunctions):
             vals = ','.join(map(urllib.quote,vals))
             tmp.append('%s=%s' % (col, vals))
         d['filters'] = '&'.join(tmp)
-        return '%(classname)s?%(filters)s&:sort=%(sort)s&:filter=%(filter)s&:group=%(group)s&:columns=%(columns)s&:pagesize=%(pagesize)s' % d
+        return '%(classname)s?%(searchtext)s%(filters)s&:sort=%(sort)s&:filter=%(filter)s&:group=%(group)s&:columns=%(columns)s&:pagesize=%(pagesize)s' % d
     
     col_re=re.compile(r'<property\s+name="([^>]+)">')
     def render(self, filterspec={}, search_text='', filter=[], columns=[], 
@@ -989,8 +995,8 @@ class IndexTemplate(TemplateFunctions):
         for name in columns:
             cname = name.capitalize()
             if show_display_form:
-                sb = self.sortby(name, filterspec, columns, filter, group,
-                    sort, pagesize, startwith)
+                sb = self.sortby(name, search_text, filterspec, columns, filter, 
+                        group, sort, pagesize)
                 anchor = "%s?%s"%(self.classname, sb)
                 w('<td><span class="list-header"><a href="%s">%s</a>'
                     '</span></td>\n'%(anchor, cname))
@@ -1286,13 +1292,15 @@ class IndexTemplate(TemplateFunctions):
             w(' </tr>\n')
         w('</table>\n')
 
-    def sortby(self, sort_name, filterspec, columns, filter, group, sort,
-            pagesize, startwith):
+    def sortby(self, sort_name, search_text, filterspec, columns, filter, group, sort,
+            pagesize):
         ''' Figure the link for a column heading so we can sort by that
             column
         '''
         l = []
         w = l.append
+        if search_text:
+            w('search_text=%s' % search_text)
         for k, v in filterspec.items():
             k = urllib.quote(k)
             if type(v) == type([]):
@@ -1306,7 +1314,7 @@ class IndexTemplate(TemplateFunctions):
         if group:
             w(':group=%s'%','.join(map(urllib.quote, group)))
         w(':pagesize=%s' % pagesize)
-        w(':startwith=%s' % startwith)
+        w(':startwith=0')
 
         # handle the sorting - if we're already sorting by this column,
         # then reverse the sorting, otherwise set the sorting to be this
@@ -1433,6 +1441,9 @@ class NewItemTemplate(ItemTemplate):
 
 #
 # $Log: not supported by cvs2svn $
+# Revision 1.107  2002/07/30 05:27:30  richard
+# nicer error messages, and a bugfix
+#
 # Revision 1.106  2002/07/30 02:41:04  richard
 # Removed the confusing, ugly two-column sorting stuff. Column heading clicks
 # now only sort on one column. Nice and simple and obvious.