Mercurial > p > roundup > code
annotate roundup/cgi/templating.py @ 1669:17ec0bd6ecc5 maint-0.5
*** empty log message ***
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Wed, 18 Jun 2003 23:52:54 +0000 |
| parents | 9e8ff9784a5f |
| children | 8054b5813aa3 |
| rev | line source |
|---|---|
|
1356
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1 import sys, cgi, urllib, os, re, os.path, time, errno |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3 from roundup import hyperdb, date |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
4 from roundup.i18n import _ |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
5 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
6 try: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
7 import cPickle as pickle |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
8 except ImportError: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
9 import pickle |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
10 try: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
11 import cStringIO as StringIO |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
12 except ImportError: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
13 import StringIO |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
14 try: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
15 import StructuredText |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
16 except ImportError: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
17 StructuredText = None |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
18 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
19 # bring in the templating support |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
20 from roundup.cgi.PageTemplates import PageTemplate |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
21 from roundup.cgi.PageTemplates.Expressions import getEngine |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
22 from roundup.cgi.TAL.TALInterpreter import TALInterpreter |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
23 from roundup.cgi import ZTUtils |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
24 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
25 class NoTemplate(Exception): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
26 pass |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
27 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
28 class Templates: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
29 templates = {} |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
30 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
31 def __init__(self, dir): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
32 self.dir = dir |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
33 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
34 def precompileTemplates(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
35 ''' Go through a directory and precompile all the templates therein |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
36 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
37 for filename in os.listdir(self.dir): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
38 if os.path.isdir(filename): continue |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
39 if '.' in filename: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
40 name, extension = filename.split('.') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
41 self.getTemplate(name, extension) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
42 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
43 self.getTemplate(filename, None) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
44 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
45 def get(self, name, extension): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
46 ''' Interface to get a template, possibly loading a compiled template. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
47 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
48 "name" and "extension" indicate the template we're after, which in |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
49 most cases will be "name.extension". If "extension" is None, then |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
50 we look for a template just called "name" with no extension. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
51 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
52 If the file "name.extension" doesn't exist, we look for |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
53 "_generic.extension" as a fallback. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
54 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
55 # default the name to "home" |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
56 if name is None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
57 name = 'home' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
58 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
59 # find the source, figure the time it was last modified |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
60 if extension: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
61 filename = '%s.%s'%(name, extension) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
62 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
63 filename = name |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
64 src = os.path.join(self.dir, filename) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
65 try: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
66 stime = os.stat(src)[os.path.stat.ST_MTIME] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
67 except os.error, error: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
68 if error.errno != errno.ENOENT: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
69 raise |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
70 if not extension: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
71 raise NoTemplate, 'Template file "%s" doesn\'t exist'%name |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
72 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
73 # try for a generic template |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
74 generic = '_generic.%s'%extension |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
75 src = os.path.join(self.dir, generic) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
76 try: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
77 stime = os.stat(src)[os.path.stat.ST_MTIME] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
78 except os.error, error: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
79 if error.errno != errno.ENOENT: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
80 raise |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
81 # nicer error |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
82 raise NoTemplate, 'No template file exists for templating '\ |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
83 '"%s" with template "%s" (neither "%s" nor "%s")'%(name, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
84 extension, filename, generic) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
85 filename = generic |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
86 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
87 if self.templates.has_key(src) and \ |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
88 stime < self.templates[src].mtime: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
89 # compiled template is up to date |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
90 return self.templates[src] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
91 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
92 # compile the template |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
93 self.templates[src] = pt = RoundupPageTemplate() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
94 pt.write(open(src).read()) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
95 pt.id = filename |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
96 pt.mtime = time.time() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
97 return pt |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
98 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
99 def __getitem__(self, name): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
100 name, extension = os.path.splitext(name) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
101 if extension: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
102 extension = extension[1:] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
103 try: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
104 return self.get(name, extension) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
105 except NoTemplate, message: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
106 raise KeyError, message |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
107 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
108 class RoundupPageTemplate(PageTemplate.PageTemplate): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
109 ''' A Roundup-specific PageTemplate. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
110 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
111 Interrogate the client to set up the various template variables to |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
112 be available: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
113 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
114 *context* |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
115 this is one of three things: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
116 1. None - we're viewing a "home" page |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
117 2. The current class of item being displayed. This is an HTMLClass |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
118 instance. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
119 3. The current item from the database, if we're viewing a specific |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
120 item, as an HTMLItem instance. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
121 *request* |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
122 Includes information about the current request, including: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
123 - the url |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
124 - the current index information (``filterspec``, ``filter`` args, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
125 ``properties``, etc) parsed out of the form. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
126 - methods for easy filterspec link generation |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
127 - *user*, the current user node as an HTMLItem instance |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
128 - *form*, the current CGI form information as a FieldStorage |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
129 *config* |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
130 The current tracker config. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
131 *db* |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
132 The current database, used to access arbitrary database items. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
133 *utils* |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
134 This is a special class that has its base in the TemplatingUtils |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
135 class in this file. If the tracker interfaces module defines a |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
136 TemplatingUtils class then it is mixed in, overriding the methods |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
137 in the base class. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
138 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
139 def getContext(self, client, classname, request): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
140 # construct the TemplatingUtils class |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
141 utils = TemplatingUtils |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
142 if hasattr(client.instance.interfaces, 'TemplatingUtils'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
143 class utils(client.instance.interfaces.TemplatingUtils, utils): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
144 pass |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
145 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
146 c = { |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
147 'options': {}, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
148 'nothing': None, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
149 'request': request, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
150 'db': HTMLDatabase(client), |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
151 'config': client.instance.config, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
152 'tracker': client.instance, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
153 'utils': utils(client), |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
154 'templates': Templates(client.instance.config.TEMPLATES), |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
155 } |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
156 # add in the item if there is one |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
157 if client.nodeid: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
158 if classname == 'user': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
159 c['context'] = HTMLUser(client, classname, client.nodeid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
160 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
161 c['context'] = HTMLItem(client, classname, client.nodeid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
162 elif client.db.classes.has_key(classname): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
163 c['context'] = HTMLClass(client, classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
164 return c |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
165 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
166 def render(self, client, classname, request, **options): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
167 """Render this Page Template""" |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
168 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
169 if not self._v_cooked: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
170 self._cook() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
171 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
172 __traceback_supplement__ = (PageTemplate.PageTemplateTracebackSupplement, self) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
173 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
174 if self._v_errors: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
175 raise PageTemplate.PTRuntimeError, \ |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
176 'Page Template %s has errors.'%self.id |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
177 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
178 # figure the context |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
179 classname = classname or client.classname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
180 request = request or HTMLRequest(client) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
181 c = self.getContext(client, classname, request) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
182 c.update({'options': options}) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
183 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
184 # and go |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
185 output = StringIO.StringIO() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
186 TALInterpreter(self._v_program, self.macros, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
187 getEngine().getContext(c), output, tal=1, strictinsert=0)() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
188 return output.getvalue() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
189 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
190 class HTMLDatabase: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
191 ''' Return HTMLClasses for valid class fetches |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
192 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
193 def __init__(self, client): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
194 self._client = client |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
195 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
196 # we want config to be exposed |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
197 self.config = client.db.config |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
198 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
199 def __getitem__(self, item): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
200 self._client.db.getclass(item) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
201 return HTMLClass(self._client, item) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
202 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
203 def __getattr__(self, attr): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
204 try: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
205 return self[attr] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
206 except KeyError: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
207 raise AttributeError, attr |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
208 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
209 def classes(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
210 l = self._client.db.classes.keys() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
211 l.sort() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
212 return [HTMLClass(self._client, cn) for cn in l] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
213 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
214 def lookupIds(db, prop, ids, num_re=re.compile('-?\d+')): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
215 cl = db.getclass(prop.classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
216 l = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
217 for entry in ids: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
218 if num_re.match(entry): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
219 l.append(entry) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
220 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
221 try: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
222 l.append(cl.lookup(entry)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
223 except KeyError: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
224 # ignore invalid keys |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
225 pass |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
226 return l |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
227 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
228 class HTMLPermissions: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
229 ''' Helpers that provide answers to commonly asked Permission questions. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
230 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
231 def is_edit_ok(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
232 ''' Is the user allowed to Edit the current class? |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
233 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
234 return self._db.security.hasPermission('Edit', self._client.userid, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
235 self._classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
236 def is_view_ok(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
237 ''' Is the user allowed to View the current class? |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
238 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
239 return self._db.security.hasPermission('View', self._client.userid, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
240 self._classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
241 def is_only_view_ok(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
242 ''' Is the user only allowed to View (ie. not Edit) the current class? |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
243 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
244 return self.is_view_ok() and not self.is_edit_ok() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
245 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
246 class HTMLClass(HTMLPermissions): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
247 ''' Accesses through a class (either through *class* or *db.<classname>*) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
248 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
249 def __init__(self, client, classname): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
250 self._client = client |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
251 self._db = client.db |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
252 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
253 # we want classname to be exposed, but _classname gives a |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
254 # consistent API for extending Class/Item |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
255 self._classname = self.classname = classname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
256 self._klass = self._db.getclass(self.classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
257 self._props = self._klass.getprops() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
258 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
259 def __repr__(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
260 return '<HTMLClass(0x%x) %s>'%(id(self), self.classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
261 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
262 def __getitem__(self, item): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
263 ''' return an HTMLProperty instance |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
264 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
265 #print 'HTMLClass.getitem', (self, item) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
266 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
267 # we don't exist |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
268 if item == 'id': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
269 return None |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
270 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
271 # get the property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
272 prop = self._props[item] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
273 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
274 # look up the correct HTMLProperty class |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
275 form = self._client.form |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
276 for klass, htmlklass in propclasses: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
277 if not isinstance(prop, klass): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
278 continue |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
279 if form.has_key(item): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
280 if isinstance(prop, hyperdb.Multilink): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
281 value = lookupIds(self._db, prop, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
282 handleListCGIValue(form[item])) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
283 elif isinstance(prop, hyperdb.Link): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
284 value = form[item].value.strip() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
285 if value: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
286 value = lookupIds(self._db, prop, [value])[0] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
287 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
288 value = None |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
289 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
290 value = form[item].value.strip() or None |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
291 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
292 if isinstance(prop, hyperdb.Multilink): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
293 value = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
294 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
295 value = None |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
296 return htmlklass(self._client, '', prop, item, value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
297 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
298 # no good |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
299 raise KeyError, item |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
300 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
301 def __getattr__(self, attr): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
302 ''' convenience access ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
303 try: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
304 return self[attr] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
305 except KeyError: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
306 raise AttributeError, attr |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
307 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
308 def getItem(self, itemid, num_re=re.compile('\d+')): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
309 ''' Get an item of this class by its item id. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
310 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
311 # make sure we're looking at an itemid |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
312 if not num_re.match(itemid): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
313 itemid = self._klass.lookup(itemid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
314 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
315 if self.classname == 'user': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
316 klass = HTMLUser |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
317 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
318 klass = HTMLItem |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
319 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
320 return klass(self._client, self.classname, itemid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
321 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
322 def properties(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
323 ''' Return HTMLProperty for all of this class' properties. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
324 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
325 l = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
326 for name, prop in self._props.items(): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
327 for klass, htmlklass in propclasses: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
328 if isinstance(prop, hyperdb.Multilink): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
329 value = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
330 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
331 value = None |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
332 if isinstance(prop, klass): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
333 l.append(htmlklass(self._client, '', prop, name, value)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
334 return l |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
335 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
336 def list(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
337 ''' List all items in this class. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
338 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
339 if self.classname == 'user': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
340 klass = HTMLUser |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
341 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
342 klass = HTMLItem |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
343 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
344 # get the list and sort it nicely |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
345 l = self._klass.list() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
346 sortfunc = make_sort_function(self._db, self.classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
347 l.sort(sortfunc) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
348 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
349 l = [klass(self._client, self.classname, x) for x in l] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
350 return l |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
351 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
352 def csv(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
353 ''' Return the items of this class as a chunk of CSV text. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
354 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
355 # get the CSV module |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
356 try: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
357 import csv |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
358 except ImportError: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
359 return 'Sorry, you need the csv module to use this function.\n'\ |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
360 'Get it from: http://www.object-craft.com.au/projects/csv/' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
361 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
362 props = self.propnames() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
363 p = csv.parser() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
364 s = StringIO.StringIO() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
365 s.write(p.join(props) + '\n') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
366 for nodeid in self._klass.list(): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
367 l = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
368 for name in props: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
369 value = self._klass.get(nodeid, name) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
370 if value is None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
371 l.append('') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
372 elif isinstance(value, type([])): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
373 l.append(':'.join(map(str, value))) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
374 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
375 l.append(str(self._klass.get(nodeid, name))) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
376 s.write(p.join(l) + '\n') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
377 return s.getvalue() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
378 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
379 def propnames(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
380 ''' Return the list of the names of the properties of this class. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
381 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
382 idlessprops = self._klass.getprops(protected=0).keys() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
383 idlessprops.sort() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
384 return ['id'] + idlessprops |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
385 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
386 def filter(self, request=None): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
387 ''' Return a list of items from this class, filtered and sorted |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
388 by the current requested filterspec/filter/sort/group args |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
389 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
390 if request is not None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
391 filterspec = request.filterspec |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
392 sort = request.sort |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
393 group = request.group |
|
1410
3a853f1c20b5
backporting fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1400
diff
changeset
|
394 else: |
|
3a853f1c20b5
backporting fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1400
diff
changeset
|
395 filterspec = {} |
|
3a853f1c20b5
backporting fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1400
diff
changeset
|
396 sort = (None,None) |
|
3a853f1c20b5
backporting fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1400
diff
changeset
|
397 group = (None,None) |
|
1356
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
398 if self.classname == 'user': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
399 klass = HTMLUser |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
400 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
401 klass = HTMLItem |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
402 l = [klass(self._client, self.classname, x) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
403 for x in self._klass.filter(None, filterspec, sort, group)] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
404 return l |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
405 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
406 def classhelp(self, properties=None, label='list', width='500', |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
407 height='400'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
408 ''' Pop up a javascript window with class help |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
409 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
410 This generates a link to a popup window which displays the |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
411 properties indicated by "properties" of the class named by |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
412 "classname". The "properties" should be a comma-separated list |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
413 (eg. 'id,name,description'). Properties defaults to all the |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
414 properties of a class (excluding id, creator, created and |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
415 activity). |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
416 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
417 You may optionally override the label displayed, the width and |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
418 height. The popup window will be resizable and scrollable. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
419 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
420 if properties is None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
421 properties = self._klass.getprops(protected=0).keys() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
422 properties.sort() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
423 properties = ','.join(properties) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
424 return '<a href="javascript:help_window(\'%s?:template=help&' \ |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
425 'properties=%s\', \'%s\', \'%s\')"><b>(%s)</b></a>'%( |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
426 self.classname, properties, width, height, label) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
427 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
428 def submit(self, label="Submit New Entry"): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
429 ''' Generate a submit button (and action hidden element) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
430 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
431 return ' <input type="hidden" name=":action" value="new">\n'\ |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
432 ' <input type="submit" name="submit" value="%s">'%label |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
433 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
434 def history(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
435 return 'New node - no history' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
436 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
437 def renderWith(self, name, **kwargs): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
438 ''' Render this class with the given template. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
439 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
440 # create a new request and override the specified args |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
441 req = HTMLRequest(self._client) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
442 req.classname = self.classname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
443 req.update(kwargs) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
444 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
445 # new template, using the specified classname and request |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
446 pt = Templates(self._db.config.TEMPLATES).get(self.classname, name) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
447 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
448 # use our fabricated request |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
449 return pt.render(self._client, self.classname, req) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
450 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
451 class HTMLItem(HTMLPermissions): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
452 ''' Accesses through an *item* |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
453 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
454 def __init__(self, client, classname, nodeid): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
455 self._client = client |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
456 self._db = client.db |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
457 self._classname = classname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
458 self._nodeid = nodeid |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
459 self._klass = self._db.getclass(classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
460 self._props = self._klass.getprops() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
461 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
462 def __repr__(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
463 return '<HTMLItem(0x%x) %s %s>'%(id(self), self._classname, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
464 self._nodeid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
465 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
466 def __getitem__(self, item): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
467 ''' return an HTMLProperty instance |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
468 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
469 #print 'HTMLItem.getitem', (self, item) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
470 if item == 'id': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
471 return self._nodeid |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
472 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
473 # get the property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
474 prop = self._props[item] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
475 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
476 # get the value, handling missing values |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
477 value = self._klass.get(self._nodeid, item, None) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
478 if value is None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
479 if isinstance(self._props[item], hyperdb.Multilink): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
480 value = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
481 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
482 # look up the correct HTMLProperty class |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
483 for klass, htmlklass in propclasses: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
484 if isinstance(prop, klass): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
485 return htmlklass(self._client, self._nodeid, prop, item, value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
486 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
487 raise KeyErorr, item |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
488 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
489 def __getattr__(self, attr): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
490 ''' convenience access to properties ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
491 try: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
492 return self[attr] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
493 except KeyError: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
494 raise AttributeError, attr |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
495 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
496 def submit(self, label="Submit Changes"): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
497 ''' Generate a submit button (and action hidden element) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
498 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
499 return ' <input type="hidden" name=":action" value="edit">\n'\ |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
500 ' <input type="submit" name="submit" value="%s">'%label |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
501 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
502 def journal(self, direction='descending'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
503 ''' Return a list of HTMLJournalEntry instances. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
504 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
505 # XXX do this |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
506 return [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
507 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
508 def history(self, direction='descending', dre=re.compile('\d+')): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
509 l = ['<table class="history">' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
510 '<tr><th colspan="4" class="header">', |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
511 _('History'), |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
512 '</th></tr><tr>', |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
513 _('<th>Date</th>'), |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
514 _('<th>User</th>'), |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
515 _('<th>Action</th>'), |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
516 _('<th>Args</th>'), |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
517 '</tr>'] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
518 comments = {} |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
519 history = self._klass.history(self._nodeid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
520 history.sort() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
521 if direction == 'descending': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
522 history.reverse() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
523 for id, evt_date, user, action, args in history: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
524 date_s = str(evt_date).replace("."," ") |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
525 arg_s = '' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
526 if action == 'link' and type(args) == type(()): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
527 if len(args) == 3: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
528 linkcl, linkid, key = args |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
529 arg_s += '<a href="%s%s">%s%s %s</a>'%(linkcl, linkid, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
530 linkcl, linkid, key) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
531 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
532 arg_s = str(args) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
533 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
534 elif action == 'unlink' and type(args) == type(()): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
535 if len(args) == 3: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
536 linkcl, linkid, key = args |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
537 arg_s += '<a href="%s%s">%s%s %s</a>'%(linkcl, linkid, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
538 linkcl, linkid, key) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
539 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
540 arg_s = str(args) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
541 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
542 elif type(args) == type({}): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
543 cell = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
544 for k in args.keys(): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
545 # try to get the relevant property and treat it |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
546 # specially |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
547 try: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
548 prop = self._props[k] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
549 except KeyError: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
550 prop = None |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
551 if prop is not None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
552 if args[k] and (isinstance(prop, hyperdb.Multilink) or |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
553 isinstance(prop, hyperdb.Link)): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
554 # figure what the link class is |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
555 classname = prop.classname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
556 try: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
557 linkcl = self._db.getclass(classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
558 except KeyError: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
559 labelprop = None |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
560 comments[classname] = _('''The linked class |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
561 %(classname)s no longer exists''')%locals() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
562 labelprop = linkcl.labelprop(1) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
563 hrefable = os.path.exists( |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
564 os.path.join(self._db.config.TEMPLATES, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
565 classname+'.item')) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
566 |
|
1511
9e8ff9784a5f
fix for odd Multilink journalling
Richard Jones <richard@users.sourceforge.net>
parents:
1452
diff
changeset
|
567 if isinstance(prop, hyperdb.Multilink) and args[k]: |
|
1356
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
568 ml = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
569 for linkid in args[k]: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
570 if isinstance(linkid, type(())): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
571 sublabel = linkid[0] + ' ' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
572 linkids = linkid[1] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
573 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
574 sublabel = '' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
575 linkids = [linkid] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
576 subml = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
577 for linkid in linkids: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
578 label = classname + linkid |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
579 # if we have a label property, try to use it |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
580 # TODO: test for node existence even when |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
581 # there's no labelprop! |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
582 try: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
583 if labelprop is not None and \ |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
584 labelprop != 'id': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
585 label = linkcl.get(linkid, labelprop) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
586 except IndexError: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
587 comments['no_link'] = _('''<strike>The |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
588 linked node no longer |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
589 exists</strike>''') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
590 subml.append('<strike>%s</strike>'%label) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
591 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
592 if hrefable: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
593 subml.append('<a href="%s%s">%s</a>'%( |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
594 classname, linkid, label)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
595 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
596 subml.append(label) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
597 ml.append(sublabel + ', '.join(subml)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
598 cell.append('%s:\n %s'%(k, ', '.join(ml))) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
599 elif isinstance(prop, hyperdb.Link) and args[k]: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
600 label = classname + args[k] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
601 # if we have a label property, try to use it |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
602 # TODO: test for node existence even when |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
603 # there's no labelprop! |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
604 if labelprop is not None and labelprop != 'id': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
605 try: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
606 label = linkcl.get(args[k], labelprop) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
607 except IndexError: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
608 comments['no_link'] = _('''<strike>The |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
609 linked node no longer |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
610 exists</strike>''') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
611 cell.append(' <strike>%s</strike>,\n'%label) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
612 # "flag" this is done .... euwww |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
613 label = None |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
614 if label is not None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
615 if hrefable: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
616 cell.append('%s: <a href="%s%s">%s</a>\n'%(k, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
617 classname, args[k], label)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
618 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
619 cell.append('%s: %s' % (k,label)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
620 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
621 elif isinstance(prop, hyperdb.Date) and args[k]: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
622 d = date.Date(args[k]) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
623 cell.append('%s: %s'%(k, str(d))) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
624 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
625 elif isinstance(prop, hyperdb.Interval) and args[k]: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
626 d = date.Interval(args[k]) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
627 cell.append('%s: %s'%(k, str(d))) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
628 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
629 elif isinstance(prop, hyperdb.String) and args[k]: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
630 cell.append('%s: %s'%(k, cgi.escape(args[k]))) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
631 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
632 elif not args[k]: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
633 cell.append('%s: (no value)\n'%k) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
634 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
635 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
636 cell.append('%s: %s\n'%(k, str(args[k]))) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
637 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
638 # property no longer exists |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
639 comments['no_exist'] = _('''<em>The indicated property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
640 no longer exists</em>''') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
641 cell.append('<em>%s: %s</em>\n'%(k, str(args[k]))) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
642 arg_s = '<br />'.join(cell) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
643 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
644 # unkown event!! |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
645 comments['unknown'] = _('''<strong><em>This event is not |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
646 handled by the history display!</em></strong>''') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
647 arg_s = '<strong><em>' + str(args) + '</em></strong>' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
648 date_s = date_s.replace(' ', ' ') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
649 # if the user's an itemid, figure the username (older journals |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
650 # have the username) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
651 if dre.match(user): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
652 user = self._db.user.get(user, 'username') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
653 l.append('<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>'%( |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
654 date_s, user, action, arg_s)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
655 if comments: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
656 l.append(_('<tr><td colspan=4><strong>Note:</strong></td></tr>')) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
657 for entry in comments.values(): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
658 l.append('<tr><td colspan=4>%s</td></tr>'%entry) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
659 l.append('</table>') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
660 return '\n'.join(l) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
661 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
662 def renderQueryForm(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
663 ''' Render this item, which is a query, as a search form. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
664 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
665 # create a new request and override the specified args |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
666 req = HTMLRequest(self._client) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
667 req.classname = self._klass.get(self._nodeid, 'klass') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
668 name = self._klass.get(self._nodeid, 'name') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
669 req.updateFromURL(self._klass.get(self._nodeid, 'url') + |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
670 '&:queryname=%s'%urllib.quote(name)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
671 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
672 # new template, using the specified classname and request |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
673 pt = Templates(self._db.config.TEMPLATES).get(req.classname, 'search') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
674 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
675 # use our fabricated request |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
676 return pt.render(self._client, req.classname, req) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
677 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
678 class HTMLUser(HTMLItem): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
679 ''' Accesses through the *user* (a special case of item) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
680 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
681 def __init__(self, client, classname, nodeid): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
682 HTMLItem.__init__(self, client, 'user', nodeid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
683 self._default_classname = client.classname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
684 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
685 # used for security checks |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
686 self._security = client.db.security |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
687 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
688 _marker = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
689 def hasPermission(self, role, classname=_marker): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
690 ''' Determine if the user has the Role. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
691 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
692 The class being tested defaults to the template's class, but may |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
693 be overidden for this test by suppling an alternate classname. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
694 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
695 if classname is self._marker: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
696 classname = self._default_classname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
697 return self._security.hasPermission(role, self._nodeid, classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
698 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
699 def is_edit_ok(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
700 ''' Is the user allowed to Edit the current class? |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
701 Also check whether this is the current user's info. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
702 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
703 return self._db.security.hasPermission('Edit', self._client.userid, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
704 self._classname) or self._nodeid == self._client.userid |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
705 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
706 def is_view_ok(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
707 ''' Is the user allowed to View the current class? |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
708 Also check whether this is the current user's info. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
709 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
710 return self._db.security.hasPermission('Edit', self._client.userid, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
711 self._classname) or self._nodeid == self._client.userid |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
712 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
713 class HTMLProperty: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
714 ''' String, Number, Date, Interval HTMLProperty |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
715 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
716 Has useful attributes: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
717 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
718 _name the name of the property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
719 _value the value of the property if any |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
720 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
721 A wrapper object which may be stringified for the plain() behaviour. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
722 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
723 def __init__(self, client, nodeid, prop, name, value): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
724 self._client = client |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
725 self._db = client.db |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
726 self._nodeid = nodeid |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
727 self._prop = prop |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
728 self._name = name |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
729 self._value = value |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
730 def __repr__(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
731 return '<HTMLProperty(0x%x) %s %r %r>'%(id(self), self._name, self._prop, self._value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
732 def __str__(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
733 return self.plain() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
734 def __cmp__(self, other): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
735 if isinstance(other, HTMLProperty): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
736 return cmp(self._value, other._value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
737 return cmp(self._value, other) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
738 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
739 class StringHTMLProperty(HTMLProperty): |
|
1400
3c9bd1faddd8
backporting fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1371
diff
changeset
|
740 hyper_re = re.compile(r'((?P<url>\w{3,6}://\S+)|' |
|
3c9bd1faddd8
backporting fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1371
diff
changeset
|
741 r'(?P<email>[\w\.]+@[\w\.\-]+)|' |
|
3c9bd1faddd8
backporting fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1371
diff
changeset
|
742 r'(?P<item>(?P<class>[a-z_]+)(?P<id>\d+)))') |
|
3c9bd1faddd8
backporting fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1371
diff
changeset
|
743 def _hyper_repl(self, match): |
|
3c9bd1faddd8
backporting fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1371
diff
changeset
|
744 if match.group('url'): |
|
3c9bd1faddd8
backporting fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1371
diff
changeset
|
745 s = match.group('url') |
|
3c9bd1faddd8
backporting fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1371
diff
changeset
|
746 return '<a href="%s">%s</a>'%(s, s) |
|
3c9bd1faddd8
backporting fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1371
diff
changeset
|
747 elif match.group('email'): |
|
3c9bd1faddd8
backporting fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1371
diff
changeset
|
748 s = match.group('email') |
|
3c9bd1faddd8
backporting fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1371
diff
changeset
|
749 return '<a href="mailto:%s">%s</a>'%(s, s) |
|
3c9bd1faddd8
backporting fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1371
diff
changeset
|
750 else: |
|
3c9bd1faddd8
backporting fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1371
diff
changeset
|
751 s = match.group('item') |
|
3c9bd1faddd8
backporting fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1371
diff
changeset
|
752 s1 = match.group('class') |
|
3c9bd1faddd8
backporting fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1371
diff
changeset
|
753 s2 = match.group('id') |
|
3c9bd1faddd8
backporting fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1371
diff
changeset
|
754 try: |
|
3c9bd1faddd8
backporting fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1371
diff
changeset
|
755 # make sure s1 is a valid tracker classname |
|
3c9bd1faddd8
backporting fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1371
diff
changeset
|
756 self._db.getclass(s1) |
|
3c9bd1faddd8
backporting fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1371
diff
changeset
|
757 return '<a href="%s">%s %s</a>'%(s, s1, s2) |
|
3c9bd1faddd8
backporting fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1371
diff
changeset
|
758 except KeyError: |
|
3c9bd1faddd8
backporting fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1371
diff
changeset
|
759 return '%s%s'%(s1, s2) |
|
1356
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
760 |
|
1371
56c5b4509378
revert StringHTMLProperty to not hyperlink text by default (added doc too)
Richard Jones <richard@users.sourceforge.net>
parents:
1356
diff
changeset
|
761 def plain(self, escape=0, hyperlink=0): |
|
1356
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
762 ''' Render a "plain" representation of the property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
763 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
764 "escape" turns on/off HTML quoting |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
765 "hyperlink" turns on/off in-text hyperlinking of URLs, email |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
766 addresses and designators |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
767 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
768 if self._value is None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
769 return '' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
770 if escape: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
771 s = cgi.escape(str(self._value)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
772 else: |
|
1371
56c5b4509378
revert StringHTMLProperty to not hyperlink text by default (added doc too)
Richard Jones <richard@users.sourceforge.net>
parents:
1356
diff
changeset
|
773 s = str(self._value) |
|
1356
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
774 if hyperlink: |
|
1371
56c5b4509378
revert StringHTMLProperty to not hyperlink text by default (added doc too)
Richard Jones <richard@users.sourceforge.net>
parents:
1356
diff
changeset
|
775 if not escape: |
|
56c5b4509378
revert StringHTMLProperty to not hyperlink text by default (added doc too)
Richard Jones <richard@users.sourceforge.net>
parents:
1356
diff
changeset
|
776 s = cgi.escape(s) |
|
1400
3c9bd1faddd8
backporting fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1371
diff
changeset
|
777 s = self.hyper_re.sub(self._hyper_repl, s) |
|
1356
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
778 return s |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
779 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
780 def stext(self, escape=0): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
781 ''' Render the value of the property as StructuredText. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
782 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
783 This requires the StructureText module to be installed separately. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
784 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
785 s = self.plain(escape=escape) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
786 if not StructuredText: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
787 return s |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
788 return StructuredText(s,level=1,header=0) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
789 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
790 def field(self, size = 30): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
791 ''' Render a form edit field for the property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
792 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
793 if self._value is None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
794 value = '' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
795 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
796 value = cgi.escape(str(self._value)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
797 value = '"'.join(value.split('"')) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
798 return '<input name="%s" value="%s" size="%s">'%(self._name, value, size) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
799 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
800 def multiline(self, escape=0, rows=5, cols=40): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
801 ''' Render a multiline form edit field for the property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
802 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
803 if self._value is None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
804 value = '' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
805 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
806 value = cgi.escape(str(self._value)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
807 value = '"'.join(value.split('"')) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
808 return '<textarea name="%s" rows="%s" cols="%s">%s</textarea>'%( |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
809 self._name, rows, cols, value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
810 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
811 def email(self, escape=1): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
812 ''' Render the value of the property as an obscured email address |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
813 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
814 if self._value is None: value = '' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
815 else: value = str(self._value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
816 if value.find('@') != -1: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
817 name, domain = value.split('@') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
818 domain = ' '.join(domain.split('.')[:-1]) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
819 name = name.replace('.', ' ') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
820 value = '%s at %s ...'%(name, domain) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
821 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
822 value = value.replace('.', ' ') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
823 if escape: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
824 value = cgi.escape(value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
825 return value |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
826 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
827 class PasswordHTMLProperty(HTMLProperty): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
828 def plain(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
829 ''' Render a "plain" representation of the property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
830 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
831 if self._value is None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
832 return '' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
833 return _('*encrypted*') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
834 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
835 def field(self, size = 30): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
836 ''' Render a form edit field for the property. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
837 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
838 return '<input type="password" name="%s" size="%s">'%(self._name, size) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
839 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
840 def confirm(self, size = 30): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
841 ''' Render a second form edit field for the property, used for |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
842 confirmation that the user typed the password correctly. Generates |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
843 a field with name "name:confirm". |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
844 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
845 return '<input type="password" name="%s:confirm" size="%s">'%( |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
846 self._name, size) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
847 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
848 class NumberHTMLProperty(HTMLProperty): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
849 def plain(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
850 ''' Render a "plain" representation of the property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
851 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
852 return str(self._value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
853 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
854 def field(self, size = 30): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
855 ''' Render a form edit field for the property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
856 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
857 if self._value is None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
858 value = '' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
859 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
860 value = cgi.escape(str(self._value)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
861 value = '"'.join(value.split('"')) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
862 return '<input name="%s" value="%s" size="%s">'%(self._name, value, size) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
863 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
864 class BooleanHTMLProperty(HTMLProperty): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
865 def plain(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
866 ''' Render a "plain" representation of the property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
867 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
868 if self._value is None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
869 return '' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
870 return self._value and "Yes" or "No" |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
871 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
872 def field(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
873 ''' Render a form edit field for the property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
874 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
875 checked = self._value and "checked" or "" |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
876 s = '<input type="radio" name="%s" value="yes" %s>Yes'%(self._name, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
877 checked) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
878 if checked: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
879 checked = "" |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
880 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
881 checked = "checked" |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
882 s += '<input type="radio" name="%s" value="no" %s>No'%(self._name, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
883 checked) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
884 return s |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
885 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
886 class DateHTMLProperty(HTMLProperty): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
887 def plain(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
888 ''' Render a "plain" representation of the property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
889 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
890 if self._value is None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
891 return '' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
892 return str(self._value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
893 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
894 def field(self, size = 30): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
895 ''' Render a form edit field for the property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
896 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
897 if self._value is None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
898 value = '' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
899 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
900 value = cgi.escape(str(self._value)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
901 value = '"'.join(value.split('"')) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
902 return '<input name="%s" value="%s" size="%s">'%(self._name, value, size) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
903 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
904 def reldate(self, pretty=1): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
905 ''' Render the interval between the date and now. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
906 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
907 If the "pretty" flag is true, then make the display pretty. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
908 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
909 if not self._value: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
910 return '' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
911 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
912 # figure the interval |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
913 interval = date.Date('.') - self._value |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
914 if pretty: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
915 return interval.pretty() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
916 return str(interval) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
917 |
|
1452
e58002599038
fixed args to some date templating methods
Richard Jones <richard@users.sourceforge.net>
parents:
1416
diff
changeset
|
918 _marker = [] |
|
e58002599038
fixed args to some date templating methods
Richard Jones <richard@users.sourceforge.net>
parents:
1416
diff
changeset
|
919 def pretty(self, format=_marker): |
|
1356
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
920 ''' Render the date in a pretty format (eg. month names, spaces). |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
921 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
922 The format string is a standard python strftime format string. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
923 Note that if the day is zero, and appears at the start of the |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
924 string, then it'll be stripped from the output. This is handy |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
925 for the situatin when a date only specifies a month and a year. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
926 ''' |
|
1452
e58002599038
fixed args to some date templating methods
Richard Jones <richard@users.sourceforge.net>
parents:
1416
diff
changeset
|
927 if format is not self._marker: |
|
e58002599038
fixed args to some date templating methods
Richard Jones <richard@users.sourceforge.net>
parents:
1416
diff
changeset
|
928 return self._value.pretty(format) |
|
e58002599038
fixed args to some date templating methods
Richard Jones <richard@users.sourceforge.net>
parents:
1416
diff
changeset
|
929 else: |
|
e58002599038
fixed args to some date templating methods
Richard Jones <richard@users.sourceforge.net>
parents:
1416
diff
changeset
|
930 return self._value.pretty() |
|
1356
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
931 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
932 def local(self, offset): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
933 ''' Return the date/time as a local (timezone offset) date/time. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
934 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
935 return DateHTMLProperty(self._client, self._nodeid, self._prop, |
|
1452
e58002599038
fixed args to some date templating methods
Richard Jones <richard@users.sourceforge.net>
parents:
1416
diff
changeset
|
936 self._name, self._value.local(offset)) |
|
1356
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
937 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
938 class IntervalHTMLProperty(HTMLProperty): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
939 def plain(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
940 ''' Render a "plain" representation of the property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
941 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
942 if self._value is None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
943 return '' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
944 return str(self._value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
945 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
946 def pretty(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
947 ''' Render the interval in a pretty format (eg. "yesterday") |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
948 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
949 return self._value.pretty() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
950 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
951 def field(self, size = 30): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
952 ''' Render a form edit field for the property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
953 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
954 if self._value is None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
955 value = '' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
956 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
957 value = cgi.escape(str(self._value)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
958 value = '"'.join(value.split('"')) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
959 return '<input name="%s" value="%s" size="%s">'%(self._name, value, size) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
960 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
961 class LinkHTMLProperty(HTMLProperty): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
962 ''' Link HTMLProperty |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
963 Include the above as well as being able to access the class |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
964 information. Stringifying the object itself results in the value |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
965 from the item being displayed. Accessing attributes of this object |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
966 result in the appropriate entry from the class being queried for the |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
967 property accessed (so item/assignedto/name would look up the user |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
968 entry identified by the assignedto property on item, and then the |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
969 name property of that user) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
970 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
971 def __init__(self, *args): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
972 HTMLProperty.__init__(self, *args) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
973 # if we're representing a form value, then the -1 from the form really |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
974 # should be a None |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
975 if str(self._value) == '-1': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
976 self._value = None |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
977 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
978 def __getattr__(self, attr): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
979 ''' return a new HTMLItem ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
980 #print 'Link.getattr', (self, attr, self._value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
981 if not self._value: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
982 raise AttributeError, "Can't access missing value" |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
983 if self._prop.classname == 'user': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
984 klass = HTMLUser |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
985 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
986 klass = HTMLItem |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
987 i = klass(self._client, self._prop.classname, self._value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
988 return getattr(i, attr) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
989 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
990 def plain(self, escape=0): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
991 ''' Render a "plain" representation of the property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
992 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
993 if self._value is None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
994 return '' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
995 linkcl = self._db.classes[self._prop.classname] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
996 k = linkcl.labelprop(1) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
997 value = str(linkcl.get(self._value, k)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
998 if escape: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
999 value = cgi.escape(value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1000 return value |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1001 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1002 def field(self, showid=0, size=None): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1003 ''' Render a form edit field for the property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1004 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1005 linkcl = self._db.getclass(self._prop.classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1006 if linkcl.getprops().has_key('order'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1007 sort_on = 'order' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1008 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1009 sort_on = linkcl.labelprop() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1010 options = linkcl.filter(None, {}, ('+', sort_on), (None, None)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1011 # TODO: make this a field display, not a menu one! |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1012 l = ['<select name="%s">'%self._name] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1013 k = linkcl.labelprop(1) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1014 if self._value is None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1015 s = 'selected ' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1016 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1017 s = '' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1018 l.append(_('<option %svalue="-1">- no selection -</option>')%s) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1019 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1020 # make sure we list the current value if it's retired |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1021 if self._value and self._value not in options: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1022 options.insert(0, self._value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1023 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1024 for optionid in options: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1025 # get the option value, and if it's None use an empty string |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1026 option = linkcl.get(optionid, k) or '' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1027 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1028 # figure if this option is selected |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1029 s = '' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1030 if optionid == self._value: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1031 s = 'selected ' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1032 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1033 # figure the label |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1034 if showid: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1035 lab = '%s%s: %s'%(self._prop.classname, optionid, option) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1036 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1037 lab = option |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1038 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1039 # truncate if it's too long |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1040 if size is not None and len(lab) > size: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1041 lab = lab[:size-3] + '...' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1042 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1043 # and generate |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1044 lab = cgi.escape(lab) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1045 l.append('<option %svalue="%s">%s</option>'%(s, optionid, lab)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1046 l.append('</select>') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1047 return '\n'.join(l) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1048 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1049 def menu(self, size=None, height=None, showid=0, additional=[], |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1050 **conditions): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1051 ''' Render a form select list for this property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1052 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1053 value = self._value |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1054 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1055 # sort function |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1056 sortfunc = make_sort_function(self._db, self._prop.classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1057 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1058 linkcl = self._db.getclass(self._prop.classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1059 l = ['<select name="%s">'%self._name] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1060 k = linkcl.labelprop(1) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1061 s = '' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1062 if value is None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1063 s = 'selected ' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1064 l.append(_('<option %svalue="-1">- no selection -</option>')%s) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1065 if linkcl.getprops().has_key('order'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1066 sort_on = ('+', 'order') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1067 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1068 sort_on = ('+', linkcl.labelprop()) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1069 options = linkcl.filter(None, conditions, sort_on, (None, None)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1070 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1071 # make sure we list the current value if it's retired |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1072 if self._value and self._value not in options: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1073 options.insert(0, self._value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1074 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1075 for optionid in options: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1076 # get the option value, and if it's None use an empty string |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1077 option = linkcl.get(optionid, k) or '' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1078 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1079 # figure if this option is selected |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1080 s = '' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1081 if value in [optionid, option]: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1082 s = 'selected ' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1083 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1084 # figure the label |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1085 if showid: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1086 lab = '%s%s: %s'%(self._prop.classname, optionid, option) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1087 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1088 lab = option |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1089 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1090 # truncate if it's too long |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1091 if size is not None and len(lab) > size: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1092 lab = lab[:size-3] + '...' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1093 if additional: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1094 m = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1095 for propname in additional: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1096 m.append(linkcl.get(optionid, propname)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1097 lab = lab + ' (%s)'%', '.join(map(str, m)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1098 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1099 # and generate |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1100 lab = cgi.escape(lab) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1101 l.append('<option %svalue="%s">%s</option>'%(s, optionid, lab)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1102 l.append('</select>') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1103 return '\n'.join(l) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1104 # def checklist(self, ...) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1105 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1106 class MultilinkHTMLProperty(HTMLProperty): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1107 ''' Multilink HTMLProperty |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1108 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1109 Also be iterable, returning a wrapper object like the Link case for |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1110 each entry in the multilink. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1111 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1112 def __len__(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1113 ''' length of the multilink ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1114 return len(self._value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1115 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1116 def __getattr__(self, attr): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1117 ''' no extended attribute accesses make sense here ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1118 raise AttributeError, attr |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1119 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1120 def __getitem__(self, num): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1121 ''' iterate and return a new HTMLItem |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1122 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1123 #print 'Multi.getitem', (self, num) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1124 value = self._value[num] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1125 if self._prop.classname == 'user': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1126 klass = HTMLUser |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1127 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1128 klass = HTMLItem |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1129 return klass(self._client, self._prop.classname, value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1130 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1131 def __contains__(self, value): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1132 ''' Support the "in" operator. We have to make sure the passed-in |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1133 value is a string first, not a *HTMLProperty. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1134 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1135 return str(value) in self._value |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1136 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1137 def reverse(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1138 ''' return the list in reverse order |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1139 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1140 l = self._value[:] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1141 l.reverse() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1142 if self._prop.classname == 'user': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1143 klass = HTMLUser |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1144 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1145 klass = HTMLItem |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1146 return [klass(self._client, self._prop.classname, value) for value in l] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1147 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1148 def plain(self, escape=0): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1149 ''' Render a "plain" representation of the property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1150 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1151 linkcl = self._db.classes[self._prop.classname] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1152 k = linkcl.labelprop(1) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1153 labels = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1154 for v in self._value: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1155 labels.append(linkcl.get(v, k)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1156 value = ', '.join(labels) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1157 if escape: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1158 value = cgi.escape(value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1159 return value |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1160 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1161 def field(self, size=30, showid=0): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1162 ''' Render a form edit field for the property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1163 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1164 sortfunc = make_sort_function(self._db, self._prop.classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1165 linkcl = self._db.getclass(self._prop.classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1166 value = self._value[:] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1167 if value: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1168 value.sort(sortfunc) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1169 # map the id to the label property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1170 if not linkcl.getkey(): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1171 showid=1 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1172 if not showid: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1173 k = linkcl.labelprop(1) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1174 value = [linkcl.get(v, k) for v in value] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1175 value = cgi.escape(','.join(value)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1176 return '<input name="%s" size="%s" value="%s">'%(self._name, size, value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1177 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1178 def menu(self, size=None, height=None, showid=0, additional=[], |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1179 **conditions): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1180 ''' Render a form select list for this property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1181 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1182 value = self._value |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1183 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1184 # sort function |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1185 sortfunc = make_sort_function(self._db, self._prop.classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1186 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1187 linkcl = self._db.getclass(self._prop.classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1188 if linkcl.getprops().has_key('order'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1189 sort_on = ('+', 'order') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1190 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1191 sort_on = ('+', linkcl.labelprop()) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1192 options = linkcl.filter(None, conditions, sort_on, (None,None)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1193 height = height or min(len(options), 7) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1194 l = ['<select multiple name="%s" size="%s">'%(self._name, height)] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1195 k = linkcl.labelprop(1) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1196 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1197 # make sure we list the current values if they're retired |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1198 for val in value: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1199 if val not in options: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1200 options.insert(0, val) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1201 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1202 for optionid in options: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1203 # get the option value, and if it's None use an empty string |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1204 option = linkcl.get(optionid, k) or '' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1205 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1206 # figure if this option is selected |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1207 s = '' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1208 if optionid in value or option in value: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1209 s = 'selected ' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1210 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1211 # figure the label |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1212 if showid: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1213 lab = '%s%s: %s'%(self._prop.classname, optionid, option) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1214 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1215 lab = option |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1216 # truncate if it's too long |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1217 if size is not None and len(lab) > size: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1218 lab = lab[:size-3] + '...' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1219 if additional: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1220 m = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1221 for propname in additional: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1222 m.append(linkcl.get(optionid, propname)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1223 lab = lab + ' (%s)'%', '.join(m) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1224 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1225 # and generate |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1226 lab = cgi.escape(lab) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1227 l.append('<option %svalue="%s">%s</option>'%(s, optionid, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1228 lab)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1229 l.append('</select>') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1230 return '\n'.join(l) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1231 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1232 # set the propclasses for HTMLItem |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1233 propclasses = ( |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1234 (hyperdb.String, StringHTMLProperty), |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1235 (hyperdb.Number, NumberHTMLProperty), |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1236 (hyperdb.Boolean, BooleanHTMLProperty), |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1237 (hyperdb.Date, DateHTMLProperty), |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1238 (hyperdb.Interval, IntervalHTMLProperty), |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1239 (hyperdb.Password, PasswordHTMLProperty), |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1240 (hyperdb.Link, LinkHTMLProperty), |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1241 (hyperdb.Multilink, MultilinkHTMLProperty), |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1242 ) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1243 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1244 def make_sort_function(db, classname): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1245 '''Make a sort function for a given class |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1246 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1247 linkcl = db.getclass(classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1248 if linkcl.getprops().has_key('order'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1249 sort_on = 'order' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1250 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1251 sort_on = linkcl.labelprop() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1252 def sortfunc(a, b, linkcl=linkcl, sort_on=sort_on): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1253 return cmp(linkcl.get(a, sort_on), linkcl.get(b, sort_on)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1254 return sortfunc |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1255 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1256 def handleListCGIValue(value): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1257 ''' Value is either a single item or a list of items. Each item has a |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1258 .value that we're actually interested in. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1259 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1260 if isinstance(value, type([])): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1261 return [value.value for value in value] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1262 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1263 value = value.value.strip() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1264 if not value: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1265 return [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1266 return value.split(',') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1267 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1268 class ShowDict: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1269 ''' A convenience access to the :columns index parameters |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1270 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1271 def __init__(self, columns): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1272 self.columns = {} |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1273 for col in columns: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1274 self.columns[col] = 1 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1275 def __getitem__(self, name): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1276 return self.columns.has_key(name) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1277 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1278 class HTMLRequest: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1279 ''' The *request*, holding the CGI form and environment. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1280 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1281 "form" the CGI form as a cgi.FieldStorage |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1282 "env" the CGI environment variables |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1283 "base" the base URL for this instance |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1284 "user" a HTMLUser instance for this user |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1285 "classname" the current classname (possibly None) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1286 "template" the current template (suffix, also possibly None) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1287 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1288 Index args: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1289 "columns" dictionary of the columns to display in an index page |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1290 "show" a convenience access to columns - request/show/colname will |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1291 be true if the columns should be displayed, false otherwise |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1292 "sort" index sort column (direction, column name) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1293 "group" index grouping property (direction, column name) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1294 "filter" properties to filter the index on |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1295 "filterspec" values to filter the index on |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1296 "search_text" text to perform a full-text search on for an index |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1297 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1298 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1299 def __init__(self, client): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1300 self.client = client |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1301 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1302 # easier access vars |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1303 self.form = client.form |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1304 self.env = client.env |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1305 self.base = client.base |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1306 self.user = HTMLUser(client, 'user', client.userid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1307 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1308 # store the current class name and action |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1309 self.classname = client.classname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1310 self.template = client.template |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1311 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1312 self._post_init() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1313 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1314 def _post_init(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1315 ''' Set attributes based on self.form |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1316 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1317 # extract the index display information from the form |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1318 self.columns = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1319 if self.form.has_key(':columns'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1320 self.columns = handleListCGIValue(self.form[':columns']) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1321 self.show = ShowDict(self.columns) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1322 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1323 # sorting |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1324 self.sort = (None, None) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1325 if self.form.has_key(':sort'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1326 sort = self.form[':sort'].value |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1327 if sort.startswith('-'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1328 self.sort = ('-', sort[1:]) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1329 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1330 self.sort = ('+', sort) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1331 if self.form.has_key(':sortdir'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1332 self.sort = ('-', self.sort[1]) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1333 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1334 # grouping |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1335 self.group = (None, None) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1336 if self.form.has_key(':group'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1337 group = self.form[':group'].value |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1338 if group.startswith('-'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1339 self.group = ('-', group[1:]) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1340 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1341 self.group = ('+', group) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1342 if self.form.has_key(':groupdir'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1343 self.group = ('-', self.group[1]) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1344 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1345 # filtering |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1346 self.filter = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1347 if self.form.has_key(':filter'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1348 self.filter = handleListCGIValue(self.form[':filter']) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1349 self.filterspec = {} |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1350 db = self.client.db |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1351 if self.classname is not None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1352 props = db.getclass(self.classname).getprops() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1353 for name in self.filter: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1354 if self.form.has_key(name): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1355 prop = props[name] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1356 fv = self.form[name] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1357 if (isinstance(prop, hyperdb.Link) or |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1358 isinstance(prop, hyperdb.Multilink)): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1359 self.filterspec[name] = lookupIds(db, prop, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1360 handleListCGIValue(fv)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1361 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1362 self.filterspec[name] = fv.value |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1363 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1364 # full-text search argument |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1365 self.search_text = None |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1366 if self.form.has_key(':search_text'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1367 self.search_text = self.form[':search_text'].value |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1368 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1369 # pagination - size and start index |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1370 # figure batch args |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1371 if self.form.has_key(':pagesize'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1372 self.pagesize = int(self.form[':pagesize'].value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1373 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1374 self.pagesize = 50 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1375 if self.form.has_key(':startwith'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1376 self.startwith = int(self.form[':startwith'].value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1377 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1378 self.startwith = 0 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1379 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1380 def updateFromURL(self, url): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1381 ''' Parse the URL for query args, and update my attributes using the |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1382 values. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1383 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1384 self.form = {} |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1385 for name, value in cgi.parse_qsl(url): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1386 if self.form.has_key(name): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1387 if isinstance(self.form[name], type([])): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1388 self.form[name].append(cgi.MiniFieldStorage(name, value)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1389 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1390 self.form[name] = [self.form[name], |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1391 cgi.MiniFieldStorage(name, value)] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1392 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1393 self.form[name] = cgi.MiniFieldStorage(name, value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1394 self._post_init() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1395 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1396 def update(self, kwargs): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1397 ''' Update my attributes using the keyword args |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1398 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1399 self.__dict__.update(kwargs) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1400 if kwargs.has_key('columns'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1401 self.show = ShowDict(self.columns) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1402 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1403 def description(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1404 ''' Return a description of the request - handle for the page title. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1405 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1406 s = [self.client.db.config.TRACKER_NAME] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1407 if self.classname: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1408 if self.client.nodeid: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1409 s.append('- %s%s'%(self.classname, self.client.nodeid)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1410 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1411 if self.template == 'item': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1412 s.append('- new %s'%self.classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1413 elif self.template == 'index': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1414 s.append('- %s index'%self.classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1415 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1416 s.append('- %s %s'%(self.classname, self.template)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1417 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1418 s.append('- home') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1419 return ' '.join(s) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1420 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1421 def __str__(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1422 d = {} |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1423 d.update(self.__dict__) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1424 f = '' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1425 for k in self.form.keys(): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1426 f += '\n %r=%r'%(k,handleListCGIValue(self.form[k])) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1427 d['form'] = f |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1428 e = '' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1429 for k,v in self.env.items(): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1430 e += '\n %r=%r'%(k, v) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1431 d['env'] = e |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1432 return ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1433 form: %(form)s |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1434 base: %(base)r |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1435 classname: %(classname)r |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1436 template: %(template)r |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1437 columns: %(columns)r |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1438 sort: %(sort)r |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1439 group: %(group)r |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1440 filter: %(filter)r |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1441 search_text: %(search_text)r |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1442 pagesize: %(pagesize)r |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1443 startwith: %(startwith)r |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1444 env: %(env)s |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1445 '''%d |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1446 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1447 def indexargs_form(self, columns=1, sort=1, group=1, filter=1, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1448 filterspec=1): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1449 ''' return the current index args as form elements ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1450 l = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1451 s = '<input type="hidden" name="%s" value="%s">' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1452 if columns and self.columns: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1453 l.append(s%(':columns', ','.join(self.columns))) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1454 if sort and self.sort[1] is not None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1455 if self.sort[0] == '-': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1456 val = '-'+self.sort[1] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1457 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1458 val = self.sort[1] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1459 l.append(s%(':sort', val)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1460 if group and self.group[1] is not None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1461 if self.group[0] == '-': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1462 val = '-'+self.group[1] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1463 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1464 val = self.group[1] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1465 l.append(s%(':group', val)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1466 if filter and self.filter: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1467 l.append(s%(':filter', ','.join(self.filter))) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1468 if filterspec: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1469 for k,v in self.filterspec.items(): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1470 if type(v) == type([]): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1471 l.append(s%(k, ','.join(v))) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1472 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1473 l.append(s%(k, v)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1474 if self.search_text: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1475 l.append(s%(':search_text', self.search_text)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1476 l.append(s%(':pagesize', self.pagesize)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1477 l.append(s%(':startwith', self.startwith)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1478 return '\n'.join(l) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1479 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1480 def indexargs_url(self, url, args): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1481 ''' embed the current index args in a URL ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1482 l = ['%s=%s'%(k,v) for k,v in args.items()] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1483 if self.columns and not args.has_key(':columns'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1484 l.append(':columns=%s'%(','.join(self.columns))) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1485 if self.sort[1] is not None and not args.has_key(':sort'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1486 if self.sort[0] == '-': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1487 val = '-'+self.sort[1] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1488 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1489 val = self.sort[1] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1490 l.append(':sort=%s'%val) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1491 if self.group[1] is not None and not args.has_key(':group'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1492 if self.group[0] == '-': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1493 val = '-'+self.group[1] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1494 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1495 val = self.group[1] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1496 l.append(':group=%s'%val) |
|
1416
293653d08292
backporting changes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1410
diff
changeset
|
1497 if self.filter and not args.has_key(':filter'): |
|
1356
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1498 l.append(':filter=%s'%(','.join(self.filter))) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1499 for k,v in self.filterspec.items(): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1500 if not args.has_key(k): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1501 if type(v) == type([]): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1502 l.append('%s=%s'%(k, ','.join(v))) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1503 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1504 l.append('%s=%s'%(k, v)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1505 if self.search_text and not args.has_key(':search_text'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1506 l.append(':search_text=%s'%self.search_text) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1507 if not args.has_key(':pagesize'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1508 l.append(':pagesize=%s'%self.pagesize) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1509 if not args.has_key(':startwith'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1510 l.append(':startwith=%s'%self.startwith) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1511 return '%s?%s'%(url, '&'.join(l)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1512 indexargs_href = indexargs_url |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1513 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1514 def base_javascript(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1515 return ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1516 <script language="javascript"> |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1517 submitted = false; |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1518 function submit_once() { |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1519 if (submitted) { |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1520 alert("Your request is being processed.\\nPlease be patient."); |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1521 return 0; |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1522 } |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1523 submitted = true; |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1524 return 1; |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1525 } |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1526 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1527 function help_window(helpurl, width, height) { |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1528 HelpWin = window.open('%s' + helpurl, 'RoundupHelpWindow', 'scrollbars=yes,resizable=yes,toolbar=no,height='+height+',width='+width); |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1529 } |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1530 </script> |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1531 '''%self.base |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1532 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1533 def batch(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1534 ''' Return a batch object for results from the "current search" |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1535 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1536 filterspec = self.filterspec |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1537 sort = self.sort |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1538 group = self.group |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1539 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1540 # get the list of ids we're batching over |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1541 klass = self.client.db.getclass(self.classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1542 if self.search_text: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1543 matches = self.client.db.indexer.search( |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1544 re.findall(r'\b\w{2,25}\b', self.search_text), klass) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1545 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1546 matches = None |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1547 l = klass.filter(matches, filterspec, sort, group) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1548 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1549 # return the batch object, using IDs only |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1550 return Batch(self.client, l, self.pagesize, self.startwith, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1551 classname=self.classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1552 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1553 # extend the standard ZTUtils Batch object to remove dependency on |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1554 # Acquisition and add a couple of useful methods |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1555 class Batch(ZTUtils.Batch): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1556 ''' Use me to turn a list of items, or item ids of a given class, into a |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1557 series of batches. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1558 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1559 ========= ======================================================== |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1560 Parameter Usage |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1561 ========= ======================================================== |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1562 sequence a list of HTMLItems or item ids |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1563 classname if sequence is a list of ids, this is the class of item |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1564 size how big to make the sequence. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1565 start where to start (0-indexed) in the sequence. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1566 end where to end (0-indexed) in the sequence. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1567 orphan if the next batch would contain less items than this |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1568 value, then it is combined with this batch |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1569 overlap the number of items shared between adjacent batches |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1570 ========= ======================================================== |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1571 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1572 Attributes: Note that the "start" attribute, unlike the |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1573 argument, is a 1-based index (I know, lame). "first" is the |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1574 0-based index. "length" is the actual number of elements in |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1575 the batch. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1576 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1577 "sequence_length" is the length of the original, unbatched, sequence. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1578 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1579 def __init__(self, client, sequence, size, start, end=0, orphan=0, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1580 overlap=0, classname=None): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1581 self.client = client |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1582 self.last_index = self.last_item = None |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1583 self.current_item = None |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1584 self.classname = classname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1585 self.sequence_length = len(sequence) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1586 ZTUtils.Batch.__init__(self, sequence, size, start, end, orphan, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1587 overlap) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1588 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1589 # overwrite so we can late-instantiate the HTMLItem instance |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1590 def __getitem__(self, index): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1591 if index < 0: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1592 if index + self.end < self.first: raise IndexError, index |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1593 return self._sequence[index + self.end] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1594 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1595 if index >= self.length: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1596 raise IndexError, index |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1597 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1598 # move the last_item along - but only if the fetched index changes |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1599 # (for some reason, index 0 is fetched twice) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1600 if index != self.last_index: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1601 self.last_item = self.current_item |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1602 self.last_index = index |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1603 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1604 item = self._sequence[index + self.first] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1605 if self.classname: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1606 # map the item ids to instances |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1607 if self.classname == 'user': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1608 item = HTMLUser(self.client, self.classname, item) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1609 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1610 item = HTMLItem(self.client, self.classname, item) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1611 self.current_item = item |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1612 return item |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1613 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1614 def propchanged(self, property): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1615 ''' Detect if the property marked as being the group property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1616 changed in the last iteration fetch |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1617 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1618 if (self.last_item is None or |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1619 self.last_item[property] != self.current_item[property]): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1620 return 1 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1621 return 0 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1622 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1623 # override these 'cos we don't have access to acquisition |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1624 def previous(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1625 if self.start == 1: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1626 return None |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1627 return Batch(self.client, self._sequence, self._size, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1628 self.first - self._size + self.overlap, 0, self.orphan, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1629 self.overlap) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1630 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1631 def next(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1632 try: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1633 self._sequence[self.end] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1634 except IndexError: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1635 return None |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1636 return Batch(self.client, self._sequence, self._size, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1637 self.end - self.overlap, 0, self.orphan, self.overlap) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1638 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1639 class TemplatingUtils: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1640 ''' Utilities for templating |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1641 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1642 def __init__(self, client): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1643 self.client = client |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1644 def Batch(self, sequence, size, start, end=0, orphan=0, overlap=0): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1645 return Batch(self.client, sequence, size, start, end, orphan, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1646 overlap) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1647 |
