Skip to content

Commit 11f4222

Browse files
author
Ralf Schlatterbeck
committed
factor getCurrentURL into its own method:
I'm using a query on a class with two different templates. Now I want to be able to store the template as part of the query. The current indexargs_url implementation strips the @template part. Factoring the URL computation lets me override the action to use in my template. But maybe the url-computation should be changed to include the template in use when storing a query? See example code in the comment.
1 parent c6cc567 commit 11f4222

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

roundup/cgi/actions.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#$Id: actions.py,v 1.62 2006-08-11 05:41:32 richard Exp $
1+
#$Id: actions.py,v 1.63 2007-01-10 20:16:17 schlatterbeck Exp $
22

33
import re, cgi, StringIO, urllib, Cookie, time, random, csv, codecs
44

@@ -150,19 +150,14 @@ def handle(self):
150150
queryname = self.getQueryName()
151151

152152
# editing existing query name?
153-
old_queryname = ''
154-
for key in ('@old-queryname', ':old-queryname'):
155-
if self.form.has_key(key):
156-
old_queryname = self.form[key].value.strip()
153+
old_queryname = self.getFromForm('old-queryname')
157154

158155
# handle saving the query params
159156
if queryname:
160157
# parse the environment and figure what the query _is_
161158
req = templating.HTMLRequest(self.client)
162159

163-
# The [1:] strips off the '?' character, it isn't part of the
164-
# query string.
165-
url = req.indexargs_url('', {})[1:]
160+
url = self.getCurrentURL(req)
166161

167162
key = self.db.query.getkey()
168163
if key:
@@ -247,12 +242,26 @@ def fakeFilterVars(self):
247242

248243
self.form.value.append(cgi.MiniFieldStorage('@filter', key))
249244

250-
def getQueryName(self):
251-
for key in ('@queryname', ':queryname'):
245+
def getCurrentURL(self, req):
246+
"""Get current URL for storing as a query.
247+
The [1:] strips off the '?' character, it isn't part of the
248+
query string.
249+
But maybe the template should be part of the stored query:
250+
template = self.getFromForm('template')
251+
if template:
252+
return req.indexargs_url('', {'@template' : template})[1:]
253+
"""
254+
return req.indexargs_url('', {})[1:]
255+
256+
def getFromForm(self, name):
257+
for key in ('@' + name, ':' + name):
252258
if self.form.has_key(key):
253259
return self.form[key].value.strip()
254260
return ''
255261

262+
def getQueryName(self):
263+
return self.getFromForm('queryname')
264+
256265
class EditCSVAction(Action):
257266
name = 'edit'
258267
permissionType = 'Edit'

0 commit comments

Comments
 (0)