Skip to content

Commit 11645d3

Browse files
author
Richard Jones
committed
Keep a cache of compiled PageTemplates.
Reinstated query saving.
1 parent 38b3d9b commit 11645d3

File tree

7 files changed

+240
-104
lines changed

7 files changed

+240
-104
lines changed

TODO.txt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,15 @@ pending web: Quick help links next to the property labels giving a
4242
form element too, eg. how to use the nosy list edit box.
4343
pending web: clicking on a group header should filter for that type of entry
4444
pending web: re-enable auth by basic http auth
45+
pending web: search "refinement"
46+
- pre-fill the search page with the current search parameters)
47+
- add a drop-down with all queries which fills form with selected
48+
query values
4549

4650
New templating TODO:
4751
. generic class editing
4852
. classhelp
49-
. query saving
50-
- add ":queryname" to search form submission, and handle it in search action
51-
- ?add a drop-down on search page with all queries that fills form with
52-
each query's values?
53-
. search "refinement" (pre-fill the search page with the current search
54-
parameters)
53+
. rewritten documentation (can come after the beta though so stuff is settled)
5554

5655
ongoing: any bugs
5756

roundup/cgi/client.py

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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__ = """
44
WWW request handler (also used in the stand-alone server).
@@ -10,8 +10,9 @@
1010
from roundup import roundupdb, date, hyperdb, password
1111
from roundup.i18n import _
1212

13-
from roundup.cgi.templating import RoundupPageTemplate
13+
from roundup.cgi.templating import getTemplate, HTMLRequest
1414
from roundup.cgi import cgitb
15+
1516
from PageTemplates import PageTemplate
1617

1718
class 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

Comments
 (0)