Mercurial > p > roundup > code
annotate roundup/cgi/templating.py @ 7025:66149a18f09e
flake8 E303 too many blank lines
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sun, 09 Oct 2022 17:46:17 -0400 |
| parents | bac315283a55 |
| children | d7f0eab25305 |
| rev | line source |
|---|---|
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
1 """Implements the API used in the HTML templating for the web interface. |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
2 """ |
|
2180
58b6d1747973
Web interface tweaks.
Richard Jones <richard@users.sourceforge.net>
parents:
2170
diff
changeset
|
3 |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
4 todo = """ |
|
4749
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
5 - Document parameters to Template.render() method |
|
4727
5033c2ad80a7
templating: Rename LoaderBase.get() to LoaderBase.load() for clarity
anatoly techtonik <techtonik@gmail.com>
parents:
4724
diff
changeset
|
6 - Add tests for Loader.load() method |
|
2327
36ae1b14aaab
remove excessive spaces in the translatable strings;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2324
diff
changeset
|
7 - Most methods should have a "default" arg to supply a value |
|
36ae1b14aaab
remove excessive spaces in the translatable strings;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2324
diff
changeset
|
8 when none appears in the hyperdb or request. |
|
2180
58b6d1747973
Web interface tweaks.
Richard Jones <richard@users.sourceforge.net>
parents:
2170
diff
changeset
|
9 - Multilink property additions: change_note and new_upload |
|
58b6d1747973
Web interface tweaks.
Richard Jones <richard@users.sourceforge.net>
parents:
2170
diff
changeset
|
10 - Add class.find() too |
|
58b6d1747973
Web interface tweaks.
Richard Jones <richard@users.sourceforge.net>
parents:
2170
diff
changeset
|
11 - NumberHTMLProperty should support numeric operations |
|
2324
da4444e593f4
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
2320
diff
changeset
|
12 - LinkHTMLProperty should handle comparisons to strings (cf. linked name) |
|
2411
7ff0a0306877
another TODO
Richard Jones <richard@users.sourceforge.net>
parents:
2396
diff
changeset
|
13 - HTMLRequest.default(self, sort, group, filter, columns, **filterspec): |
|
3843
97d9368ed485
Yet another emacs syntax highlighting workaround.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3842
diff
changeset
|
14 '''Set the request's view arguments to the given values when no |
|
2411
7ff0a0306877
another TODO
Richard Jones <richard@users.sourceforge.net>
parents:
2396
diff
changeset
|
15 values are found in the CGI environment. |
|
3843
97d9368ed485
Yet another emacs syntax highlighting workaround.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3842
diff
changeset
|
16 ''' |
|
2664
8348373b4361
another TODO
Richard Jones <richard@users.sourceforge.net>
parents:
2651
diff
changeset
|
17 - have menu() methods accept filtering arguments |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
18 """ |
|
2180
58b6d1747973
Web interface tweaks.
Richard Jones <richard@users.sourceforge.net>
parents:
2170
diff
changeset
|
19 |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
20 __docformat__ = 'restructuredtext' |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
21 |
|
6104
a1fd9551d416
don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6103
diff
changeset
|
22 # List of schemes that are not rendered as links in rst and markdown. |
|
7017
96be63649c92
flake8 fix additional spaces within () and []
John Rouillard <rouilj@ieee.org>
parents:
6856
diff
changeset
|
23 _disable_url_schemes = ['javascript', 'data'] |
|
1931
f1e5e5115c29
Always sort MultilinkHTMLProperty in the correct order...
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
1917
diff
changeset
|
24 |
|
5488
52cb53eedf77
reworked random number use
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5485
diff
changeset
|
25 import base64, cgi, re, os.path, mimetypes, csv, string |
|
5043
ac0c117cd24c
Remove wrap and associated functions from roundup.support
John Kristensen <john@jerrykan.com>
parents:
5006
diff
changeset
|
26 import calendar |
|
ac0c117cd24c
Remove wrap and associated functions from roundup.support
John Kristensen <john@jerrykan.com>
parents:
5006
diff
changeset
|
27 import textwrap |
|
5201
a9ace22e0a2f
issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents:
5193
diff
changeset
|
28 import time, hashlib |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
29 |
|
5837
883c9e90b403
Fix problem with cgi.escape being depricated a different way. This way
John Rouillard <rouilj@ieee.org>
parents:
5809
diff
changeset
|
30 from roundup.anypy.html import html_escape |
|
5800
1a835db41674
Call cgi.escape only on python 2. Replace with html.escapeif it can be
John Rouillard <rouilj@ieee.org>
parents:
5684
diff
changeset
|
31 |
|
5402
88dbacd11cd1
Python 3 preparation: update urllib / urllib2 / urlparse imports.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5399
diff
changeset
|
32 from roundup.anypy import urllib_ |
|
3188
7faae85e1e33
merge from branch
Richard Jones <richard@users.sourceforge.net>
parents:
3183
diff
changeset
|
33 from roundup import hyperdb, date, support |
|
2377
a53f87f2488a
StaticTranslationService moved here out of the code originating from Zope;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2347
diff
changeset
|
34 from roundup import i18n |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
35 from roundup.i18n import _ |
|
5488
52cb53eedf77
reworked random number use
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5485
diff
changeset
|
36 from roundup.anypy.strings import is_us, b2s, s2b, us2s, s2u, u2s, StringIO |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
37 |
|
5388
d26921b851c3
Python 3 preparation: make relative imports explicit.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5381
diff
changeset
|
38 from .KeywordsExpr import render_keywords_expression_editor |
|
4466
f1fe6fd0aa61
Multilinks can be filtered by combining elements with AND, OR and NOT now.
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4463
diff
changeset
|
39 |
|
5973
fe334430ca07
issue2550919 - Anti-bot signup using 4 second delay
John Rouillard <rouilj@ieee.org>
parents:
5947
diff
changeset
|
40 from roundup.cgi.timestamp import pack_timestamp |
|
6856
c27276e0bdce
flake8 undefined symbol fixes.
John Rouillard <rouilj@ieee.org>
parents:
6832
diff
changeset
|
41 from roundup.cgi import TranslationService |
|
5973
fe334430ca07
issue2550919 - Anti-bot signup using 4 second delay
John Rouillard <rouilj@ieee.org>
parents:
5947
diff
changeset
|
42 |
|
5488
52cb53eedf77
reworked random number use
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5485
diff
changeset
|
43 import roundup.anypy.random_ as random_ |
|
1016
d6c13142e7b9
Keep a cache of compiled PageTemplates.
Richard Jones <richard@users.sourceforge.net>
parents:
1008
diff
changeset
|
44 try: |
|
d6c13142e7b9
Keep a cache of compiled PageTemplates.
Richard Jones <richard@users.sourceforge.net>
parents:
1008
diff
changeset
|
45 import cPickle as pickle |
|
d6c13142e7b9
Keep a cache of compiled PageTemplates.
Richard Jones <richard@users.sourceforge.net>
parents:
1008
diff
changeset
|
46 except ImportError: |
|
d6c13142e7b9
Keep a cache of compiled PageTemplates.
Richard Jones <richard@users.sourceforge.net>
parents:
1008
diff
changeset
|
47 import pickle |
|
d6c13142e7b9
Keep a cache of compiled PageTemplates.
Richard Jones <richard@users.sourceforge.net>
parents:
1008
diff
changeset
|
48 try: |
|
3509
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
49 from StructuredText.StructuredText import HTML as StructuredText |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
50 except ImportError: |
|
7022
f4bfc1af5d95
flake8 inline comment spacing; too many leading #
John Rouillard <rouilj@ieee.org>
parents:
7021
diff
changeset
|
51 try: # older version |
|
3509
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
52 import StructuredText |
|
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
53 except ImportError: |
|
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
54 StructuredText = None |
|
3862
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
55 try: |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
56 from docutils.core import publish_parts as ReStructuredText |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
57 except ImportError: |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
58 ReStructuredText = None |
|
5399
dccae35caa59
Python 3 preparation: update map() calls as needed.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5395
diff
changeset
|
59 try: |
|
dccae35caa59
Python 3 preparation: update map() calls as needed.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5395
diff
changeset
|
60 from itertools import zip_longest |
|
dccae35caa59
Python 3 preparation: update map() calls as needed.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5395
diff
changeset
|
61 except ImportError: |
|
dccae35caa59
Python 3 preparation: update map() calls as needed.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5395
diff
changeset
|
62 from itertools import izip_longest as zip_longest |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
63 |
| 6125 | 64 from roundup.exceptions import RoundupException |
| 65 | |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
66 |
|
6099
55c56ceacb8e
escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6098
diff
changeset
|
67 def _import_markdown2(): |
|
55c56ceacb8e
escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6098
diff
changeset
|
68 try: |
|
55c56ceacb8e
escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6098
diff
changeset
|
69 import markdown2, re |
|
7021
4e25815961a7
flake8: remove trailing whitespace; blank lines for definitions
John Rouillard <rouilj@ieee.org>
parents:
7020
diff
changeset
|
70 |
|
6099
55c56ceacb8e
escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6098
diff
changeset
|
71 class Markdown(markdown2.Markdown): |
|
6104
a1fd9551d416
don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6103
diff
changeset
|
72 # don't allow disabled protocols in links |
|
a1fd9551d416
don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6103
diff
changeset
|
73 _safe_protocols = re.compile('(?!' + ':|'.join([re.escape(s) for s in _disable_url_schemes]) + ':)', re.IGNORECASE) |
|
6099
55c56ceacb8e
escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6098
diff
changeset
|
74 |
|
6277
957a0fc20021
issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents:
6275
diff
changeset
|
75 def _extras(config): |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
76 extras = {'fenced-code-blocks': {}, 'nofollow': None} |
|
6277
957a0fc20021
issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents:
6275
diff
changeset
|
77 if config['MARKDOWN_BREAK_ON_NEWLINE']: |
|
957a0fc20021
issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents:
6275
diff
changeset
|
78 extras['break-on-newline'] = True |
|
957a0fc20021
issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents:
6275
diff
changeset
|
79 return extras |
|
957a0fc20021
issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents:
6275
diff
changeset
|
80 |
|
957a0fc20021
issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents:
6275
diff
changeset
|
81 markdown = lambda s, c: Markdown(safe_mode='escape', extras=_extras(c)).convert(s) |
|
6099
55c56ceacb8e
escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6098
diff
changeset
|
82 except ImportError: |
|
55c56ceacb8e
escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6098
diff
changeset
|
83 markdown = None |
|
55c56ceacb8e
escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6098
diff
changeset
|
84 |
|
55c56ceacb8e
escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6098
diff
changeset
|
85 return markdown |
|
55c56ceacb8e
escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6098
diff
changeset
|
86 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
87 |
|
6099
55c56ceacb8e
escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6098
diff
changeset
|
88 def _import_markdown(): |
|
55c56ceacb8e
escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6098
diff
changeset
|
89 try: |
|
55c56ceacb8e
escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6098
diff
changeset
|
90 from markdown import markdown as markdown_impl |
|
55c56ceacb8e
escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6098
diff
changeset
|
91 from markdown.extensions import Extension as MarkdownExtension |
|
6104
a1fd9551d416
don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6103
diff
changeset
|
92 from markdown.treeprocessors import Treeprocessor |
|
a1fd9551d416
don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6103
diff
changeset
|
93 |
|
a1fd9551d416
don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6103
diff
changeset
|
94 class RestrictLinksProcessor(Treeprocessor): |
|
a1fd9551d416
don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6103
diff
changeset
|
95 def run(self, root): |
|
a1fd9551d416
don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6103
diff
changeset
|
96 for el in root.iter('a'): |
|
a1fd9551d416
don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6103
diff
changeset
|
97 if 'href' in el.attrib: |
|
a1fd9551d416
don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6103
diff
changeset
|
98 url = el.attrib['href'].lstrip(' \r\n\t\x1a\0').lower() |
|
a1fd9551d416
don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6103
diff
changeset
|
99 for s in _disable_url_schemes: |
|
a1fd9551d416
don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6103
diff
changeset
|
100 if url.startswith(s + ':'): |
|
a1fd9551d416
don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6103
diff
changeset
|
101 el.attrib['href'] = '#' |
|
a1fd9551d416
don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6103
diff
changeset
|
102 |
|
6282
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
103 class LinkRendererWithRel(Treeprocessor): |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
104 ''' Rendering class that sets the rel="nofollow noreferer" |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
105 for links. ''' |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
106 rel_value = "nofollow noopener" |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
107 |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
108 def run(self, root): |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
109 for el in root.iter('a'): |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
110 if 'href' in el.attrib: |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
111 url = el.get('href').lstrip(' \r\n\t\x1a\0').lower() |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
112 if not url.startswith('http'): # only add rel for absolute http url's |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
113 continue |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
114 el.set('rel', self.rel_value) |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
115 |
|
6104
a1fd9551d416
don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6103
diff
changeset
|
116 # make sure any HTML tags get escaped and some links restricted |
|
6282
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
117 # and rel="nofollow noopener" are added to links |
|
6104
a1fd9551d416
don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6103
diff
changeset
|
118 class SafeHtml(MarkdownExtension): |
|
6100
d4ce26b14cf5
backward compatibility with older Markdown modules that pass globals arg
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6099
diff
changeset
|
119 def extendMarkdown(self, md, md_globals=None): |
|
6102
0a82437a2930
make sure to use the right deregister api so it works for older versions
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6100
diff
changeset
|
120 if hasattr(md.preprocessors, 'deregister'): |
|
0a82437a2930
make sure to use the right deregister api so it works for older versions
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6100
diff
changeset
|
121 md.preprocessors.deregister('html_block') |
|
0a82437a2930
make sure to use the right deregister api so it works for older versions
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6100
diff
changeset
|
122 else: |
|
0a82437a2930
make sure to use the right deregister api so it works for older versions
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6100
diff
changeset
|
123 del md.preprocessors['html_block'] |
|
0a82437a2930
make sure to use the right deregister api so it works for older versions
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6100
diff
changeset
|
124 if hasattr(md.inlinePatterns, 'deregister'): |
|
0a82437a2930
make sure to use the right deregister api so it works for older versions
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6100
diff
changeset
|
125 md.inlinePatterns.deregister('html') |
|
0a82437a2930
make sure to use the right deregister api so it works for older versions
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6100
diff
changeset
|
126 else: |
|
0a82437a2930
make sure to use the right deregister api so it works for older versions
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6100
diff
changeset
|
127 del md.inlinePatterns['html'] |
|
6099
55c56ceacb8e
escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6098
diff
changeset
|
128 |
|
6104
a1fd9551d416
don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6103
diff
changeset
|
129 if hasattr(md.preprocessors, 'register'): |
|
a1fd9551d416
don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6103
diff
changeset
|
130 md.treeprocessors.register(RestrictLinksProcessor(), 'restrict_links', 0) |
|
a1fd9551d416
don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6103
diff
changeset
|
131 else: |
|
a1fd9551d416
don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6103
diff
changeset
|
132 md.treeprocessors['restrict_links'] = RestrictLinksProcessor() |
|
6282
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
133 if hasattr(md.preprocessors, 'register'): |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
134 md.treeprocessors.register(LinkRendererWithRel(), 'add_link_rel', 0) |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
135 else: |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
136 md.treeprocessors['add_link_rel'] = LinkRendererWithRel() |
|
7019
e1528860e591
flake8 remove space from blank lines W293
John Rouillard <rouilj@ieee.org>
parents:
7018
diff
changeset
|
137 |
|
6277
957a0fc20021
issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents:
6275
diff
changeset
|
138 def _extensions(config): |
|
957a0fc20021
issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents:
6275
diff
changeset
|
139 extensions = [SafeHtml(), 'fenced_code'] |
|
957a0fc20021
issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents:
6275
diff
changeset
|
140 if config['MARKDOWN_BREAK_ON_NEWLINE']: |
|
957a0fc20021
issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents:
6275
diff
changeset
|
141 extensions.append('nl2br') |
|
957a0fc20021
issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents:
6275
diff
changeset
|
142 return extensions |
|
957a0fc20021
issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents:
6275
diff
changeset
|
143 |
|
957a0fc20021
issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents:
6275
diff
changeset
|
144 markdown = lambda s, c: markdown_impl(s, extensions=_extensions(c)) |
|
6099
55c56ceacb8e
escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6098
diff
changeset
|
145 except ImportError: |
|
55c56ceacb8e
escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6098
diff
changeset
|
146 markdown = None |
|
55c56ceacb8e
escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6098
diff
changeset
|
147 |
|
55c56ceacb8e
escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6098
diff
changeset
|
148 return markdown |
|
55c56ceacb8e
escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6098
diff
changeset
|
149 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
150 |
|
6099
55c56ceacb8e
escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6098
diff
changeset
|
151 def _import_mistune(): |
|
55c56ceacb8e
escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6098
diff
changeset
|
152 try: |
|
6104
a1fd9551d416
don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6103
diff
changeset
|
153 import mistune |
|
6282
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
154 from mistune import Renderer, escape_link, escape |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
155 |
|
7017
96be63649c92
flake8 fix additional spaces within () and []
John Rouillard <rouilj@ieee.org>
parents:
6856
diff
changeset
|
156 mistune._scheme_blacklist = [s + ':' for s in _disable_url_schemes] |
|
6277
957a0fc20021
issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents:
6275
diff
changeset
|
157 |
|
6282
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
158 class LinkRendererWithRel(Renderer): |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
159 ''' Rendering class that sets the rel="nofollow noreferer" |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
160 for links. ''' |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
161 |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
162 rel_value = "nofollow noopener" |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
163 |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
164 def autolink(self, link, is_email=False): |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
165 ''' handle <url or email> style explicit links ''' |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
166 text = link = escape_link(link) |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
167 if is_email: |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
168 link = 'mailto:%s' % link |
|
7017
96be63649c92
flake8 fix additional spaces within () and []
John Rouillard <rouilj@ieee.org>
parents:
6856
diff
changeset
|
169 return '<a href="%(href)s">%(text)s</a>' % { |
|
96be63649c92
flake8 fix additional spaces within () and []
John Rouillard <rouilj@ieee.org>
parents:
6856
diff
changeset
|
170 'href': link, 'text': text} |
|
6282
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
171 return '<a href="%(href)s" rel="%(rel)s">%(href)s</a>' % { |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
172 'rel': self.rel_value, 'href': escape_link(link)} |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
173 |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
174 def link(self, link, title, content): |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
175 ''' handle [text](url "title") style links and Reference |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
176 links ''' |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
177 |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
178 values = { |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
179 'content': escape(content), |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
180 'href': escape_link(link), |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
181 'rel': self.rel_value, |
|
7021
4e25815961a7
flake8: remove trailing whitespace; blank lines for definitions
John Rouillard <rouilj@ieee.org>
parents:
7020
diff
changeset
|
182 'title': escape(title) if title else '', |
|
6282
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
183 } |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
184 |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
185 if title: |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
186 return '<a href="%(href)s" rel="%(rel)s" ' \ |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
187 'title="%(title)s">%(content)s</a>' % values |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
188 |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
189 return '<a href="%(href)s" rel="%(rel)s">%(content)s</a>' % values |
|
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
190 |
|
6277
957a0fc20021
issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents:
6275
diff
changeset
|
191 def _options(config): |
|
6282
d30501bafdfb
issue2551098: markdown links missing rel="noreferer nofollow"
John Rouillard <rouilj@ieee.org>
parents:
6280
diff
changeset
|
192 options = {'renderer': LinkRendererWithRel(escape = True)} |
|
6277
957a0fc20021
issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents:
6275
diff
changeset
|
193 if config['MARKDOWN_BREAK_ON_NEWLINE']: |
|
957a0fc20021
issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents:
6275
diff
changeset
|
194 options['hard_wrap'] = True |
|
957a0fc20021
issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents:
6275
diff
changeset
|
195 return options |
|
957a0fc20021
issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents:
6275
diff
changeset
|
196 |
|
957a0fc20021
issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents:
6275
diff
changeset
|
197 markdown = lambda s, c: mistune.markdown(s, **_options(c)) |
|
6099
55c56ceacb8e
escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6098
diff
changeset
|
198 except ImportError: |
|
55c56ceacb8e
escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6098
diff
changeset
|
199 markdown = None |
|
55c56ceacb8e
escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6098
diff
changeset
|
200 |
|
55c56ceacb8e
escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6098
diff
changeset
|
201 return markdown |
|
55c56ceacb8e
escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6098
diff
changeset
|
202 |
|
7021
4e25815961a7
flake8: remove trailing whitespace; blank lines for definitions
John Rouillard <rouilj@ieee.org>
parents:
7020
diff
changeset
|
203 |
|
6099
55c56ceacb8e
escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6098
diff
changeset
|
204 markdown = _import_markdown2() or _import_markdown() or _import_mistune() |
|
55c56ceacb8e
escape HTML tags in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6098
diff
changeset
|
205 |
| 1049 | 206 # bring in the templating support |
|
6658
408fd477761f
Add i18n object to roundupdb.Database
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6620
diff
changeset
|
207 from roundup.cgi import ZTUtils |
|
2377
a53f87f2488a
StaticTranslationService moved here out of the code originating from Zope;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2347
diff
changeset
|
208 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
209 |
|
5488
52cb53eedf77
reworked random number use
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5485
diff
changeset
|
210 def anti_csrf_nonce(client, lifetime=None): |
|
5201
a9ace22e0a2f
issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents:
5193
diff
changeset
|
211 ''' Create a nonce for defending against CSRF attack. |
|
a9ace22e0a2f
issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents:
5193
diff
changeset
|
212 |
|
a9ace22e0a2f
issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents:
5193
diff
changeset
|
213 Then it stores the nonce, the session id for the user |
|
a9ace22e0a2f
issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents:
5193
diff
changeset
|
214 and the user id in the one time key database for use |
|
a9ace22e0a2f
issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents:
5193
diff
changeset
|
215 by the csrf validator that runs in the client::inner_main |
|
a9ace22e0a2f
issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents:
5193
diff
changeset
|
216 module/function. |
|
a9ace22e0a2f
issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents:
5193
diff
changeset
|
217 ''' |
|
a9ace22e0a2f
issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents:
5193
diff
changeset
|
218 otks=client.db.getOTKManager() |
|
6823
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
219 key = otks.getUniqueKey() |
|
5201
a9ace22e0a2f
issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents:
5193
diff
changeset
|
220 # lifetime is in minutes. |
|
a9ace22e0a2f
issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents:
5193
diff
changeset
|
221 if lifetime is None: |
|
a9ace22e0a2f
issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents:
5193
diff
changeset
|
222 lifetime = client.db.config['WEB_CSRF_TOKEN_LIFETIME'] |
|
a9ace22e0a2f
issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents:
5193
diff
changeset
|
223 |
|
6814
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6706
diff
changeset
|
224 ts = otks.lifetime(lifetime * 60) |
|
5201
a9ace22e0a2f
issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents:
5193
diff
changeset
|
225 otks.set(key, uid=client.db.getuid(), |
|
a9ace22e0a2f
issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents:
5193
diff
changeset
|
226 sid=client.session_api._sid, |
|
7017
96be63649c92
flake8 fix additional spaces within () and []
John Rouillard <rouilj@ieee.org>
parents:
6856
diff
changeset
|
227 __timestamp=ts) |
|
5319
62de601bdf6f
Fix commits although a Reject exception is raised
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5264
diff
changeset
|
228 otks.commit() |
|
5201
a9ace22e0a2f
issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents:
5193
diff
changeset
|
229 return key |
|
a9ace22e0a2f
issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents:
5193
diff
changeset
|
230 |
|
7022
f4bfc1af5d95
flake8 inline comment spacing; too many leading #
John Rouillard <rouilj@ieee.org>
parents:
7021
diff
changeset
|
231 # templating |
|
2377
a53f87f2488a
StaticTranslationService moved here out of the code originating from Zope;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2347
diff
changeset
|
232 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
233 |
|
6123
c177e7128dc9
issue2551083 Replace BaseException and Exception with RoundupException
John Rouillard <rouilj@ieee.org>
parents:
6104
diff
changeset
|
234 class NoTemplate(RoundupException): |
|
1068
665730c27d29
nicer template absence error
Richard Jones <richard@users.sourceforge.net>
parents:
1067
diff
changeset
|
235 pass |
|
665730c27d29
nicer template absence error
Richard Jones <richard@users.sourceforge.net>
parents:
1067
diff
changeset
|
236 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
237 |
|
6123
c177e7128dc9
issue2551083 Replace BaseException and Exception with RoundupException
John Rouillard <rouilj@ieee.org>
parents:
6104
diff
changeset
|
238 class Unauthorised(RoundupException): |
|
2466
7b248ea0a2e5
add translation to Unauthorised exception; mark missed text for translation
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2458
diff
changeset
|
239 def __init__(self, action, klass, translator=None): |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
240 self.action = action |
|
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
241 self.klass = klass |
|
2466
7b248ea0a2e5
add translation to Unauthorised exception; mark missed text for translation
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2458
diff
changeset
|
242 if translator: |
|
7b248ea0a2e5
add translation to Unauthorised exception; mark missed text for translation
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2458
diff
changeset
|
243 self._ = translator.gettext |
|
7b248ea0a2e5
add translation to Unauthorised exception; mark missed text for translation
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2458
diff
changeset
|
244 else: |
|
2561
0dd3dca6bd01
always use translation service set in the tracker client instance;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2558
diff
changeset
|
245 self._ = TranslationService.get_translation().gettext |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
246 |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
247 def __str__(self): |
|
2466
7b248ea0a2e5
add translation to Unauthorised exception; mark missed text for translation
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2458
diff
changeset
|
248 return self._('You are not allowed to %(action)s ' |
|
7b248ea0a2e5
add translation to Unauthorised exception; mark missed text for translation
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2458
diff
changeset
|
249 'items of class %(class)s') % { |
|
7b248ea0a2e5
add translation to Unauthorised exception; mark missed text for translation
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2458
diff
changeset
|
250 'action': self.action, 'class': self.klass} |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
251 |
|
4747
955860a18e12
templating: Raise exception if configured template engine is unknown
anatoly techtonik <techtonik@gmail.com>
parents:
4743
diff
changeset
|
252 |
|
955860a18e12
templating: Raise exception if configured template engine is unknown
anatoly techtonik <techtonik@gmail.com>
parents:
4743
diff
changeset
|
253 # --- Template Loader API |
|
955860a18e12
templating: Raise exception if configured template engine is unknown
anatoly techtonik <techtonik@gmail.com>
parents:
4743
diff
changeset
|
254 |
|
4719
05fe39f1d823
API break, bumping version to 1.15.0, renamed TemplatesBase to
anatoly techtonik <techtonik@gmail.com>
parents:
4696
diff
changeset
|
255 class LoaderBase: |
|
4740
fe9568a6cbd6
Untangle template selection logic from template loading functionality.
anatoly techtonik <techtonik@gmail.com>
parents:
4737
diff
changeset
|
256 """ Base for engine-specific template Loader class.""" |
|
4743
2d6959f1d2df
templating: proof of concept for Jinja2 support. Select 'jinja2'
anatoly techtonik <techtonik@gmail.com>
parents:
4742
diff
changeset
|
257 def __init__(self, dir): |
|
2d6959f1d2df
templating: proof of concept for Jinja2 support. Select 'jinja2'
anatoly techtonik <techtonik@gmail.com>
parents:
4742
diff
changeset
|
258 # loaders are given the template directory as a first argument |
|
2d6959f1d2df
templating: proof of concept for Jinja2 support. Select 'jinja2'
anatoly techtonik <techtonik@gmail.com>
parents:
4742
diff
changeset
|
259 pass |
|
2d6959f1d2df
templating: proof of concept for Jinja2 support. Select 'jinja2'
anatoly techtonik <techtonik@gmail.com>
parents:
4742
diff
changeset
|
260 |
|
4748
e339583eae8e
templating: rename precompileTemplates to precompile
anatoly techtonik <techtonik@gmail.com>
parents:
4747
diff
changeset
|
261 def precompile(self): |
|
e339583eae8e
templating: rename precompileTemplates to precompile
anatoly techtonik <techtonik@gmail.com>
parents:
4747
diff
changeset
|
262 """ This method may be called when tracker is loaded to precompile |
|
e339583eae8e
templating: rename precompileTemplates to precompile
anatoly techtonik <techtonik@gmail.com>
parents:
4747
diff
changeset
|
263 templates that support this ability. |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
264 """ |
|
4749
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
265 pass |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
266 |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
267 def load(self, tplname): |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
268 """ Load template and return template object with render() method. |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
269 |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
270 "tplname" is a template name. For filesystem loaders it is a |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
271 filename without extensions, typically in the "classname.view" |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
272 format. |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
273 """ |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
274 raise NotImplementedError |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
275 |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
276 def check(self, name): |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
277 """ Check if template with the given name exists. Should return |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
278 false if template can not be found. |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
279 """ |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
280 raise NotImplementedError |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
281 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
282 |
|
4749
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
283 class TALLoaderBase(LoaderBase): |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
284 """ Common methods for the legacy TAL loaders.""" |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
285 |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
286 def __init__(self, dir): |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
287 self.dir = dir |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
288 |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
289 def _find(self, name): |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
290 """ Find template, return full path and filename of the |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
291 template if it is found, None otherwise.""" |
|
5145
d22eb1d40d0e
issue2550701, issue2550891 deal with path traversal issue in TAL based template finding code. Use standard method.
John Rouillard <rouilj@ieee.org>
parents:
5112
diff
changeset
|
292 realsrc = os.path.realpath(self.dir) |
|
4749
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
293 for extension in ['', '.html', '.xml']: |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
294 f = name + extension |
|
5145
d22eb1d40d0e
issue2550701, issue2550891 deal with path traversal issue in TAL based template finding code. Use standard method.
John Rouillard <rouilj@ieee.org>
parents:
5112
diff
changeset
|
295 src = os.path.join(realsrc, f) |
|
d22eb1d40d0e
issue2550701, issue2550891 deal with path traversal issue in TAL based template finding code. Use standard method.
John Rouillard <rouilj@ieee.org>
parents:
5112
diff
changeset
|
296 realpath = os.path.realpath(src) |
|
5423
58057ea53779
Python 3 preparation: avoid string.find.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5418
diff
changeset
|
297 if not realpath.startswith(realsrc): |
|
7022
f4bfc1af5d95
flake8 inline comment spacing; too many leading #
John Rouillard <rouilj@ieee.org>
parents:
7021
diff
changeset
|
298 return # will raise invalid template |
|
4749
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
299 if os.path.exists(src): |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
300 return (src, f) |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
301 |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
302 def check(self, name): |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
303 return bool(self._find(name)) |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
304 |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
305 def precompile(self): |
|
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4748
diff
changeset
|
306 """ Precompile templates in load directory by loading them """ |
|
1204
b862bbf2067a
Replaced the content() callback ickiness with Page Template macro usage
Richard Jones <richard@users.sourceforge.net>
parents:
1202
diff
changeset
|
307 for filename in os.listdir(self.dir): |
|
2854
6acc315570eb
Templates.precompileTemplates: skip files without ".html" extension
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2827
diff
changeset
|
308 # skip subdirs |
|
6acc315570eb
Templates.precompileTemplates: skip files without ".html" extension
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2827
diff
changeset
|
309 if os.path.isdir(filename): |
|
6acc315570eb
Templates.precompileTemplates: skip files without ".html" extension
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2827
diff
changeset
|
310 continue |
| 2961 | 311 |
|
2959
fa5410ae581d
allow use of XML templates again
Richard Jones <richard@users.sourceforge.net>
parents:
2956
diff
changeset
|
312 # skip files without ".html" or ".xml" extension - .css, .js etc. |
|
fa5410ae581d
allow use of XML templates again
Richard Jones <richard@users.sourceforge.net>
parents:
2956
diff
changeset
|
313 for extension in '.html', '.xml': |
|
fa5410ae581d
allow use of XML templates again
Richard Jones <richard@users.sourceforge.net>
parents:
2956
diff
changeset
|
314 if filename.endswith(extension): |
|
fa5410ae581d
allow use of XML templates again
Richard Jones <richard@users.sourceforge.net>
parents:
2956
diff
changeset
|
315 break |
|
fa5410ae581d
allow use of XML templates again
Richard Jones <richard@users.sourceforge.net>
parents:
2956
diff
changeset
|
316 else: |
|
fa5410ae581d
allow use of XML templates again
Richard Jones <richard@users.sourceforge.net>
parents:
2956
diff
changeset
|
317 continue |
|
fa5410ae581d
allow use of XML templates again
Richard Jones <richard@users.sourceforge.net>
parents:
2956
diff
changeset
|
318 |
| 2961 | 319 # remove extension |
|
2959
fa5410ae581d
allow use of XML templates again
Richard Jones <richard@users.sourceforge.net>
parents:
2956
diff
changeset
|
320 filename = filename[:-len(extension)] |
|
4740
fe9568a6cbd6
Untangle template selection logic from template loading functionality.
anatoly techtonik <techtonik@gmail.com>
parents:
4737
diff
changeset
|
321 self.load(filename) |
|
fe9568a6cbd6
Untangle template selection logic from template loading functionality.
anatoly techtonik <techtonik@gmail.com>
parents:
4737
diff
changeset
|
322 |
|
1204
b862bbf2067a
Replaced the content() callback ickiness with Page Template macro usage
Richard Jones <richard@users.sourceforge.net>
parents:
1202
diff
changeset
|
323 def __getitem__(self, name): |
|
4724
98b727b6f7f8
Self-focument API in templating.py loader class
anatoly techtonik <techtonik@gmail.com>
parents:
4721
diff
changeset
|
324 """Special method to access templates by loader['name']""" |
|
1204
b862bbf2067a
Replaced the content() callback ickiness with Page Template macro usage
Richard Jones <richard@users.sourceforge.net>
parents:
1202
diff
changeset
|
325 try: |
|
4740
fe9568a6cbd6
Untangle template selection logic from template loading functionality.
anatoly techtonik <techtonik@gmail.com>
parents:
4737
diff
changeset
|
326 return self.load(name) |
|
5248
198b6e810c67
Use Python-3-compatible 'as' syntax for except statements
Eric S. Raymond <esr@thyrsus.com>
parents:
5232
diff
changeset
|
327 except NoTemplate as message: |
|
5378
35ea9b1efc14
Python 3 preparation: "raise" syntax.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5356
diff
changeset
|
328 raise KeyError(message) |
|
1016
d6c13142e7b9
Keep a cache of compiled PageTemplates.
Richard Jones <richard@users.sourceforge.net>
parents:
1008
diff
changeset
|
329 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
330 |
|
4750
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
331 class MultiLoader(LoaderBase): |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
332 def __init__(self): |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
333 self.loaders = [] |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
334 |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
335 def add_loader(self, loader): |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
336 self.loaders.append(loader) |
|
7019
e1528860e591
flake8 remove space from blank lines W293
John Rouillard <rouilj@ieee.org>
parents:
7018
diff
changeset
|
337 |
|
4750
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
338 def check(self, name): |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
339 for l in self.loaders: |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
340 if l.check(name): |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
341 return True |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
342 |
|
7021
4e25815961a7
flake8: remove trailing whitespace; blank lines for definitions
John Rouillard <rouilj@ieee.org>
parents:
7020
diff
changeset
|
343 def load(self, name): |
|
4750
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
344 for l in self.loaders: |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
345 if l.check(name): |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
346 return l.load(name) |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
347 |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
348 def __getitem__(self, name): |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
349 """Needed for TAL templates compatibility""" |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
350 # [ ] document root and helper templates |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
351 try: |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
352 return self.load(name) |
|
5248
198b6e810c67
Use Python-3-compatible 'as' syntax for except statements
Eric S. Raymond <esr@thyrsus.com>
parents:
5232
diff
changeset
|
353 except NoTemplate as message: |
|
5378
35ea9b1efc14
Python 3 preparation: "raise" syntax.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5356
diff
changeset
|
354 raise KeyError(message) |
|
7019
e1528860e591
flake8 remove space from blank lines W293
John Rouillard <rouilj@ieee.org>
parents:
7018
diff
changeset
|
355 |
|
4750
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
356 |
|
4743
2d6959f1d2df
templating: proof of concept for Jinja2 support. Select 'jinja2'
anatoly techtonik <techtonik@gmail.com>
parents:
4742
diff
changeset
|
357 class TemplateBase: |
|
2d6959f1d2df
templating: proof of concept for Jinja2 support. Select 'jinja2'
anatoly techtonik <techtonik@gmail.com>
parents:
4742
diff
changeset
|
358 content_type = 'text/html' |
|
4740
fe9568a6cbd6
Untangle template selection logic from template loading functionality.
anatoly techtonik <techtonik@gmail.com>
parents:
4737
diff
changeset
|
359 |
|
4750
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
360 |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
361 def get_loader(dir, template_engine): |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
362 |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
363 # Support for multiple engines using fallback mechanizm |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
364 # meaning that if first engine can't find template, we |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
365 # use the second |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
366 |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
367 engines = template_engine.split(',') |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
368 engines = [x.strip() for x in engines] |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
369 ml = MultiLoader() |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
370 |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
371 for engine_name in engines: |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
372 if engine_name == 'chameleon': |
|
5388
d26921b851c3
Python 3 preparation: make relative imports explicit.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5381
diff
changeset
|
373 from .engine_chameleon import Loader |
|
4750
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
374 elif engine_name == 'jinja2': |
|
5388
d26921b851c3
Python 3 preparation: make relative imports explicit.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5381
diff
changeset
|
375 from .engine_jinja2 import Jinja2Loader as Loader |
|
4750
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
376 elif engine_name == 'zopetal': |
|
5388
d26921b851c3
Python 3 preparation: make relative imports explicit.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5381
diff
changeset
|
377 from .engine_zopetal import Loader |
|
4750
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
378 else: |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
379 raise Exception('Unknown template engine "%s"' % engine_name) |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
380 ml.add_loader(Loader(dir)) |
|
7019
e1528860e591
flake8 remove space from blank lines W293
John Rouillard <rouilj@ieee.org>
parents:
7018
diff
changeset
|
381 |
|
4750
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
382 if len(engines) == 1: |
|
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
383 return ml.loaders[0] |
|
4747
955860a18e12
templating: Raise exception if configured template engine is unknown
anatoly techtonik <techtonik@gmail.com>
parents:
4743
diff
changeset
|
384 else: |
|
4750
12b029655c05
Templating proof of concept to use multiple engines simultaneously,
anatoly techtonik <techtonik@gmail.com>
parents:
4749
diff
changeset
|
385 return ml |
|
4587
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4584
diff
changeset
|
386 |
|
4747
955860a18e12
templating: Raise exception if configured template engine is unknown
anatoly techtonik <techtonik@gmail.com>
parents:
4743
diff
changeset
|
387 # --/ Template Loader API |
|
955860a18e12
templating: Raise exception if configured template engine is unknown
anatoly techtonik <techtonik@gmail.com>
parents:
4743
diff
changeset
|
388 |
|
955860a18e12
templating: Raise exception if configured template engine is unknown
anatoly techtonik <techtonik@gmail.com>
parents:
4743
diff
changeset
|
389 |
|
2390
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
390 def context(client, template=None, classname=None, request=None): |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
391 """Return the rendering context dictionary |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
392 |
|
2390
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
393 The dictionary includes following symbols: |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
394 |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
395 *context* |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
396 this is one of three things: |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
397 |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
398 1. None - we're viewing a "home" page |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
399 2. The current class of item being displayed. This is an HTMLClass |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
400 instance. |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
401 3. The current item from the database, if we're viewing a specific |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
402 item, as an HTMLItem instance. |
|
2390
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
403 |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
404 *request* |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
405 Includes information about the current request, including: |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
406 |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
407 - the url |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
408 - the current index information (``filterspec``, ``filter`` args, |
|
2327
36ae1b14aaab
remove excessive spaces in the translatable strings;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2324
diff
changeset
|
409 ``properties``, etc) parsed out of the form. |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
410 - methods for easy filterspec link generation |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
411 - *user*, the current user node as an HTMLItem instance |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
412 - *form*, the current CGI form information as a FieldStorage |
|
2390
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
413 |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
414 *config* |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
415 The current tracker config. |
|
2390
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
416 |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
417 *db* |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
418 The current database, used to access arbitrary database items. |
|
2390
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
419 |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
420 *utils* |
|
4584
760483ce731e
Fix override of TemplatingUtils in instance.py.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4577
diff
changeset
|
421 This is an instance of client.instance.TemplatingUtils, which is |
|
760483ce731e
Fix override of TemplatingUtils in instance.py.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4577
diff
changeset
|
422 optionally defined in the tracker interfaces module and defaults to |
|
760483ce731e
Fix override of TemplatingUtils in instance.py.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4577
diff
changeset
|
423 TemplatingUtils class in this file. |
|
2390
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
424 |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
425 *templates* |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
426 Access to all the tracker templates by name. |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
427 Used mainly in *use-macro* commands. |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
428 |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
429 *template* |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
430 Current rendering template. |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
431 |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
432 *true* |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
433 Logical True value. |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
434 |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
435 *false* |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
436 Logical False value. |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
437 |
|
2562
1f4791438b65
add 'i18n' to the rendering context dictionary description
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2561
diff
changeset
|
438 *i18n* |
|
1f4791438b65
add 'i18n' to the rendering context dictionary description
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2561
diff
changeset
|
439 Internationalization service, providing string translation |
|
1f4791438b65
add 'i18n' to the rendering context dictionary description
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2561
diff
changeset
|
440 methods ``gettext`` and ``ngettext``. |
|
1f4791438b65
add 'i18n' to the rendering context dictionary description
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2561
diff
changeset
|
441 |
|
2390
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
442 """ |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
443 |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
444 # if template, classname and/or request are not passed explicitely, |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
445 # compute form client |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
446 if template is None: |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
447 template = client.template |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
448 if classname is None: |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
449 classname = client.classname |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
450 if request is None: |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
451 request = HTMLRequest(client) |
|
1270
c3424abf7f77
added ability to implement new templating utility methods
Richard Jones <richard@users.sourceforge.net>
parents:
1263
diff
changeset
|
452 |
|
2390
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
453 c = { |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
454 'context': None, |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
455 'options': {}, |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
456 'nothing': None, |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
457 'request': request, |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
458 'db': HTMLDatabase(client), |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
459 'config': client.instance.config, |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
460 'tracker': client.instance, |
|
4584
760483ce731e
Fix override of TemplatingUtils in instance.py.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4577
diff
changeset
|
461 'utils': client.instance.TemplatingUtils(client), |
|
2854
6acc315570eb
Templates.precompileTemplates: skip files without ".html" extension
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2827
diff
changeset
|
462 'templates': client.instance.templates, |
|
2390
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
463 'template': template, |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
464 'true': 1, |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
465 'false': 0, |
|
2538
09b0fc5b1716
make client.translator available to templates as 'i18n'
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2524
diff
changeset
|
466 'i18n': client.translator |
|
2390
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
467 } |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
468 # add in the item if there is one |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
469 if client.nodeid: |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
470 c['context'] = HTMLItem(client, classname, client.nodeid, |
|
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
471 anonymous=1) |
|
5381
0942fe89e82e
Python 3 preparation: change "x.has_key(y)" to "y in x".
Joseph Myers <jsm@polyomino.org.uk>
parents:
5378
diff
changeset
|
472 elif classname in client.db.classes: |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
473 c['context'] = HTMLClass(client, classname, anonymous=1) |
|
2390
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
474 return c |
|
0778421414c3
added module function context()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2389
diff
changeset
|
475 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
476 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
477 class HTMLDatabase: |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
478 """ Return HTMLClasses for valid class fetches |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
479 """ |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
480 def __init__(self, client): |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
481 self._client = client |
|
3164
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
482 self._ = client._ |
|
1513
455f79a2981f
add access to real db through HTML db
Richard Jones <richard@users.sourceforge.net>
parents:
1510
diff
changeset
|
483 self._db = client.db |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
484 |
|
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
485 # we want config to be exposed |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
486 self.config = client.db.config |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
487 |
|
4055
de832c486f86
Fix designator regular expression in HTMLDatabase.__getitem__.
Stefan Seefeld <stefan@seefeld.name>
parents:
4054
diff
changeset
|
488 def __getitem__(self, item, desre=re.compile(r'(?P<cl>[a-zA-Z_]+)(?P<id>[-\d]+)')): |
|
1447
6118d4498db3
added "foo@" prefix to all but "context" form variable names
Richard Jones <richard@users.sourceforge.net>
parents:
1441
diff
changeset
|
489 # check to see if we're actually accessing an item |
|
6118d4498db3
added "foo@" prefix to all but "context" form variable names
Richard Jones <richard@users.sourceforge.net>
parents:
1441
diff
changeset
|
490 m = desre.match(item) |
|
6118d4498db3
added "foo@" prefix to all but "context" form variable names
Richard Jones <richard@users.sourceforge.net>
parents:
1441
diff
changeset
|
491 if m: |
|
2157
e976fa0640b3
db/userN wasn't returning HTMLUser
Richard Jones <richard@users.sourceforge.net>
parents:
2154
diff
changeset
|
492 cl = m.group('cl') |
|
e976fa0640b3
db/userN wasn't returning HTMLUser
Richard Jones <richard@users.sourceforge.net>
parents:
2154
diff
changeset
|
493 self._client.db.getclass(cl) |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
494 return HTMLItem(self._client, cl, m.group('id')) |
|
1447
6118d4498db3
added "foo@" prefix to all but "context" form variable names
Richard Jones <richard@users.sourceforge.net>
parents:
1441
diff
changeset
|
495 else: |
|
6118d4498db3
added "foo@" prefix to all but "context" form variable names
Richard Jones <richard@users.sourceforge.net>
parents:
1441
diff
changeset
|
496 self._client.db.getclass(item) |
|
6118d4498db3
added "foo@" prefix to all but "context" form variable names
Richard Jones <richard@users.sourceforge.net>
parents:
1441
diff
changeset
|
497 return HTMLClass(self._client, item) |
|
1134
16874c9b86ad
generic item editing
Richard Jones <richard@users.sourceforge.net>
parents:
1133
diff
changeset
|
498 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
499 def __getattr__(self, attr): |
|
1030
f5216dbced55
translate bad class lookup error meaningfully
Richard Jones <richard@users.sourceforge.net>
parents:
1028
diff
changeset
|
500 try: |
|
1134
16874c9b86ad
generic item editing
Richard Jones <richard@users.sourceforge.net>
parents:
1133
diff
changeset
|
501 return self[attr] |
|
1030
f5216dbced55
translate bad class lookup error meaningfully
Richard Jones <richard@users.sourceforge.net>
parents:
1028
diff
changeset
|
502 except KeyError: |
|
5378
35ea9b1efc14
Python 3 preparation: "raise" syntax.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5356
diff
changeset
|
503 raise AttributeError(attr) |
|
1134
16874c9b86ad
generic item editing
Richard Jones <richard@users.sourceforge.net>
parents:
1133
diff
changeset
|
504 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
505 def classes(self): |
|
5395
23b8e6067f7c
Python 3 preparation: update calls to dict methods.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5388
diff
changeset
|
506 l = sorted(self._client.db.classes.keys()) |
|
2118
917826e3fb54
In the classes method of HTMLDatabase, the variable 'm' was undefined.
Brian Kelley <wc2so1@users.sourceforge.net>
parents:
2116
diff
changeset
|
507 m = [] |
|
2031
bcb21e5722b8
fix permission handling around rego
Richard Jones <richard@users.sourceforge.net>
parents:
2025
diff
changeset
|
508 for item in l: |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
509 m.append(HTMLClass(self._client, item)) |
|
2118
917826e3fb54
In the classes method of HTMLDatabase, the variable 'm' was undefined.
Brian Kelley <wc2so1@users.sourceforge.net>
parents:
2116
diff
changeset
|
510 return m |
|
1104
d759c3cb1f06
Remeber values in edit/new submission error pages.
Richard Jones <richard@users.sourceforge.net>
parents:
1103
diff
changeset
|
511 |
|
7021
4e25815961a7
flake8: remove trailing whitespace; blank lines for definitions
John Rouillard <rouilj@ieee.org>
parents:
7020
diff
changeset
|
512 |
| 5809 | 513 num_re = re.compile(r'^-?\d+$') |
|
3860
c672b15ddae6
- fix id-lookup in case we already *know* that the value is an id (in
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3857
diff
changeset
|
514 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
515 |
|
3860
c672b15ddae6
- fix id-lookup in case we already *know* that the value is an id (in
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3857
diff
changeset
|
516 def lookupIds(db, prop, ids, fail_ok=0, num_re=num_re, do_lookup=True): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
517 """ "fail_ok" should be specified if we wish to pass through bad values |
|
2049
5a5f66e6b0e1
forward-port of fix from maint-0-6
Richard Jones <richard@users.sourceforge.net>
parents:
2037
diff
changeset
|
518 (most likely form values that we wish to represent back to the user) |
|
3860
c672b15ddae6
- fix id-lookup in case we already *know* that the value is an id (in
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3857
diff
changeset
|
519 "do_lookup" is there for preventing lookup by key-value (if we |
|
c672b15ddae6
- fix id-lookup in case we already *know* that the value is an id (in
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3857
diff
changeset
|
520 know that the value passed *is* an id) |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
521 """ |
|
1104
d759c3cb1f06
Remeber values in edit/new submission error pages.
Richard Jones <richard@users.sourceforge.net>
parents:
1103
diff
changeset
|
522 cl = db.getclass(prop.classname) |
|
d759c3cb1f06
Remeber values in edit/new submission error pages.
Richard Jones <richard@users.sourceforge.net>
parents:
1103
diff
changeset
|
523 l = [] |
|
d759c3cb1f06
Remeber values in edit/new submission error pages.
Richard Jones <richard@users.sourceforge.net>
parents:
1103
diff
changeset
|
524 for entry in ids: |
|
5927
a2a7860502fa
Fix lookupIds for try_id_parsing off
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5907
diff
changeset
|
525 # Do not look up numeric IDs if try_id_parsing |
|
a2a7860502fa
Fix lookupIds for try_id_parsing off
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5907
diff
changeset
|
526 if prop.try_id_parsing and num_re.match(entry): |
|
5876
716d50585c8d
Fix Link/Multilink searching
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5837
diff
changeset
|
527 l.append(entry) |
|
716d50585c8d
Fix Link/Multilink searching
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5837
diff
changeset
|
528 continue |
|
3861
d4ac8954ce5c
Update on recent fix, better version suggested by alexander smishlajev
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3860
diff
changeset
|
529 if do_lookup: |
|
d4ac8954ce5c
Update on recent fix, better version suggested by alexander smishlajev
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3860
diff
changeset
|
530 try: |
|
d4ac8954ce5c
Update on recent fix, better version suggested by alexander smishlajev
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3860
diff
changeset
|
531 item = cl.lookup(entry) |
|
d4ac8954ce5c
Update on recent fix, better version suggested by alexander smishlajev
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3860
diff
changeset
|
532 except (TypeError, KeyError): |
|
d4ac8954ce5c
Update on recent fix, better version suggested by alexander smishlajev
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3860
diff
changeset
|
533 pass |
|
d4ac8954ce5c
Update on recent fix, better version suggested by alexander smishlajev
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3860
diff
changeset
|
534 else: |
|
d4ac8954ce5c
Update on recent fix, better version suggested by alexander smishlajev
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3860
diff
changeset
|
535 l.append(item) |
|
3860
c672b15ddae6
- fix id-lookup in case we already *know* that the value is an id (in
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3857
diff
changeset
|
536 continue |
|
c672b15ddae6
- fix id-lookup in case we already *know* that the value is an id (in
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3857
diff
changeset
|
537 # if fail_ok, ignore lookup error |
|
c672b15ddae6
- fix id-lookup in case we already *know* that the value is an id (in
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3857
diff
changeset
|
538 # otherwise entry must be existing object id rather than key value |
|
5876
716d50585c8d
Fix Link/Multilink searching
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5837
diff
changeset
|
539 if fail_ok: |
|
3860
c672b15ddae6
- fix id-lookup in case we already *know* that the value is an id (in
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3857
diff
changeset
|
540 l.append(entry) |
|
1104
d759c3cb1f06
Remeber values in edit/new submission error pages.
Richard Jones <richard@users.sourceforge.net>
parents:
1103
diff
changeset
|
541 return l |
|
d759c3cb1f06
Remeber values in edit/new submission error pages.
Richard Jones <richard@users.sourceforge.net>
parents:
1103
diff
changeset
|
542 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
543 |
|
3860
c672b15ddae6
- fix id-lookup in case we already *know* that the value is an id (in
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3857
diff
changeset
|
544 def lookupKeys(linkcl, key, ids, num_re=num_re): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
545 """ Look up the "key" values for "ids" list - though some may already |
|
2083
a94eacad51c8
handle bad multilink input at item creation time better [SF#917834]
Richard Jones <richard@users.sourceforge.net>
parents:
2056
diff
changeset
|
546 be key values, not ids. |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
547 """ |
|
2083
a94eacad51c8
handle bad multilink input at item creation time better [SF#917834]
Richard Jones <richard@users.sourceforge.net>
parents:
2056
diff
changeset
|
548 l = [] |
|
a94eacad51c8
handle bad multilink input at item creation time better [SF#917834]
Richard Jones <richard@users.sourceforge.net>
parents:
2056
diff
changeset
|
549 for entry in ids: |
|
a94eacad51c8
handle bad multilink input at item creation time better [SF#917834]
Richard Jones <richard@users.sourceforge.net>
parents:
2056
diff
changeset
|
550 if num_re.match(entry): |
|
5051
b69c5e763295
issue2550748: Crash when creating new issues with non-existing multilink values (in classic template). Applied patch provided by user. (John Rouillard)
John Rouillard <rouilj@ieee.org>
parents:
5043
diff
changeset
|
551 try: |
|
5193
cfd6d1f2caa1
Fix incorrect indentation using tabs
John Kristensen <john@jerrykan.com>
parents:
5192
diff
changeset
|
552 label = linkcl.get(entry, key) |
|
cfd6d1f2caa1
Fix incorrect indentation using tabs
John Kristensen <john@jerrykan.com>
parents:
5192
diff
changeset
|
553 except IndexError: |
|
cfd6d1f2caa1
Fix incorrect indentation using tabs
John Kristensen <john@jerrykan.com>
parents:
5192
diff
changeset
|
554 # fall back to id if illegal (avoid template crash) |
|
5051
b69c5e763295
issue2550748: Crash when creating new issues with non-existing multilink values (in classic template). Applied patch provided by user. (John Rouillard)
John Rouillard <rouilj@ieee.org>
parents:
5043
diff
changeset
|
555 label = entry |
|
3401
62e4032cb280
merge from maint-0-8
Richard Jones <richard@users.sourceforge.net>
parents:
3394
diff
changeset
|
556 # fall back to designator if label is None |
|
62e4032cb280
merge from maint-0-8
Richard Jones <richard@users.sourceforge.net>
parents:
3394
diff
changeset
|
557 if label is None: label = '%s%s'%(linkcl.classname, entry) |
|
62e4032cb280
merge from maint-0-8
Richard Jones <richard@users.sourceforge.net>
parents:
3394
diff
changeset
|
558 l.append(label) |
|
2083
a94eacad51c8
handle bad multilink input at item creation time better [SF#917834]
Richard Jones <richard@users.sourceforge.net>
parents:
2056
diff
changeset
|
559 else: |
|
a94eacad51c8
handle bad multilink input at item creation time better [SF#917834]
Richard Jones <richard@users.sourceforge.net>
parents:
2056
diff
changeset
|
560 l.append(entry) |
|
a94eacad51c8
handle bad multilink input at item creation time better [SF#917834]
Richard Jones <richard@users.sourceforge.net>
parents:
2056
diff
changeset
|
561 return l |
|
a94eacad51c8
handle bad multilink input at item creation time better [SF#917834]
Richard Jones <richard@users.sourceforge.net>
parents:
2056
diff
changeset
|
562 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
563 |
|
3710
2862cb0d9be4
default attributes for input fields:
Tobias Herp <tobias-herp@users.sourceforge.net>
parents:
3702
diff
changeset
|
564 def _set_input_default_args(dic): |
|
2862cb0d9be4
default attributes for input fields:
Tobias Herp <tobias-herp@users.sourceforge.net>
parents:
3702
diff
changeset
|
565 # 'text' is the default value anyway -- |
|
2862cb0d9be4
default attributes for input fields:
Tobias Herp <tobias-herp@users.sourceforge.net>
parents:
3702
diff
changeset
|
566 # but for CSS usage it should be present |
|
2862cb0d9be4
default attributes for input fields:
Tobias Herp <tobias-herp@users.sourceforge.net>
parents:
3702
diff
changeset
|
567 dic.setdefault('type', 'text') |
|
2862cb0d9be4
default attributes for input fields:
Tobias Herp <tobias-herp@users.sourceforge.net>
parents:
3702
diff
changeset
|
568 # useful e.g for HTML LABELs: |
|
5381
0942fe89e82e
Python 3 preparation: change "x.has_key(y)" to "y in x".
Joseph Myers <jsm@polyomino.org.uk>
parents:
5378
diff
changeset
|
569 if 'id' not in dic: |
|
3710
2862cb0d9be4
default attributes for input fields:
Tobias Herp <tobias-herp@users.sourceforge.net>
parents:
3702
diff
changeset
|
570 try: |
|
2862cb0d9be4
default attributes for input fields:
Tobias Herp <tobias-herp@users.sourceforge.net>
parents:
3702
diff
changeset
|
571 if dic['text'] in ('radio', 'checkbox'): |
|
2862cb0d9be4
default attributes for input fields:
Tobias Herp <tobias-herp@users.sourceforge.net>
parents:
3702
diff
changeset
|
572 dic['id'] = '%(name)s-%(value)s' % dic |
|
2862cb0d9be4
default attributes for input fields:
Tobias Herp <tobias-herp@users.sourceforge.net>
parents:
3702
diff
changeset
|
573 else: |
|
2862cb0d9be4
default attributes for input fields:
Tobias Herp <tobias-herp@users.sourceforge.net>
parents:
3702
diff
changeset
|
574 dic['id'] = dic['name'] |
|
2862cb0d9be4
default attributes for input fields:
Tobias Herp <tobias-herp@users.sourceforge.net>
parents:
3702
diff
changeset
|
575 except KeyError: |
|
2862cb0d9be4
default attributes for input fields:
Tobias Herp <tobias-herp@users.sourceforge.net>
parents:
3702
diff
changeset
|
576 pass |
|
2862cb0d9be4
default attributes for input fields:
Tobias Herp <tobias-herp@users.sourceforge.net>
parents:
3702
diff
changeset
|
577 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
578 |
|
5988
39b8bc511ed7
Fix html generation errors for boolean options.
John Rouillard <rouilj@ieee.org>
parents:
5973
diff
changeset
|
579 def html4_cgi_escape_attrs(**attrs): |
|
39b8bc511ed7
Fix html generation errors for boolean options.
John Rouillard <rouilj@ieee.org>
parents:
5973
diff
changeset
|
580 ''' Boolean attributes like 'disabled', 'required' |
|
39b8bc511ed7
Fix html generation errors for boolean options.
John Rouillard <rouilj@ieee.org>
parents:
5973
diff
changeset
|
581 are represented without a value. E.G. |
|
39b8bc511ed7
Fix html generation errors for boolean options.
John Rouillard <rouilj@ieee.org>
parents:
5973
diff
changeset
|
582 <input required ..> not <input required="required" ...> |
|
39b8bc511ed7
Fix html generation errors for boolean options.
John Rouillard <rouilj@ieee.org>
parents:
5973
diff
changeset
|
583 The latter is xhtml. Recognize booleans by: |
|
39b8bc511ed7
Fix html generation errors for boolean options.
John Rouillard <rouilj@ieee.org>
parents:
5973
diff
changeset
|
584 value is None |
|
6058
8fbcaac944e7
Different fix for displaying booleans properly in xhtml vs html
John Rouillard <rouilj@ieee.org>
parents:
6057
diff
changeset
|
585 Code can use None to indicate a pure boolean. |
|
5988
39b8bc511ed7
Fix html generation errors for boolean options.
John Rouillard <rouilj@ieee.org>
parents:
5973
diff
changeset
|
586 ''' |
|
7021
4e25815961a7
flake8: remove trailing whitespace; blank lines for definitions
John Rouillard <rouilj@ieee.org>
parents:
7020
diff
changeset
|
587 return ' '.join(['%s="%s"'%(k,html_escape(str(v), True)) |
|
7023
ae6fa7b32e2d
flake8: E711 comparison to None should be 'if cond is not None:'
John Rouillard <rouilj@ieee.org>
parents:
7022
diff
changeset
|
588 if v is not None else '%s'%(k) |
|
5988
39b8bc511ed7
Fix html generation errors for boolean options.
John Rouillard <rouilj@ieee.org>
parents:
5973
diff
changeset
|
589 for k,v in sorted(attrs.items())]) |
|
39b8bc511ed7
Fix html generation errors for boolean options.
John Rouillard <rouilj@ieee.org>
parents:
5973
diff
changeset
|
590 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
591 |
|
5988
39b8bc511ed7
Fix html generation errors for boolean options.
John Rouillard <rouilj@ieee.org>
parents:
5973
diff
changeset
|
592 def xhtml_cgi_escape_attrs(**attrs): |
|
39b8bc511ed7
Fix html generation errors for boolean options.
John Rouillard <rouilj@ieee.org>
parents:
5973
diff
changeset
|
593 ''' Boolean attributes like 'disabled', 'required' |
|
39b8bc511ed7
Fix html generation errors for boolean options.
John Rouillard <rouilj@ieee.org>
parents:
5973
diff
changeset
|
594 are represented with a value that is the same as |
|
39b8bc511ed7
Fix html generation errors for boolean options.
John Rouillard <rouilj@ieee.org>
parents:
5973
diff
changeset
|
595 the attribute name.. E.G. |
|
39b8bc511ed7
Fix html generation errors for boolean options.
John Rouillard <rouilj@ieee.org>
parents:
5973
diff
changeset
|
596 <input required="required" ...> not <input required ..> |
|
39b8bc511ed7
Fix html generation errors for boolean options.
John Rouillard <rouilj@ieee.org>
parents:
5973
diff
changeset
|
597 The latter is html4 or 5. Recognize booleans by: |
|
39b8bc511ed7
Fix html generation errors for boolean options.
John Rouillard <rouilj@ieee.org>
parents:
5973
diff
changeset
|
598 value is None |
|
6058
8fbcaac944e7
Different fix for displaying booleans properly in xhtml vs html
John Rouillard <rouilj@ieee.org>
parents:
6057
diff
changeset
|
599 Code can use None to indicate a pure boolean. |
|
5988
39b8bc511ed7
Fix html generation errors for boolean options.
John Rouillard <rouilj@ieee.org>
parents:
5973
diff
changeset
|
600 ''' |
|
5800
1a835db41674
Call cgi.escape only on python 2. Replace with html.escapeif it can be
John Rouillard <rouilj@ieee.org>
parents:
5684
diff
changeset
|
601 return ' '.join(['%s="%s"'%(k,html_escape(str(v), True)) |
|
7023
ae6fa7b32e2d
flake8: E711 comparison to None should be 'if cond is not None:'
John Rouillard <rouilj@ieee.org>
parents:
7022
diff
changeset
|
602 if v is not None else '%s="%s"'%(k,k) |
|
5988
39b8bc511ed7
Fix html generation errors for boolean options.
John Rouillard <rouilj@ieee.org>
parents:
5973
diff
changeset
|
603 for k,v in sorted(attrs.items())]) |
|
4267
c5f52c2c9e36
Provide ability to specify arbitrary HTML attributes.
Stefan Seefeld <stefan@seefeld.name>
parents:
4233
diff
changeset
|
604 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
605 |
|
1956
1e2cccf6b53b
give access to the input() method all over the place
Richard Jones <richard@users.sourceforge.net>
parents:
1952
diff
changeset
|
606 def input_html4(**attrs): |
|
1e2cccf6b53b
give access to the input() method all over the place
Richard Jones <richard@users.sourceforge.net>
parents:
1952
diff
changeset
|
607 """Generate an 'input' (html4) element with given attributes""" |
|
3909
e89bcb28f683
indexargs_url force ids to int
Justus Pendleton <jpend@users.sourceforge.net>
parents:
3905
diff
changeset
|
608 _set_input_default_args(attrs) |
|
5988
39b8bc511ed7
Fix html generation errors for boolean options.
John Rouillard <rouilj@ieee.org>
parents:
5973
diff
changeset
|
609 return '<input %s>'%html4_cgi_escape_attrs(**attrs) |
|
1956
1e2cccf6b53b
give access to the input() method all over the place
Richard Jones <richard@users.sourceforge.net>
parents:
1952
diff
changeset
|
610 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
611 |
|
1956
1e2cccf6b53b
give access to the input() method all over the place
Richard Jones <richard@users.sourceforge.net>
parents:
1952
diff
changeset
|
612 def input_xhtml(**attrs): |
|
1e2cccf6b53b
give access to the input() method all over the place
Richard Jones <richard@users.sourceforge.net>
parents:
1952
diff
changeset
|
613 """Generate an 'input' (xhtml) element with given attributes""" |
|
3710
2862cb0d9be4
default attributes for input fields:
Tobias Herp <tobias-herp@users.sourceforge.net>
parents:
3702
diff
changeset
|
614 _set_input_default_args(attrs) |
|
5988
39b8bc511ed7
Fix html generation errors for boolean options.
John Rouillard <rouilj@ieee.org>
parents:
5973
diff
changeset
|
615 return '<input %s/>'%xhtml_cgi_escape_attrs(**attrs) |
|
1956
1e2cccf6b53b
give access to the input() method all over the place
Richard Jones <richard@users.sourceforge.net>
parents:
1952
diff
changeset
|
616 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
617 |
|
4878
f6e76a03b502
HTML* classes for cgi are now all new-style
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4875
diff
changeset
|
618 class HTMLInputMixin(object): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
619 """ requires a _client property """ |
|
1956
1e2cccf6b53b
give access to the input() method all over the place
Richard Jones <richard@users.sourceforge.net>
parents:
1952
diff
changeset
|
620 def __init__(self): |
|
1e2cccf6b53b
give access to the input() method all over the place
Richard Jones <richard@users.sourceforge.net>
parents:
1952
diff
changeset
|
621 html_version = 'html4' |
|
1e2cccf6b53b
give access to the input() method all over the place
Richard Jones <richard@users.sourceforge.net>
parents:
1952
diff
changeset
|
622 if hasattr(self._client.instance.config, 'HTML_VERSION'): |
|
1e2cccf6b53b
give access to the input() method all over the place
Richard Jones <richard@users.sourceforge.net>
parents:
1952
diff
changeset
|
623 html_version = self._client.instance.config.HTML_VERSION |
|
6058
8fbcaac944e7
Different fix for displaying booleans properly in xhtml vs html
John Rouillard <rouilj@ieee.org>
parents:
6057
diff
changeset
|
624 if html_version == 'xhtml': |
|
8fbcaac944e7
Different fix for displaying booleans properly in xhtml vs html
John Rouillard <rouilj@ieee.org>
parents:
6057
diff
changeset
|
625 self.input = input_xhtml |
|
8fbcaac944e7
Different fix for displaying booleans properly in xhtml vs html
John Rouillard <rouilj@ieee.org>
parents:
6057
diff
changeset
|
626 self.cgi_escape_attrs=xhtml_cgi_escape_attrs |
|
8fbcaac944e7
Different fix for displaying booleans properly in xhtml vs html
John Rouillard <rouilj@ieee.org>
parents:
6057
diff
changeset
|
627 else: |
|
8fbcaac944e7
Different fix for displaying booleans properly in xhtml vs html
John Rouillard <rouilj@ieee.org>
parents:
6057
diff
changeset
|
628 self.input = input_html4 |
|
8fbcaac944e7
Different fix for displaying booleans properly in xhtml vs html
John Rouillard <rouilj@ieee.org>
parents:
6057
diff
changeset
|
629 self.cgi_escape_attrs=html4_cgi_escape_attrs |
|
2396
39cdddd313ca
HTMLInputMixin provides translation interface for all its hiers...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2390
diff
changeset
|
630 # self._context is used for translations. |
|
39cdddd313ca
HTMLInputMixin provides translation interface for all its hiers...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2390
diff
changeset
|
631 # will be initialized by the first call to .gettext() |
|
39cdddd313ca
HTMLInputMixin provides translation interface for all its hiers...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2390
diff
changeset
|
632 self._context = None |
|
39cdddd313ca
HTMLInputMixin provides translation interface for all its hiers...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2390
diff
changeset
|
633 |
|
39cdddd313ca
HTMLInputMixin provides translation interface for all its hiers...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2390
diff
changeset
|
634 def gettext(self, msgid): |
|
39cdddd313ca
HTMLInputMixin provides translation interface for all its hiers...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2390
diff
changeset
|
635 """Return the localized translation of msgid""" |
|
39cdddd313ca
HTMLInputMixin provides translation interface for all its hiers...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2390
diff
changeset
|
636 if self._context is None: |
|
39cdddd313ca
HTMLInputMixin provides translation interface for all its hiers...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2390
diff
changeset
|
637 self._context = context(self._client) |
|
2561
0dd3dca6bd01
always use translation service set in the tracker client instance;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2558
diff
changeset
|
638 return self._client.translator.translate(domain="roundup", |
|
2396
39cdddd313ca
HTMLInputMixin provides translation interface for all its hiers...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2390
diff
changeset
|
639 msgid=msgid, context=self._context) |
|
39cdddd313ca
HTMLInputMixin provides translation interface for all its hiers...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2390
diff
changeset
|
640 |
|
39cdddd313ca
HTMLInputMixin provides translation interface for all its hiers...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2390
diff
changeset
|
641 _ = gettext |
|
1956
1e2cccf6b53b
give access to the input() method all over the place
Richard Jones <richard@users.sourceforge.net>
parents:
1952
diff
changeset
|
642 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
643 |
|
4878
f6e76a03b502
HTML* classes for cgi are now all new-style
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4875
diff
changeset
|
644 class HTMLPermissions(object): |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
645 |
|
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
646 def view_check(self): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
647 """ Raise the Unauthorised exception if the user's not permitted to |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
648 view this class. |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
649 """ |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
650 if not self.is_view_ok(): |
|
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
651 raise Unauthorised("view", self._classname, |
|
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
652 translator=self._client.translator) |
|
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
653 |
|
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
654 def edit_check(self): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
655 """ Raise the Unauthorised exception if the user's not permitted to |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
656 edit items of this class. |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
657 """ |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
658 if not self.is_edit_ok(): |
|
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
659 raise Unauthorised("edit", self._classname, |
|
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
660 translator=self._client.translator) |
|
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
661 |
|
4088
34434785f308
Plug a number of security holes:
Richard Jones <richard@users.sourceforge.net>
parents:
4058
diff
changeset
|
662 def retire_check(self): |
|
34434785f308
Plug a number of security holes:
Richard Jones <richard@users.sourceforge.net>
parents:
4058
diff
changeset
|
663 """ Raise the Unauthorised exception if the user's not permitted to |
|
34434785f308
Plug a number of security holes:
Richard Jones <richard@users.sourceforge.net>
parents:
4058
diff
changeset
|
664 retire items of this class. |
|
34434785f308
Plug a number of security holes:
Richard Jones <richard@users.sourceforge.net>
parents:
4058
diff
changeset
|
665 """ |
|
34434785f308
Plug a number of security holes:
Richard Jones <richard@users.sourceforge.net>
parents:
4058
diff
changeset
|
666 if not self.is_retire_ok(): |
|
34434785f308
Plug a number of security holes:
Richard Jones <richard@users.sourceforge.net>
parents:
4058
diff
changeset
|
667 raise Unauthorised("retire", self._classname, |
|
34434785f308
Plug a number of security holes:
Richard Jones <richard@users.sourceforge.net>
parents:
4058
diff
changeset
|
668 translator=self._client.translator) |
|
34434785f308
Plug a number of security holes:
Richard Jones <richard@users.sourceforge.net>
parents:
4058
diff
changeset
|
669 |
|
2983
9614a101b68f
Stuff from the train ride this morning:
Richard Jones <richard@users.sourceforge.net>
parents:
2962
diff
changeset
|
670 |
|
1956
1e2cccf6b53b
give access to the input() method all over the place
Richard Jones <richard@users.sourceforge.net>
parents:
1952
diff
changeset
|
671 class HTMLClass(HTMLInputMixin, HTMLPermissions): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
672 """ Accesses through a class (either through *class* or *db.<classname>*) |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
673 """ |
|
1447
6118d4498db3
added "foo@" prefix to all but "context" form variable names
Richard Jones <richard@users.sourceforge.net>
parents:
1441
diff
changeset
|
674 def __init__(self, client, classname, anonymous=0): |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
675 self._client = client |
|
3164
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
676 self._ = client._ |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
677 self._db = client.db |
|
1447
6118d4498db3
added "foo@" prefix to all but "context" form variable names
Richard Jones <richard@users.sourceforge.net>
parents:
1441
diff
changeset
|
678 self._anonymous = anonymous |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
679 |
|
1136
7e193bbda38e
added generic item editing
Richard Jones <richard@users.sourceforge.net>
parents:
1134
diff
changeset
|
680 # we want classname to be exposed, but _classname gives a |
|
7e193bbda38e
added generic item editing
Richard Jones <richard@users.sourceforge.net>
parents:
1134
diff
changeset
|
681 # consistent API for extending Class/Item |
|
7e193bbda38e
added generic item editing
Richard Jones <richard@users.sourceforge.net>
parents:
1134
diff
changeset
|
682 self._classname = self.classname = classname |
|
1204
b862bbf2067a
Replaced the content() callback ickiness with Page Template macro usage
Richard Jones <richard@users.sourceforge.net>
parents:
1202
diff
changeset
|
683 self._klass = self._db.getclass(self.classname) |
|
b862bbf2067a
Replaced the content() callback ickiness with Page Template macro usage
Richard Jones <richard@users.sourceforge.net>
parents:
1202
diff
changeset
|
684 self._props = self._klass.getprops() |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
685 |
|
1956
1e2cccf6b53b
give access to the input() method all over the place
Richard Jones <richard@users.sourceforge.net>
parents:
1952
diff
changeset
|
686 HTMLInputMixin.__init__(self) |
|
1952
c40ed9113285
Applied Stefan Seefeld's html4/xhtml patch with some changes.
Richard Jones <richard@users.sourceforge.net>
parents:
1932
diff
changeset
|
687 |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
688 def is_edit_ok(self): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
689 """ Is the user allowed to Create the current class? |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
690 """ |
|
4328
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
691 perm = self._db.security.hasPermission |
|
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
692 return perm('Web Access', self._client.userid) and perm('Create', |
|
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
693 self._client.userid, self._classname) |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
694 |
|
4088
34434785f308
Plug a number of security holes:
Richard Jones <richard@users.sourceforge.net>
parents:
4058
diff
changeset
|
695 def is_retire_ok(self): |
|
34434785f308
Plug a number of security holes:
Richard Jones <richard@users.sourceforge.net>
parents:
4058
diff
changeset
|
696 """ Is the user allowed to retire items of the current class? |
|
34434785f308
Plug a number of security holes:
Richard Jones <richard@users.sourceforge.net>
parents:
4058
diff
changeset
|
697 """ |
|
4328
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
698 perm = self._db.security.hasPermission |
|
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
699 return perm('Web Access', self._client.userid) and perm('Retire', |
|
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
700 self._client.userid, self._classname) |
|
4088
34434785f308
Plug a number of security holes:
Richard Jones <richard@users.sourceforge.net>
parents:
4058
diff
changeset
|
701 |
|
6150
edbd4bba728a
Add 'is_restore_ok' method
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6125
diff
changeset
|
702 def is_restore_ok(self): |
|
edbd4bba728a
Add 'is_restore_ok' method
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6125
diff
changeset
|
703 """ Is the user allowed to restore retired items of the current class? |
|
edbd4bba728a
Add 'is_restore_ok' method
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6125
diff
changeset
|
704 """ |
|
edbd4bba728a
Add 'is_restore_ok' method
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6125
diff
changeset
|
705 perm = self._db.security.hasPermission |
|
edbd4bba728a
Add 'is_restore_ok' method
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6125
diff
changeset
|
706 return perm('Web Access', self._client.userid) and perm('Restore', |
|
edbd4bba728a
Add 'is_restore_ok' method
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6125
diff
changeset
|
707 self._client.userid, self._classname) |
|
edbd4bba728a
Add 'is_restore_ok' method
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6125
diff
changeset
|
708 |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
709 def is_view_ok(self): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
710 """ Is the user allowed to View the current class? |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
711 """ |
|
4328
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
712 perm = self._db.security.hasPermission |
|
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
713 return perm('Web Access', self._client.userid) and perm('View', |
|
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
714 self._client.userid, self._classname) |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
715 |
|
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
716 def is_only_view_ok(self): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
717 """ Is the user only allowed to View (ie. not Create) the current class? |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
718 """ |
|
2651
17bab083c8a0
Couple of fixes - make the interface just be is_edit_ok...
Richard Jones <richard@users.sourceforge.net>
parents:
2649
diff
changeset
|
719 return self.is_view_ok() and not self.is_edit_ok() |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
720 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
721 def __repr__(self): |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
722 return '<HTMLClass(0x%x) %s>'%(id(self), self.classname) |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
723 |
| 1002 | 724 def __getitem__(self, item): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
725 """ return an HTMLProperty instance |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
726 """ |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
727 |
|
1073
cf30c6cdca02
More documentation.
Richard Jones <richard@users.sourceforge.net>
parents:
1068
diff
changeset
|
728 # we don't exist |
|
cf30c6cdca02
More documentation.
Richard Jones <richard@users.sourceforge.net>
parents:
1068
diff
changeset
|
729 if item == 'id': |
|
cf30c6cdca02
More documentation.
Richard Jones <richard@users.sourceforge.net>
parents:
1068
diff
changeset
|
730 return None |
|
cf30c6cdca02
More documentation.
Richard Jones <richard@users.sourceforge.net>
parents:
1068
diff
changeset
|
731 |
|
cf30c6cdca02
More documentation.
Richard Jones <richard@users.sourceforge.net>
parents:
1068
diff
changeset
|
732 # get the property |
|
2056
ba1d54edc53f
nicer invalid property error in HTML templating
Richard Jones <richard@users.sourceforge.net>
parents:
2049
diff
changeset
|
733 try: |
|
ba1d54edc53f
nicer invalid property error in HTML templating
Richard Jones <richard@users.sourceforge.net>
parents:
2049
diff
changeset
|
734 prop = self._props[item] |
|
ba1d54edc53f
nicer invalid property error in HTML templating
Richard Jones <richard@users.sourceforge.net>
parents:
2049
diff
changeset
|
735 except KeyError: |
|
5378
35ea9b1efc14
Python 3 preparation: "raise" syntax.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5356
diff
changeset
|
736 raise KeyError('No such property "%s" on %s'%(item, self.classname)) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
737 |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
738 # look up the correct HTMLProperty class |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
739 for klass, htmlklass in propclasses: |
|
1104
d759c3cb1f06
Remeber values in edit/new submission error pages.
Richard Jones <richard@users.sourceforge.net>
parents:
1103
diff
changeset
|
740 if not isinstance(prop, klass): |
|
d759c3cb1f06
Remeber values in edit/new submission error pages.
Richard Jones <richard@users.sourceforge.net>
parents:
1103
diff
changeset
|
741 continue |
|
3779
ee73abcc95d2
Sorry, another mega-patch:
Richard Jones <richard@users.sourceforge.net>
parents:
3770
diff
changeset
|
742 return htmlklass(self._client, self._classname, None, prop, item, |
|
6404
e29d5f4e0af4
issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents:
6398
diff
changeset
|
743 None, self._anonymous) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
744 |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
745 # no good |
|
5378
35ea9b1efc14
Python 3 preparation: "raise" syntax.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5356
diff
changeset
|
746 raise KeyError(item) |
| 1002 | 747 |
| 748 def __getattr__(self, attr): | |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
749 """ convenience access """ |
| 1002 | 750 try: |
| 751 return self[attr] | |
| 752 except KeyError: | |
|
5378
35ea9b1efc14
Python 3 preparation: "raise" syntax.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5356
diff
changeset
|
753 raise AttributeError(attr) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
754 |
|
1743
f166cd4fd392
add action attribute to issue.item form action tag
Richard Jones <richard@users.sourceforge.net>
parents:
1739
diff
changeset
|
755 def designator(self): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
756 """ Return this class' designator (classname) """ |
|
1743
f166cd4fd392
add action attribute to issue.item form action tag
Richard Jones <richard@users.sourceforge.net>
parents:
1739
diff
changeset
|
757 return self._classname |
|
f166cd4fd392
add action attribute to issue.item form action tag
Richard Jones <richard@users.sourceforge.net>
parents:
1739
diff
changeset
|
758 |
|
3860
c672b15ddae6
- fix id-lookup in case we already *know* that the value is an id (in
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3857
diff
changeset
|
759 def getItem(self, itemid, num_re=num_re): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
760 """ Get an item of this class by its item id. |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
761 """ |
|
1200
0a7bd082b94a
usability improvements in API
Richard Jones <richard@users.sourceforge.net>
parents:
1183
diff
changeset
|
762 # make sure we're looking at an itemid |
|
2010
1b11ffd8015e
forward-porting of fixed edit action / parsePropsFromForm...
Richard Jones <richard@users.sourceforge.net>
parents:
2005
diff
changeset
|
763 if not isinstance(itemid, type(1)) and not num_re.match(itemid): |
|
1200
0a7bd082b94a
usability improvements in API
Richard Jones <richard@users.sourceforge.net>
parents:
1183
diff
changeset
|
764 itemid = self._klass.lookup(itemid) |
|
0a7bd082b94a
usability improvements in API
Richard Jones <richard@users.sourceforge.net>
parents:
1183
diff
changeset
|
765 |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
766 return HTMLItem(self._client, self.classname, itemid) |
|
1200
0a7bd082b94a
usability improvements in API
Richard Jones <richard@users.sourceforge.net>
parents:
1183
diff
changeset
|
767 |
|
5222
9bf221cebef3
Make properties method return only properties the user can search.
John Rouillard <rouilj@ieee.org>
parents:
5221
diff
changeset
|
768 def properties(self, sort=1, cansearch=True): |
|
9bf221cebef3
Make properties method return only properties the user can search.
John Rouillard <rouilj@ieee.org>
parents:
5221
diff
changeset
|
769 """ Return HTMLProperty for allowed class' properties. |
|
9bf221cebef3
Make properties method return only properties the user can search.
John Rouillard <rouilj@ieee.org>
parents:
5221
diff
changeset
|
770 |
|
9bf221cebef3
Make properties method return only properties the user can search.
John Rouillard <rouilj@ieee.org>
parents:
5221
diff
changeset
|
771 To return all properties call it with cansearch=False |
|
9bf221cebef3
Make properties method return only properties the user can search.
John Rouillard <rouilj@ieee.org>
parents:
5221
diff
changeset
|
772 and it will return properties the user is unable to |
|
9bf221cebef3
Make properties method return only properties the user can search.
John Rouillard <rouilj@ieee.org>
parents:
5221
diff
changeset
|
773 search. |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
774 """ |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
775 l = [] |
|
5222
9bf221cebef3
Make properties method return only properties the user can search.
John Rouillard <rouilj@ieee.org>
parents:
5221
diff
changeset
|
776 canSearch=self._db.security.hasSearchPermission |
|
9bf221cebef3
Make properties method return only properties the user can search.
John Rouillard <rouilj@ieee.org>
parents:
5221
diff
changeset
|
777 userid=self._client.userid |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
778 for name, prop in self._props.items(): |
|
5222
9bf221cebef3
Make properties method return only properties the user can search.
John Rouillard <rouilj@ieee.org>
parents:
5221
diff
changeset
|
779 if cansearch and \ |
|
9bf221cebef3
Make properties method return only properties the user can search.
John Rouillard <rouilj@ieee.org>
parents:
5221
diff
changeset
|
780 not canSearch(userid, self._classname, name): |
|
9bf221cebef3
Make properties method return only properties the user can search.
John Rouillard <rouilj@ieee.org>
parents:
5221
diff
changeset
|
781 continue |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
782 for klass, htmlklass in propclasses: |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
783 if isinstance(prop, klass): |
|
4481
9bbf3758c16a
Allow default value declaration in DB schema.
Stefan Seefeld <stefan@seefeld.name>
parents:
4466
diff
changeset
|
784 value = prop.get_default_value() |
|
1450
7a9db3f9022a
... and a classname
Richard Jones <richard@users.sourceforge.net>
parents:
1449
diff
changeset
|
785 l.append(htmlklass(self._client, self._classname, '', |
|
4481
9bbf3758c16a
Allow default value declaration in DB schema.
Stefan Seefeld <stefan@seefeld.name>
parents:
4466
diff
changeset
|
786 prop, name, value, self._anonymous)) |
|
1633
ac5f7e5a11e5
sort HTMLClass.properties results by name (feature [SF#724738])
Richard Jones <richard@users.sourceforge.net>
parents:
1631
diff
changeset
|
787 if sort: |
|
5414
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
788 l.sort(key=lambda a:a._name) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
789 return l |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
790 |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
791 def list(self, sort_on=None): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
792 """ List all items in this class. |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
793 """ |
|
1155
5cf0a6b6e787
*cough* sort list results *cough*
Richard Jones <richard@users.sourceforge.net>
parents:
1151
diff
changeset
|
794 # get the list and sort it nicely |
|
5cf0a6b6e787
*cough* sort list results *cough*
Richard Jones <richard@users.sourceforge.net>
parents:
1151
diff
changeset
|
795 l = self._klass.list() |
|
5414
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
796 keyfunc = make_key_function(self._db, self._classname, sort_on) |
|
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
797 l.sort(key=keyfunc) |
|
1155
5cf0a6b6e787
*cough* sort list results *cough*
Richard Jones <richard@users.sourceforge.net>
parents:
1151
diff
changeset
|
798 |
|
3126
a2889d22db4a
the cgi templating code now checks item-level
Richard Jones <richard@users.sourceforge.net>
parents:
3117
diff
changeset
|
799 # check perms |
|
a2889d22db4a
the cgi templating code now checks item-level
Richard Jones <richard@users.sourceforge.net>
parents:
3117
diff
changeset
|
800 check = self._client.db.security.hasPermission |
|
a2889d22db4a
the cgi templating code now checks item-level
Richard Jones <richard@users.sourceforge.net>
parents:
3117
diff
changeset
|
801 userid = self._client.userid |
|
4328
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
802 if not check('Web Access', userid): |
|
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
803 return [] |
|
3126
a2889d22db4a
the cgi templating code now checks item-level
Richard Jones <richard@users.sourceforge.net>
parents:
3117
diff
changeset
|
804 |
|
a2889d22db4a
the cgi templating code now checks item-level
Richard Jones <richard@users.sourceforge.net>
parents:
3117
diff
changeset
|
805 l = [HTMLItem(self._client, self._classname, id) for id in l |
|
a2889d22db4a
the cgi templating code now checks item-level
Richard Jones <richard@users.sourceforge.net>
parents:
3117
diff
changeset
|
806 if check('View', userid, self._classname, itemid=id)] |
|
a2889d22db4a
the cgi templating code now checks item-level
Richard Jones <richard@users.sourceforge.net>
parents:
3117
diff
changeset
|
807 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
808 return l |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
809 |
|
1041
c28603c9f831
Class help and generic class editing done.
Richard Jones <richard@users.sourceforge.net>
parents:
1030
diff
changeset
|
810 def csv(self): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
811 """ Return the items of this class as a chunk of CSV text. |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
812 """ |
|
1041
c28603c9f831
Class help and generic class editing done.
Richard Jones <richard@users.sourceforge.net>
parents:
1030
diff
changeset
|
813 props = self.propnames() |
|
5418
55f09ca366c4
Python 3 preparation: StringIO.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5416
diff
changeset
|
814 s = StringIO() |
|
3179
88dbe6b3d891
merge removal of rcsv
Richard Jones <richard@users.sourceforge.net>
parents:
3169
diff
changeset
|
815 writer = csv.writer(s) |
|
1767
fdaa0b751355
python2.3 CSV support, also missing thankyou in index.txt :)
Richard Jones <richard@users.sourceforge.net>
parents:
1743
diff
changeset
|
816 writer.writerow(props) |
|
4090
6f698aef2ad4
fix missed hole in the CSV editing - could still view items in the generic index editor
Richard Jones <richard@users.sourceforge.net>
parents:
4088
diff
changeset
|
817 check = self._client.db.security.hasPermission |
|
4328
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
818 userid = self._client.userid |
|
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
819 if not check('Web Access', userid): |
|
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
820 return '' |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
821 for nodeid in self._klass.list(): |
|
1041
c28603c9f831
Class help and generic class editing done.
Richard Jones <richard@users.sourceforge.net>
parents:
1030
diff
changeset
|
822 l = [] |
|
c28603c9f831
Class help and generic class editing done.
Richard Jones <richard@users.sourceforge.net>
parents:
1030
diff
changeset
|
823 for name in props: |
|
4090
6f698aef2ad4
fix missed hole in the CSV editing - could still view items in the generic index editor
Richard Jones <richard@users.sourceforge.net>
parents:
4088
diff
changeset
|
824 # check permission to view this property on this item |
|
4328
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
825 if not check('View', userid, itemid=nodeid, |
|
4090
6f698aef2ad4
fix missed hole in the CSV editing - could still view items in the generic index editor
Richard Jones <richard@users.sourceforge.net>
parents:
4088
diff
changeset
|
826 classname=self._klass.classname, property=name): |
|
6f698aef2ad4
fix missed hole in the CSV editing - could still view items in the generic index editor
Richard Jones <richard@users.sourceforge.net>
parents:
4088
diff
changeset
|
827 raise Unauthorised('view', self._klass.classname, |
|
6f698aef2ad4
fix missed hole in the CSV editing - could still view items in the generic index editor
Richard Jones <richard@users.sourceforge.net>
parents:
4088
diff
changeset
|
828 translator=self._client.translator) |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
829 value = self._klass.get(nodeid, name) |
|
1041
c28603c9f831
Class help and generic class editing done.
Richard Jones <richard@users.sourceforge.net>
parents:
1030
diff
changeset
|
830 if value is None: |
|
c28603c9f831
Class help and generic class editing done.
Richard Jones <richard@users.sourceforge.net>
parents:
1030
diff
changeset
|
831 l.append('') |
|
c28603c9f831
Class help and generic class editing done.
Richard Jones <richard@users.sourceforge.net>
parents:
1030
diff
changeset
|
832 elif isinstance(value, type([])): |
|
c28603c9f831
Class help and generic class editing done.
Richard Jones <richard@users.sourceforge.net>
parents:
1030
diff
changeset
|
833 l.append(':'.join(map(str, value))) |
|
c28603c9f831
Class help and generic class editing done.
Richard Jones <richard@users.sourceforge.net>
parents:
1030
diff
changeset
|
834 else: |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
835 l.append(str(self._klass.get(nodeid, name))) |
|
1767
fdaa0b751355
python2.3 CSV support, also missing thankyou in index.txt :)
Richard Jones <richard@users.sourceforge.net>
parents:
1743
diff
changeset
|
836 writer.writerow(l) |
|
1041
c28603c9f831
Class help and generic class editing done.
Richard Jones <richard@users.sourceforge.net>
parents:
1030
diff
changeset
|
837 return s.getvalue() |
|
c28603c9f831
Class help and generic class editing done.
Richard Jones <richard@users.sourceforge.net>
parents:
1030
diff
changeset
|
838 |
|
c28603c9f831
Class help and generic class editing done.
Richard Jones <richard@users.sourceforge.net>
parents:
1030
diff
changeset
|
839 def propnames(self): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
840 """ Return the list of the names of the properties of this class. |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
841 """ |
|
5395
23b8e6067f7c
Python 3 preparation: update calls to dict methods.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5388
diff
changeset
|
842 idlessprops = sorted(self._klass.getprops(protected=0).keys()) |
|
1041
c28603c9f831
Class help and generic class editing done.
Richard Jones <richard@users.sourceforge.net>
parents:
1030
diff
changeset
|
843 return ['id'] + idlessprops |
|
c28603c9f831
Class help and generic class editing done.
Richard Jones <richard@users.sourceforge.net>
parents:
1030
diff
changeset
|
844 |
|
3696
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
845 def filter(self, request=None, filterspec={}, sort=[], group=[]): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
846 """ Return a list of items from this class, filtered and sorted |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
847 by the current requested filterspec/filter/sort/group args |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
848 |
|
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
849 "request" takes precedence over the other three arguments. |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
850 """ |
|
4437
261c9f913ff7
- Add explicit "Search" permissions, see Security Fix below.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4417
diff
changeset
|
851 security = self._db.security |
|
261c9f913ff7
- Add explicit "Search" permissions, see Security Fix below.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4417
diff
changeset
|
852 userid = self._client.userid |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
853 if request is not None: |
|
4437
261c9f913ff7
- Add explicit "Search" permissions, see Security Fix below.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4417
diff
changeset
|
854 # for a request we asume it has already been |
|
261c9f913ff7
- Add explicit "Search" permissions, see Security Fix below.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4417
diff
changeset
|
855 # security-filtered |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
856 filterspec = request.filterspec |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
857 sort = request.sort |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
858 group = request.group |
|
4437
261c9f913ff7
- Add explicit "Search" permissions, see Security Fix below.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4417
diff
changeset
|
859 else: |
|
261c9f913ff7
- Add explicit "Search" permissions, see Security Fix below.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4417
diff
changeset
|
860 cn = self.classname |
|
261c9f913ff7
- Add explicit "Search" permissions, see Security Fix below.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4417
diff
changeset
|
861 filterspec = security.filterFilterspec(userid, cn, filterspec) |
|
261c9f913ff7
- Add explicit "Search" permissions, see Security Fix below.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4417
diff
changeset
|
862 sort = security.filterSortspec(userid, cn, sort) |
|
261c9f913ff7
- Add explicit "Search" permissions, see Security Fix below.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4417
diff
changeset
|
863 group = security.filterSortspec(userid, cn, group) |
|
261c9f913ff7
- Add explicit "Search" permissions, see Security Fix below.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4417
diff
changeset
|
864 |
|
261c9f913ff7
- Add explicit "Search" permissions, see Security Fix below.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4417
diff
changeset
|
865 check = security.hasPermission |
|
4328
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
866 if not check('Web Access', userid): |
|
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
867 return [] |
|
3126
a2889d22db4a
the cgi templating code now checks item-level
Richard Jones <richard@users.sourceforge.net>
parents:
3117
diff
changeset
|
868 |
|
3198
0b7990f54778
fixed broken csv import in roundup.admin module
Richard Jones <richard@users.sourceforge.net>
parents:
3194
diff
changeset
|
869 l = [HTMLItem(self._client, self.classname, id) |
|
3126
a2889d22db4a
the cgi templating code now checks item-level
Richard Jones <richard@users.sourceforge.net>
parents:
3117
diff
changeset
|
870 for id in self._klass.filter(None, filterspec, sort, group) |
|
a2889d22db4a
the cgi templating code now checks item-level
Richard Jones <richard@users.sourceforge.net>
parents:
3117
diff
changeset
|
871 if check('View', userid, self.classname, itemid=id)] |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
872 return l |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
873 |
|
2458
c18a7d4259e3
translate labels hardcoded in HTMLClass and HTMLItem
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2411
diff
changeset
|
874 def classhelp(self, properties=None, label=''"(list)", width='500', |
|
4945
55aef7ab35a8
Increase default height of classhelp windows from 400 to 600.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4928
diff
changeset
|
875 height='600', property='', form='itemSynopsis', |
|
4783
365deccf7347
issue2550807 enhance classhelp method with ability to set html properties
John Rouillard <rouilj@ieee.org>
parents:
4750
diff
changeset
|
876 pagesize=50, inputtype="checkbox", html_kwargs={}, |
|
5336
5a81a097a394
Allow grouping of classhelp items
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5325
diff
changeset
|
877 group='', sort=None, filter=None): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
878 """Pop up a javascript window with class help |
|
2761
10a49678ebf2
allow listing popup to be used in query forms (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
2673
diff
changeset
|
879 |
|
10a49678ebf2
allow listing popup to be used in query forms (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
2673
diff
changeset
|
880 This generates a link to a popup window which displays the |
|
10a49678ebf2
allow listing popup to be used in query forms (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
2673
diff
changeset
|
881 properties indicated by "properties" of the class named by |
|
10a49678ebf2
allow listing popup to be used in query forms (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
2673
diff
changeset
|
882 "classname". The "properties" should be a comma-separated list |
|
10a49678ebf2
allow listing popup to be used in query forms (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
2673
diff
changeset
|
883 (eg. 'id,name,description'). Properties defaults to all the |
|
10a49678ebf2
allow listing popup to be used in query forms (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
2673
diff
changeset
|
884 properties of a class (excluding id, creator, created and |
|
10a49678ebf2
allow listing popup to be used in query forms (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
2673
diff
changeset
|
885 activity). |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
886 |
|
3363
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
887 You may optionally override the label displayed, the width, |
|
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
888 the height, the number of items per page and the field on which |
|
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
889 the list is sorted (defaults to username if in the displayed |
|
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
890 properties). |
|
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
891 |
|
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
892 With the "filter" arg it is possible to specify a filter for |
|
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
893 which items are supposed to be displayed. It has to be of |
|
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
894 the format "<field>=<values>;<field>=<values>;...". |
|
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
895 |
|
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
896 The popup window will be resizable and scrollable. |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
897 |
|
2761
10a49678ebf2
allow listing popup to be used in query forms (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
2673
diff
changeset
|
898 If the "property" arg is given, it's passed through to the |
|
10a49678ebf2
allow listing popup to be used in query forms (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
2673
diff
changeset
|
899 javascript help_window function. |
|
3509
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
900 |
|
3472
522b11d5ba8d
classhelp works with Link properties now [SF#1410290]
Richard Jones <richard@users.sourceforge.net>
parents:
3470
diff
changeset
|
901 You can use inputtype="radio" to display a radio box instead |
|
522b11d5ba8d
classhelp works with Link properties now [SF#1410290]
Richard Jones <richard@users.sourceforge.net>
parents:
3470
diff
changeset
|
902 of the default checkbox (useful for entering Link-properties) |
|
1551
9b9917b7719b
added an additional argument to help_window to allow comms back to form
Richard Jones <richard@users.sourceforge.net>
parents:
1543
diff
changeset
|
903 |
|
2827
43e3a7ac1190
fix HTMLClass.is_view_ok: permission to create new items
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2761
diff
changeset
|
904 If the "form" arg is given, it's passed through to the |
|
2761
10a49678ebf2
allow listing popup to be used in query forms (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
2673
diff
changeset
|
905 javascript help_window function. - it's the name of the form |
|
10a49678ebf2
allow listing popup to be used in query forms (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
2673
diff
changeset
|
906 the "property" belongs to. |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
907 """ |
|
1113
a95428868bf4
Added the missing keyword/topic interface to classic template (blush)
Richard Jones <richard@users.sourceforge.net>
parents:
1104
diff
changeset
|
908 if properties is None: |
|
5395
23b8e6067f7c
Python 3 preparation: update calls to dict methods.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5388
diff
changeset
|
909 properties = sorted(self._klass.getprops(protected=0).keys()) |
|
1113
a95428868bf4
Added the missing keyword/topic interface to classic template (blush)
Richard Jones <richard@users.sourceforge.net>
parents:
1104
diff
changeset
|
910 properties = ','.join(properties) |
|
3363
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
911 if sort is None: |
|
7017
96be63649c92
flake8 fix additional spaces within () and []
John Rouillard <rouilj@ieee.org>
parents:
6856
diff
changeset
|
912 if 'username' in properties.split(','): |
|
3610
1dbaa664be28
sorting of entries in classhelp popup [SF#1449000]
Richard Jones <richard@users.sourceforge.net>
parents:
3594
diff
changeset
|
913 sort = 'username' |
|
3363
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
914 else: |
| 4032 | 915 sort = self._klass.orderprop() |
|
3610
1dbaa664be28
sorting of entries in classhelp popup [SF#1449000]
Richard Jones <richard@users.sourceforge.net>
parents:
3594
diff
changeset
|
916 sort = '&@sort=' + sort |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
917 if group: |
|
5336
5a81a097a394
Allow grouping of classhelp items
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5325
diff
changeset
|
918 group = '&@group=' + group |
|
1551
9b9917b7719b
added an additional argument to help_window to allow comms back to form
Richard Jones <richard@users.sourceforge.net>
parents:
1543
diff
changeset
|
919 if property: |
|
1853
389c4d44c73c
Replace '&' with '&' in the URLs generated by classhelp(), to validate.
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
1824
diff
changeset
|
920 property = '&property=%s'%property |
|
2761
10a49678ebf2
allow listing popup to be used in query forms (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
2673
diff
changeset
|
921 if form: |
|
10a49678ebf2
allow listing popup to be used in query forms (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
2673
diff
changeset
|
922 form = '&form=%s'%form |
|
3472
522b11d5ba8d
classhelp works with Link properties now [SF#1410290]
Richard Jones <richard@users.sourceforge.net>
parents:
3470
diff
changeset
|
923 if inputtype: |
|
522b11d5ba8d
classhelp works with Link properties now [SF#1410290]
Richard Jones <richard@users.sourceforge.net>
parents:
3470
diff
changeset
|
924 type= '&type=%s'%inputtype |
|
3363
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
925 if filter: |
|
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
926 filterprops = filter.split(';') |
|
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
927 filtervalues = [] |
|
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
928 names = [] |
|
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
929 for x in filterprops: |
|
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
930 (name, values) = x.split('=') |
|
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
931 names.append(name) |
|
5402
88dbacd11cd1
Python 3 preparation: update urllib / urllib2 / urlparse imports.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5399
diff
changeset
|
932 filtervalues.append('&%s=%s' % (name, urllib_.quote(values))) |
|
3363
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
933 filter = '&@filter=%s%s' % (','.join(names), ''.join(filtervalues)) |
|
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
934 else: |
|
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
935 filter = '' |
|
3169
d8d1ebd80930
fallback for (list) popups if javascript disabled (patch [SF#1101626])
Richard Jones <richard@users.sourceforge.net>
parents:
3164
diff
changeset
|
936 help_url = "%s?@startwith=0&@template=help&"\ |
|
5336
5a81a097a394
Allow grouping of classhelp items
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5325
diff
changeset
|
937 "properties=%s%s%s%s%s%s&@pagesize=%s%s" % \ |
|
3582
026adc5f1e13
fix "Adding a new constrained field to the classic schema" example in docs
Richard Jones <richard@users.sourceforge.net>
parents:
3573
diff
changeset
|
938 (self.classname, properties, property, form, type, |
|
5336
5a81a097a394
Allow grouping of classhelp items
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5325
diff
changeset
|
939 group, sort, pagesize, filter) |
|
3169
d8d1ebd80930
fallback for (list) popups if javascript disabled (patch [SF#1101626])
Richard Jones <richard@users.sourceforge.net>
parents:
3164
diff
changeset
|
940 onclick = "javascript:help_window('%s', '%s', '%s');return false;" % \ |
|
d8d1ebd80930
fallback for (list) popups if javascript disabled (patch [SF#1101626])
Richard Jones <richard@users.sourceforge.net>
parents:
3164
diff
changeset
|
941 (help_url, width, height) |
|
6215
af372b9372f6
Add data attributes to classhelp to allow use with CSP.
John Rouillard <rouilj@ieee.org>
parents:
6150
diff
changeset
|
942 return '<a class="classhelp" data-helpurl="%s" data-width="%s" data-height="%s" href="%s" onclick="%s" %s>%s</a>' % \ |
|
af372b9372f6
Add data attributes to classhelp to allow use with CSP.
John Rouillard <rouilj@ieee.org>
parents:
6150
diff
changeset
|
943 (help_url, width, height, |
|
af372b9372f6
Add data attributes to classhelp to allow use with CSP.
John Rouillard <rouilj@ieee.org>
parents:
6150
diff
changeset
|
944 help_url, onclick, self.cgi_escape_attrs(**html_kwargs), |
|
4783
365deccf7347
issue2550807 enhance classhelp method with ability to set html properties
John Rouillard <rouilj@ieee.org>
parents:
4750
diff
changeset
|
945 self._(label)) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
946 |
|
5991
b0940ad50f43
issue2551075 Update jinja template to bootstrap 4.
John Rouillard <rouilj@ieee.org>
parents:
5988
diff
changeset
|
947 def submit(self, label=''"Submit New Entry", action="new", html_kwargs={}): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
948 """ Generate a submit button (and action hidden element) |
|
3040
14322134dcef
fix permissions checks in cgi templating [SF#1082755]
Richard Jones <richard@users.sourceforge.net>
parents:
3006
diff
changeset
|
949 |
|
5991
b0940ad50f43
issue2551075 Update jinja template to bootstrap 4.
John Rouillard <rouilj@ieee.org>
parents:
5988
diff
changeset
|
950 "html_kwargs" specified additional html args for the |
|
b0940ad50f43
issue2551075 Update jinja template to bootstrap 4.
John Rouillard <rouilj@ieee.org>
parents:
5988
diff
changeset
|
951 generated html <select> |
|
b0940ad50f43
issue2551075 Update jinja template to bootstrap 4.
John Rouillard <rouilj@ieee.org>
parents:
5988
diff
changeset
|
952 |
|
3040
14322134dcef
fix permissions checks in cgi templating [SF#1082755]
Richard Jones <richard@users.sourceforge.net>
parents:
3006
diff
changeset
|
953 Generate nothing if we're not editable. |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
954 """ |
|
3040
14322134dcef
fix permissions checks in cgi templating [SF#1082755]
Richard Jones <richard@users.sourceforge.net>
parents:
3006
diff
changeset
|
955 if not self.is_edit_ok(): |
|
14322134dcef
fix permissions checks in cgi templating [SF#1082755]
Richard Jones <richard@users.sourceforge.net>
parents:
3006
diff
changeset
|
956 return '' |
|
14322134dcef
fix permissions checks in cgi templating [SF#1082755]
Richard Jones <richard@users.sourceforge.net>
parents:
3006
diff
changeset
|
957 |
|
5907
fe96015445e9
Reorder html entities generated by submit button
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5903
diff
changeset
|
958 return \ |
|
fe96015445e9
Reorder html entities generated by submit button
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5903
diff
changeset
|
959 self.input(type="submit", name="submit_button", |
|
5991
b0940ad50f43
issue2551075 Update jinja template to bootstrap 4.
John Rouillard <rouilj@ieee.org>
parents:
5988
diff
changeset
|
960 value=self._(label), **html_kwargs) + \ |
|
5201
a9ace22e0a2f
issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents:
5193
diff
changeset
|
961 '\n' + \ |
|
5907
fe96015445e9
Reorder html entities generated by submit button
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5903
diff
changeset
|
962 self.input(type="hidden", name="@csrf", |
|
fe96015445e9
Reorder html entities generated by submit button
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5903
diff
changeset
|
963 value=anti_csrf_nonce(self._client)) + \ |
|
2983
9614a101b68f
Stuff from the train ride this morning:
Richard Jones <richard@users.sourceforge.net>
parents:
2962
diff
changeset
|
964 '\n' + \ |
|
5907
fe96015445e9
Reorder html entities generated by submit button
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5903
diff
changeset
|
965 self.input(type="hidden", name="@action", value=action) |
|
999
8d54c0f3198e
Fixed history and its nihilism. Added convenience method for submit buttons
Richard Jones <richard@users.sourceforge.net>
parents:
985
diff
changeset
|
966 |
|
6428
32a04dc87b30
Make HTMLClass::history signature compatible to _HTMLItem::history
John Rouillard <rouilj@ieee.org>
parents:
6422
diff
changeset
|
967 def history(self, **args): |
|
3117
460eb0209a9e
Permissions improvements.
Richard Jones <richard@users.sourceforge.net>
parents:
3104
diff
changeset
|
968 if not self.is_view_ok(): |
|
3164
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
969 return self._('[hidden]') |
|
2466
7b248ea0a2e5
add translation to Unauthorised exception; mark missed text for translation
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2458
diff
changeset
|
970 return self._('New node - no history') |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
971 |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
972 def renderWith(self, name, **kwargs): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
973 """ Render this class with the given template. |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
974 """ |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
975 # create a new request and override the specified args |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
976 req = HTMLRequest(self._client) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
977 req.classname = self.classname |
|
1016
d6c13142e7b9
Keep a cache of compiled PageTemplates.
Richard Jones <richard@users.sourceforge.net>
parents:
1008
diff
changeset
|
978 req.update(kwargs) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
979 |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
980 # new template, using the specified classname and request |
|
4740
fe9568a6cbd6
Untangle template selection logic from template loading functionality.
anatoly techtonik <techtonik@gmail.com>
parents:
4737
diff
changeset
|
981 # [ ] this code is too similar to client.renderContext() |
|
fe9568a6cbd6
Untangle template selection logic from template loading functionality.
anatoly techtonik <techtonik@gmail.com>
parents:
4737
diff
changeset
|
982 tplname = self._client.selectTemplate(self.classname, name) |
|
fe9568a6cbd6
Untangle template selection logic from template loading functionality.
anatoly techtonik <techtonik@gmail.com>
parents:
4737
diff
changeset
|
983 pt = self._client.instance.templates.load(tplname) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
984 |
|
1097
98f3d41f41d9
query "editing" now working, minus filling the form in with the query params
Richard Jones <richard@users.sourceforge.net>
parents:
1096
diff
changeset
|
985 # use our fabricated request |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
986 args = { |
|
4880
ca692423e401
Different approach to fix XSS in issue2550817
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4879
diff
changeset
|
987 'ok_message': self._client._ok_message, |
|
ca692423e401
Different approach to fix XSS in issue2550817
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4879
diff
changeset
|
988 'error_message': self._client._error_message |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
989 } |
|
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
990 return pt.render(self._client, self.classname, req, **args) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
991 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
992 |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
993 class _HTMLItem(HTMLInputMixin, HTMLPermissions): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
994 """ Accesses through an *item* |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
995 """ |
|
1447
6118d4498db3
added "foo@" prefix to all but "context" form variable names
Richard Jones <richard@users.sourceforge.net>
parents:
1441
diff
changeset
|
996 def __init__(self, client, classname, nodeid, anonymous=0): |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
997 self._client = client |
|
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
998 self._db = client.db |
|
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
999 self._classname = classname |
|
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
1000 self._nodeid = nodeid |
|
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
1001 self._klass = self._db.getclass(classname) |
|
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
1002 self._props = self._klass.getprops() |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1003 |
|
1447
6118d4498db3
added "foo@" prefix to all but "context" form variable names
Richard Jones <richard@users.sourceforge.net>
parents:
1441
diff
changeset
|
1004 # do we prefix the form items with the item's identification? |
|
6118d4498db3
added "foo@" prefix to all but "context" form variable names
Richard Jones <richard@users.sourceforge.net>
parents:
1441
diff
changeset
|
1005 self._anonymous = anonymous |
|
6118d4498db3
added "foo@" prefix to all but "context" form variable names
Richard Jones <richard@users.sourceforge.net>
parents:
1441
diff
changeset
|
1006 |
|
1956
1e2cccf6b53b
give access to the input() method all over the place
Richard Jones <richard@users.sourceforge.net>
parents:
1952
diff
changeset
|
1007 HTMLInputMixin.__init__(self) |
|
1e2cccf6b53b
give access to the input() method all over the place
Richard Jones <richard@users.sourceforge.net>
parents:
1952
diff
changeset
|
1008 |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
1009 def is_edit_ok(self): |
|
4088
34434785f308
Plug a number of security holes:
Richard Jones <richard@users.sourceforge.net>
parents:
4058
diff
changeset
|
1010 """ Is the user allowed to Edit this item? |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1011 """ |
|
4328
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
1012 perm = self._db.security.hasPermission |
|
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
1013 return perm('Web Access', self._client.userid) and perm('Edit', |
|
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
1014 self._client.userid, self._classname, itemid=self._nodeid) |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
1015 |
|
4088
34434785f308
Plug a number of security holes:
Richard Jones <richard@users.sourceforge.net>
parents:
4058
diff
changeset
|
1016 def is_retire_ok(self): |
|
34434785f308
Plug a number of security holes:
Richard Jones <richard@users.sourceforge.net>
parents:
4058
diff
changeset
|
1017 """ Is the user allowed to Reture this item? |
|
34434785f308
Plug a number of security holes:
Richard Jones <richard@users.sourceforge.net>
parents:
4058
diff
changeset
|
1018 """ |
|
4328
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
1019 perm = self._db.security.hasPermission |
|
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
1020 return perm('Web Access', self._client.userid) and perm('Retire', |
|
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
1021 self._client.userid, self._classname, itemid=self._nodeid) |
|
4088
34434785f308
Plug a number of security holes:
Richard Jones <richard@users.sourceforge.net>
parents:
4058
diff
changeset
|
1022 |
|
6150
edbd4bba728a
Add 'is_restore_ok' method
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6125
diff
changeset
|
1023 def is_restore_ok(self): |
|
edbd4bba728a
Add 'is_restore_ok' method
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6125
diff
changeset
|
1024 """ Is the user allowed to restore this item? |
|
edbd4bba728a
Add 'is_restore_ok' method
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6125
diff
changeset
|
1025 """ |
|
edbd4bba728a
Add 'is_restore_ok' method
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6125
diff
changeset
|
1026 perm = self._db.security.hasPermission |
|
edbd4bba728a
Add 'is_restore_ok' method
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6125
diff
changeset
|
1027 return perm('Web Access', self._client.userid) and perm('Restore', |
|
edbd4bba728a
Add 'is_restore_ok' method
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6125
diff
changeset
|
1028 self._client.userid, self._classname, itemid=self._nodeid) |
|
edbd4bba728a
Add 'is_restore_ok' method
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6125
diff
changeset
|
1029 |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
1030 def is_view_ok(self): |
|
4088
34434785f308
Plug a number of security holes:
Richard Jones <richard@users.sourceforge.net>
parents:
4058
diff
changeset
|
1031 """ Is the user allowed to View this item? |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1032 """ |
|
4328
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
1033 perm = self._db.security.hasPermission |
|
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
1034 if perm('Web Access', self._client.userid) and perm('View', |
|
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
1035 self._client.userid, self._classname, itemid=self._nodeid): |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
1036 return 1 |
|
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
1037 return self.is_edit_ok() |
|
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
1038 |
|
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
1039 def is_only_view_ok(self): |
|
4088
34434785f308
Plug a number of security holes:
Richard Jones <richard@users.sourceforge.net>
parents:
4058
diff
changeset
|
1040 """ Is the user only allowed to View (ie. not Edit) this item? |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1041 """ |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
1042 return self.is_view_ok() and not self.is_edit_ok() |
|
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
1043 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1044 def __repr__(self): |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
1045 return '<HTMLItem(0x%x) %s %s>'%(id(self), self._classname, |
|
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
1046 self._nodeid) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1047 |
| 1002 | 1048 def __getitem__(self, item): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1049 """ return an HTMLProperty instance |
|
3696
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
1050 this now can handle transitive lookups where item is of the |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
1051 form x.y.z |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1052 """ |
| 1002 | 1053 if item == 'id': |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
1054 return self._nodeid |
|
1073
cf30c6cdca02
More documentation.
Richard Jones <richard@users.sourceforge.net>
parents:
1068
diff
changeset
|
1055 |
|
3696
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
1056 items = item.split('.', 1) |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
1057 has_rest = len(items) > 1 |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
1058 |
|
1073
cf30c6cdca02
More documentation.
Richard Jones <richard@users.sourceforge.net>
parents:
1068
diff
changeset
|
1059 # get the property |
|
3696
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
1060 prop = self._props[items[0]] |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
1061 |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
1062 if has_rest and not isinstance(prop, (hyperdb.Link, hyperdb.Multilink)): |
|
5378
35ea9b1efc14
Python 3 preparation: "raise" syntax.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5356
diff
changeset
|
1063 raise KeyError(item) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1064 |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1065 # get the value, handling missing values |
|
1447
6118d4498db3
added "foo@" prefix to all but "context" form variable names
Richard Jones <richard@users.sourceforge.net>
parents:
1441
diff
changeset
|
1066 value = None |
|
6398
26e5c42f148c
issue2551078 - Fix traceback caused when putting two id's into a Link html field.
John Rouillard <rouilj@ieee.org>
parents:
6377
diff
changeset
|
1067 try: |
|
26e5c42f148c
issue2551078 - Fix traceback caused when putting two id's into a Link html field.
John Rouillard <rouilj@ieee.org>
parents:
6377
diff
changeset
|
1068 if int(self._nodeid) > 0: |
|
26e5c42f148c
issue2551078 - Fix traceback caused when putting two id's into a Link html field.
John Rouillard <rouilj@ieee.org>
parents:
6377
diff
changeset
|
1069 value = self._klass.get(self._nodeid, items[0], None) |
|
26e5c42f148c
issue2551078 - Fix traceback caused when putting two id's into a Link html field.
John Rouillard <rouilj@ieee.org>
parents:
6377
diff
changeset
|
1070 except ValueError: |
|
26e5c42f148c
issue2551078 - Fix traceback caused when putting two id's into a Link html field.
John Rouillard <rouilj@ieee.org>
parents:
6377
diff
changeset
|
1071 value = self._nodeid |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1072 if value is None: |
|
3696
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
1073 if isinstance(prop, hyperdb.Multilink): |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1074 value = [] |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1075 |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1076 # look up the correct HTMLProperty class |
|
3696
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
1077 htmlprop = None |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1078 for klass, htmlklass in propclasses: |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1079 if isinstance(prop, klass): |
|
3696
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
1080 htmlprop = htmlklass(self._client, self._classname, |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
1081 self._nodeid, prop, items[0], value, self._anonymous) |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
1082 if htmlprop is not None: |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
1083 if has_rest: |
|
3699
976191d749fb
grouping by ID and grouping by transitive multilinks didn't work correctly.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3698
diff
changeset
|
1084 if isinstance(htmlprop, MultilinkHTMLProperty): |
|
976191d749fb
grouping by ID and grouping by transitive multilinks didn't work correctly.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3698
diff
changeset
|
1085 return [h[items[1]] for h in htmlprop] |
|
3696
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
1086 return htmlprop[items[1]] |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
1087 return htmlprop |
| 1002 | 1088 |
|
5378
35ea9b1efc14
Python 3 preparation: "raise" syntax.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5356
diff
changeset
|
1089 raise KeyError(item) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1090 |
| 1002 | 1091 def __getattr__(self, attr): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1092 """ convenience access to properties """ |
| 1002 | 1093 try: |
| 1094 return self[attr] | |
| 1095 except KeyError: | |
|
5378
35ea9b1efc14
Python 3 preparation: "raise" syntax.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5356
diff
changeset
|
1096 raise AttributeError(attr) |
|
1743
f166cd4fd392
add action attribute to issue.item form action tag
Richard Jones <richard@users.sourceforge.net>
parents:
1739
diff
changeset
|
1097 |
|
f166cd4fd392
add action attribute to issue.item form action tag
Richard Jones <richard@users.sourceforge.net>
parents:
1739
diff
changeset
|
1098 def designator(self): |
|
2014
366d3bbce982
Simple version of collision detection...
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
2010
diff
changeset
|
1099 """Return this item's designator (classname + id).""" |
|
1743
f166cd4fd392
add action attribute to issue.item form action tag
Richard Jones <richard@users.sourceforge.net>
parents:
1739
diff
changeset
|
1100 return '%s%s'%(self._classname, self._nodeid) |
|
2136
ee3cf6a44f29
queries on a per-user basis, and public queries [SF#891798] :)
Richard Jones <richard@users.sourceforge.net>
parents:
2118
diff
changeset
|
1101 |
|
ee3cf6a44f29
queries on a per-user basis, and public queries [SF#891798] :)
Richard Jones <richard@users.sourceforge.net>
parents:
2118
diff
changeset
|
1102 def is_retired(self): |
|
ee3cf6a44f29
queries on a per-user basis, and public queries [SF#891798] :)
Richard Jones <richard@users.sourceforge.net>
parents:
2118
diff
changeset
|
1103 """Is this item retired?""" |
|
ee3cf6a44f29
queries on a per-user basis, and public queries [SF#891798] :)
Richard Jones <richard@users.sourceforge.net>
parents:
2118
diff
changeset
|
1104 return self._klass.is_retired(self._nodeid) |
|
2327
36ae1b14aaab
remove excessive spaces in the translatable strings;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2324
diff
changeset
|
1105 |
|
5991
b0940ad50f43
issue2551075 Update jinja template to bootstrap 4.
John Rouillard <rouilj@ieee.org>
parents:
5988
diff
changeset
|
1106 def submit(self, label=''"Submit Changes", action="edit", html_kwargs={}): |
|
2014
366d3bbce982
Simple version of collision detection...
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
2010
diff
changeset
|
1107 """Generate a submit button. |
|
366d3bbce982
Simple version of collision detection...
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
2010
diff
changeset
|
1108 |
|
5991
b0940ad50f43
issue2551075 Update jinja template to bootstrap 4.
John Rouillard <rouilj@ieee.org>
parents:
5988
diff
changeset
|
1109 "html_kwargs" specified additional html args for the |
|
b0940ad50f43
issue2551075 Update jinja template to bootstrap 4.
John Rouillard <rouilj@ieee.org>
parents:
5988
diff
changeset
|
1110 generated html <select> |
|
b0940ad50f43
issue2551075 Update jinja template to bootstrap 4.
John Rouillard <rouilj@ieee.org>
parents:
5988
diff
changeset
|
1111 |
|
2014
366d3bbce982
Simple version of collision detection...
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
2010
diff
changeset
|
1112 Also sneak in the lastactivity and action hidden elements. |
|
366d3bbce982
Simple version of collision detection...
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
2010
diff
changeset
|
1113 """ |
|
5907
fe96015445e9
Reorder html entities generated by submit button
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5903
diff
changeset
|
1114 return \ |
|
fe96015445e9
Reorder html entities generated by submit button
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5903
diff
changeset
|
1115 self.input(type="submit", name="submit_button", |
|
5991
b0940ad50f43
issue2551075 Update jinja template to bootstrap 4.
John Rouillard <rouilj@ieee.org>
parents:
5988
diff
changeset
|
1116 value=self._(label), **html_kwargs) + \ |
|
5907
fe96015445e9
Reorder html entities generated by submit button
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5903
diff
changeset
|
1117 '\n' + \ |
|
fe96015445e9
Reorder html entities generated by submit button
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5903
diff
changeset
|
1118 self.input(type="hidden", name="@lastactivity", |
|
fe96015445e9
Reorder html entities generated by submit button
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5903
diff
changeset
|
1119 value=self.activity.local(0)) + \ |
|
5201
a9ace22e0a2f
issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents:
5193
diff
changeset
|
1120 '\n' + \ |
|
a9ace22e0a2f
issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents:
5193
diff
changeset
|
1121 self.input(type="hidden", name="@csrf", |
|
5488
52cb53eedf77
reworked random number use
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5485
diff
changeset
|
1122 value=anti_csrf_nonce(self._client)) + \ |
|
5201
a9ace22e0a2f
issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents:
5193
diff
changeset
|
1123 '\n' + \ |
|
5907
fe96015445e9
Reorder html entities generated by submit button
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5903
diff
changeset
|
1124 self.input(type="hidden", name="@action", value=action) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1125 |
|
1103
db787cef1385
handled some XXXs
Richard Jones <richard@users.sourceforge.net>
parents:
1099
diff
changeset
|
1126 def journal(self, direction='descending'): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1127 """ Return a list of HTMLJournalEntry instances. |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1128 """ |
|
1103
db787cef1385
handled some XXXs
Richard Jones <richard@users.sourceforge.net>
parents:
1099
diff
changeset
|
1129 # XXX do this |
|
db787cef1385
handled some XXXs
Richard Jones <richard@users.sourceforge.net>
parents:
1099
diff
changeset
|
1130 return [] |
|
db787cef1385
handled some XXXs
Richard Jones <richard@users.sourceforge.net>
parents:
1099
diff
changeset
|
1131 |
| 5809 | 1132 def history(self, direction='descending', dre=re.compile(r'^\d+$'), |
|
7017
96be63649c92
flake8 fix additional spaces within () and []
John Rouillard <rouilj@ieee.org>
parents:
6856
diff
changeset
|
1133 limit=None, showall=False): |
|
5112
8901cc4ef0e0
- issue1714899: Feature Request: Optional Change Note. Added a new
John Rouillard <rouilj@ieee.org>
parents:
5095
diff
changeset
|
1134 """Create an html view of the journal for the item. |
|
8901cc4ef0e0
- issue1714899: Feature Request: Optional Change Note. Added a new
John Rouillard <rouilj@ieee.org>
parents:
5095
diff
changeset
|
1135 |
|
8901cc4ef0e0
- issue1714899: Feature Request: Optional Change Note. Added a new
John Rouillard <rouilj@ieee.org>
parents:
5095
diff
changeset
|
1136 Display property changes for all properties that does not have quiet set. |
|
8901cc4ef0e0
- issue1714899: Feature Request: Optional Change Note. Added a new
John Rouillard <rouilj@ieee.org>
parents:
5095
diff
changeset
|
1137 If showall=True then all properties regardless of quiet setting will be |
|
8901cc4ef0e0
- issue1714899: Feature Request: Optional Change Note. Added a new
John Rouillard <rouilj@ieee.org>
parents:
5095
diff
changeset
|
1138 shown. |
|
8901cc4ef0e0
- issue1714899: Feature Request: Optional Change Note. Added a new
John Rouillard <rouilj@ieee.org>
parents:
5095
diff
changeset
|
1139 """ |
|
3117
460eb0209a9e
Permissions improvements.
Richard Jones <richard@users.sourceforge.net>
parents:
3104
diff
changeset
|
1140 if not self.is_view_ok(): |
|
3164
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
1141 return self._('[hidden]') |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
1142 |
|
6422
91ae685405ba
- issue2550964 - History can (temporarily) show incorrect value...
John Rouillard <rouilj@ieee.org>
parents:
6421
diff
changeset
|
1143 # history should only use database values not current |
|
91ae685405ba
- issue2550964 - History can (temporarily) show incorrect value...
John Rouillard <rouilj@ieee.org>
parents:
6421
diff
changeset
|
1144 # form values. Disable form_wins for the body of the |
|
91ae685405ba
- issue2550964 - History can (temporarily) show incorrect value...
John Rouillard <rouilj@ieee.org>
parents:
6421
diff
changeset
|
1145 # function. Reset it to original value on return. |
|
91ae685405ba
- issue2550964 - History can (temporarily) show incorrect value...
John Rouillard <rouilj@ieee.org>
parents:
6421
diff
changeset
|
1146 orig_form_wins = self._client.form_wins |
|
91ae685405ba
- issue2550964 - History can (temporarily) show incorrect value...
John Rouillard <rouilj@ieee.org>
parents:
6421
diff
changeset
|
1147 self._client.form_wins = False |
|
7019
e1528860e591
flake8 remove space from blank lines W293
John Rouillard <rouilj@ieee.org>
parents:
7018
diff
changeset
|
1148 |
|
2614
c64ea31a569b
merge from HEAD, with some additional code re-arranging
Richard Jones <richard@users.sourceforge.net>
parents:
2591
diff
changeset
|
1149 # get the journal, sort and reverse |
|
5232
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5222
diff
changeset
|
1150 history = self._klass.history(self._nodeid, skipquiet=(not showall)) |
|
5448
754be676ccc8
set key for history sort to avoid sorting history args (could be a dict)
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5440
diff
changeset
|
1151 history.sort(key=lambda a: a[:3]) |
|
2614
c64ea31a569b
merge from HEAD, with some additional code re-arranging
Richard Jones <richard@users.sourceforge.net>
parents:
2591
diff
changeset
|
1152 history.reverse() |
|
c64ea31a569b
merge from HEAD, with some additional code re-arranging
Richard Jones <richard@users.sourceforge.net>
parents:
2591
diff
changeset
|
1153 |
|
4233
01ef28bffcbd
don't show entire history by default
Richard Jones <richard@users.sourceforge.net>
parents:
4146
diff
changeset
|
1154 # restrict the volume |
|
01ef28bffcbd
don't show entire history by default
Richard Jones <richard@users.sourceforge.net>
parents:
4146
diff
changeset
|
1155 if limit: |
|
01ef28bffcbd
don't show entire history by default
Richard Jones <richard@users.sourceforge.net>
parents:
4146
diff
changeset
|
1156 history = history[:limit] |
|
01ef28bffcbd
don't show entire history by default
Richard Jones <richard@users.sourceforge.net>
parents:
4146
diff
changeset
|
1157 |
|
1402
27586da5557c
Added users' timezone support
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1394
diff
changeset
|
1158 timezone = self._db.getUserTimezone() |
|
2614
c64ea31a569b
merge from HEAD, with some additional code re-arranging
Richard Jones <richard@users.sourceforge.net>
parents:
2591
diff
changeset
|
1159 l = [] |
|
5492
6b0c542642be
blobfiles now always stores/returns bytes
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5488
diff
changeset
|
1160 current = {} |
|
2614
c64ea31a569b
merge from HEAD, with some additional code re-arranging
Richard Jones <richard@users.sourceforge.net>
parents:
2591
diff
changeset
|
1161 comments = {} |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1162 for id, evt_date, user, action, args in history: |
|
1402
27586da5557c
Added users' timezone support
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1394
diff
changeset
|
1163 date_s = str(evt_date.local(timezone)).replace("."," ") |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1164 arg_s = '' |
|
7024
bac315283a55
flake8: E721 do not compare types, use 'isinstance()'
John Rouillard <rouilj@ieee.org>
parents:
7023
diff
changeset
|
1165 if action in ['link', 'unlink'] and isinstance(args, tuple): |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1166 if len(args) == 3: |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1167 linkcl, linkid, key = args |
|
5684
97e2125e064c
When we generate links from URL's in messages, we add rel="nofollow"
John Rouillard <rouilj@ieee.org>
parents:
5548
diff
changeset
|
1168 arg_s += '<a rel="nofollow noopener" href="%s%s">%s%s %s</a>'%(linkcl, linkid, |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1169 linkcl, linkid, key) |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1170 else: |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1171 arg_s = str(args) |
|
7024
bac315283a55
flake8: E721 do not compare types, use 'isinstance()'
John Rouillard <rouilj@ieee.org>
parents:
7023
diff
changeset
|
1172 elif isinstance(args, dict): |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1173 cell = [] |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1174 for k in args.keys(): |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1175 # try to get the relevant property and treat it |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1176 # specially |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1177 try: |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
1178 prop = self._props[k] |
|
999
8d54c0f3198e
Fixed history and its nihilism. Added convenience method for submit buttons
Richard Jones <richard@users.sourceforge.net>
parents:
985
diff
changeset
|
1179 except KeyError: |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1180 prop = None |
|
1773
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1181 if prop is None: |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1182 # property no longer exists |
|
2396
39cdddd313ca
HTMLInputMixin provides translation interface for all its hiers...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2390
diff
changeset
|
1183 comments['no_exist'] = self._( |
|
2327
36ae1b14aaab
remove excessive spaces in the translatable strings;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2324
diff
changeset
|
1184 "<em>The indicated property no longer exists</em>") |
|
2396
39cdddd313ca
HTMLInputMixin provides translation interface for all its hiers...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2390
diff
changeset
|
1185 cell.append(self._('<em>%s: %s</em>\n') |
|
2547
9b9c8fb52732
translate action names and property names in the history list
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2538
diff
changeset
|
1186 % (self._(k), str(args[k]))) |
|
1773
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1187 continue |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1188 |
|
5492
6b0c542642be
blobfiles now always stores/returns bytes
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5488
diff
changeset
|
1189 # load the current state for the property (if we |
|
6b0c542642be
blobfiles now always stores/returns bytes
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5488
diff
changeset
|
1190 # haven't already) |
|
6b0c542642be
blobfiles now always stores/returns bytes
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5488
diff
changeset
|
1191 if k not in current: |
|
6b0c542642be
blobfiles now always stores/returns bytes
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5488
diff
changeset
|
1192 val = self[k] |
|
6b0c542642be
blobfiles now always stores/returns bytes
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5488
diff
changeset
|
1193 if not isinstance(val, HTMLProperty): |
|
6b0c542642be
blobfiles now always stores/returns bytes
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5488
diff
changeset
|
1194 current[k] = None |
|
6b0c542642be
blobfiles now always stores/returns bytes
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5488
diff
changeset
|
1195 else: |
|
6b0c542642be
blobfiles now always stores/returns bytes
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5488
diff
changeset
|
1196 current[k] = val.plain(escape=1) |
|
6b0c542642be
blobfiles now always stores/returns bytes
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5488
diff
changeset
|
1197 # make link if hrefable |
|
6b0c542642be
blobfiles now always stores/returns bytes
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5488
diff
changeset
|
1198 if (isinstance(prop, hyperdb.Link)): |
|
6b0c542642be
blobfiles now always stores/returns bytes
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5488
diff
changeset
|
1199 classname = prop.classname |
|
6b0c542642be
blobfiles now always stores/returns bytes
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5488
diff
changeset
|
1200 try: |
|
6b0c542642be
blobfiles now always stores/returns bytes
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5488
diff
changeset
|
1201 template = self._client.selectTemplate(classname, 'item') |
|
6b0c542642be
blobfiles now always stores/returns bytes
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5488
diff
changeset
|
1202 if template.startswith('_generic.'): |
|
6b0c542642be
blobfiles now always stores/returns bytes
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5488
diff
changeset
|
1203 raise NoTemplate('not really...') |
|
6b0c542642be
blobfiles now always stores/returns bytes
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5488
diff
changeset
|
1204 except NoTemplate: |
|
6b0c542642be
blobfiles now always stores/returns bytes
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5488
diff
changeset
|
1205 pass |
|
6b0c542642be
blobfiles now always stores/returns bytes
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5488
diff
changeset
|
1206 else: |
|
6b0c542642be
blobfiles now always stores/returns bytes
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5488
diff
changeset
|
1207 linkid = self._klass.get(self._nodeid, k, None) |
|
5684
97e2125e064c
When we generate links from URL's in messages, we add rel="nofollow"
John Rouillard <rouilj@ieee.org>
parents:
5548
diff
changeset
|
1208 current[k] = '<a rel="nofollow noopener" href="%s%s">%s</a>'%( |
|
5492
6b0c542642be
blobfiles now always stores/returns bytes
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5488
diff
changeset
|
1209 classname, linkid, current[k]) |
|
6b0c542642be
blobfiles now always stores/returns bytes
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5488
diff
changeset
|
1210 |
|
1773
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1211 if args[k] and (isinstance(prop, hyperdb.Multilink) or |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1212 isinstance(prop, hyperdb.Link)): |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1213 # figure what the link class is |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1214 classname = prop.classname |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1215 try: |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1216 linkcl = self._db.getclass(classname) |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1217 except KeyError: |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1218 labelprop = None |
|
2396
39cdddd313ca
HTMLInputMixin provides translation interface for all its hiers...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2390
diff
changeset
|
1219 comments[classname] = self._( |
|
2327
36ae1b14aaab
remove excessive spaces in the translatable strings;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2324
diff
changeset
|
1220 "The linked class %(classname)s no longer exists" |
|
36ae1b14aaab
remove excessive spaces in the translatable strings;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2324
diff
changeset
|
1221 ) % locals() |
|
1773
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1222 labelprop = linkcl.labelprop(1) |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1223 try: |
|
4740
fe9568a6cbd6
Untangle template selection logic from template loading functionality.
anatoly techtonik <techtonik@gmail.com>
parents:
4737
diff
changeset
|
1224 template = self._client.selectTemplate(classname, |
|
fe9568a6cbd6
Untangle template selection logic from template loading functionality.
anatoly techtonik <techtonik@gmail.com>
parents:
4737
diff
changeset
|
1225 'item') |
|
fe9568a6cbd6
Untangle template selection logic from template loading functionality.
anatoly techtonik <techtonik@gmail.com>
parents:
4737
diff
changeset
|
1226 if template.startswith('_generic.'): |
|
5378
35ea9b1efc14
Python 3 preparation: "raise" syntax.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5356
diff
changeset
|
1227 raise NoTemplate('not really...') |
|
1773
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1228 hrefable = 1 |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1229 except NoTemplate: |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1230 hrefable = 0 |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1231 |
|
5232
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5222
diff
changeset
|
1232 if isinstance(prop, hyperdb.Multilink) and args[k]: |
|
1773
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1233 ml = [] |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1234 for linkid in args[k]: |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1235 if isinstance(linkid, type(())): |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1236 sublabel = linkid[0] + ' ' |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1237 linkids = linkid[1] |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1238 else: |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1239 sublabel = '' |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1240 linkids = [linkid] |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1241 subml = [] |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1242 for linkid in linkids: |
|
5325
7c7f3faa5e10
Check for None linkid in history
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5319
diff
changeset
|
1243 # We're seeing things like |
|
7c7f3faa5e10
Check for None linkid in history
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5319
diff
changeset
|
1244 # {'nosy':['38', '113', None, '82']} in the wild |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
1245 if linkid is None: |
|
5325
7c7f3faa5e10
Check for None linkid in history
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5319
diff
changeset
|
1246 continue |
|
1773
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1247 label = classname + linkid |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1248 # if we have a label property, try to use it |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1249 # TODO: test for node existence even when |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1250 # there's no labelprop! |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1251 try: |
|
1773
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1252 if labelprop is not None and \ |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1253 labelprop != 'id': |
|
6620
b7093aa16895
issue2551196 - Unset labelprop of a Multilink can lead to Python error when using context/history
John Rouillard <rouilj@ieee.org>
parents:
6593
diff
changeset
|
1254 label = linkcl.get(linkid, labelprop, |
|
b7093aa16895
issue2551196 - Unset labelprop of a Multilink can lead to Python error when using context/history
John Rouillard <rouilj@ieee.org>
parents:
6593
diff
changeset
|
1255 default=self._( |
|
b7093aa16895
issue2551196 - Unset labelprop of a Multilink can lead to Python error when using context/history
John Rouillard <rouilj@ieee.org>
parents:
6593
diff
changeset
|
1256 "[label is missing]")) |
|
5800
1a835db41674
Call cgi.escape only on python 2. Replace with html.escapeif it can be
John Rouillard <rouilj@ieee.org>
parents:
5684
diff
changeset
|
1257 label = html_escape(label) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1258 except IndexError: |
|
2396
39cdddd313ca
HTMLInputMixin provides translation interface for all its hiers...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2390
diff
changeset
|
1259 comments['no_link'] = self._( |
|
2327
36ae1b14aaab
remove excessive spaces in the translatable strings;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2324
diff
changeset
|
1260 "<strike>The linked node" |
|
36ae1b14aaab
remove excessive spaces in the translatable strings;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2324
diff
changeset
|
1261 " no longer exists</strike>") |
|
1773
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1262 subml.append('<strike>%s</strike>'%label) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1263 else: |
|
1773
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1264 if hrefable: |
|
5684
97e2125e064c
When we generate links from URL's in messages, we add rel="nofollow"
John Rouillard <rouilj@ieee.org>
parents:
5548
diff
changeset
|
1265 subml.append('<a rel="nofollow noopener" ' |
|
5325
7c7f3faa5e10
Check for None linkid in history
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5319
diff
changeset
|
1266 'href="%s%s">%s</a>'%( |
|
1773
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1267 classname, linkid, label)) |
|
3401
62e4032cb280
merge from maint-0-8
Richard Jones <richard@users.sourceforge.net>
parents:
3394
diff
changeset
|
1268 elif label is None: |
|
62e4032cb280
merge from maint-0-8
Richard Jones <richard@users.sourceforge.net>
parents:
3394
diff
changeset
|
1269 subml.append('%s%s'%(classname, |
|
62e4032cb280
merge from maint-0-8
Richard Jones <richard@users.sourceforge.net>
parents:
3394
diff
changeset
|
1270 linkid)) |
|
1773
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1271 else: |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1272 subml.append(label) |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1273 ml.append(sublabel + ', '.join(subml)) |
|
2547
9b9c8fb52732
translate action names and property names in the history list
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2538
diff
changeset
|
1274 cell.append('%s:\n %s'%(self._(k), ', '.join(ml))) |
|
1773
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1275 elif isinstance(prop, hyperdb.Link) and args[k]: |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1276 label = classname + args[k] |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1277 # if we have a label property, try to use it |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1278 # TODO: test for node existence even when |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1279 # there's no labelprop! |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1280 if labelprop is not None and labelprop != 'id': |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1281 try: |
|
5800
1a835db41674
Call cgi.escape only on python 2. Replace with html.escapeif it can be
John Rouillard <rouilj@ieee.org>
parents:
5684
diff
changeset
|
1282 label = html_escape(linkcl.get(args[k], |
|
6620
b7093aa16895
issue2551196 - Unset labelprop of a Multilink can lead to Python error when using context/history
John Rouillard <rouilj@ieee.org>
parents:
6593
diff
changeset
|
1283 labelprop, default=self._( |
|
b7093aa16895
issue2551196 - Unset labelprop of a Multilink can lead to Python error when using context/history
John Rouillard <rouilj@ieee.org>
parents:
6593
diff
changeset
|
1284 "[label is missing]"))) |
|
1773
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1285 except IndexError: |
|
2396
39cdddd313ca
HTMLInputMixin provides translation interface for all its hiers...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2390
diff
changeset
|
1286 comments['no_link'] = self._( |
|
2327
36ae1b14aaab
remove excessive spaces in the translatable strings;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2324
diff
changeset
|
1287 "<strike>The linked node" |
|
36ae1b14aaab
remove excessive spaces in the translatable strings;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2324
diff
changeset
|
1288 " no longer exists</strike>") |
|
1773
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1289 cell.append(' <strike>%s</strike>,\n'%label) |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1290 # "flag" this is done .... euwww |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1291 label = None |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1292 if label is not None: |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1293 if hrefable: |
|
6542
58bd05fbf350
Replace bad ref= attr with rel= on a tag in history.
John Rouillard <rouilj@ieee.org>
parents:
6444
diff
changeset
|
1294 old = '<a rel="nofollow noopener" href="%s%s">%s</a>'%(classname, |
|
3971
ff3a8b7d1819
security fixes
Richard Jones <richard@users.sourceforge.net>
parents:
3968
diff
changeset
|
1295 args[k], label) |
|
1773
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1296 else: |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1297 old = label; |
|
2547
9b9c8fb52732
translate action names and property names in the history list
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2538
diff
changeset
|
1298 cell.append('%s: %s' % (self._(k), old)) |
|
5492
6b0c542642be
blobfiles now always stores/returns bytes
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5488
diff
changeset
|
1299 if k in current and current[k] is not None: |
|
1364
1d1ee96e8956
applied patch for nicer history display (feature [SF#638280])
Richard Jones <richard@users.sourceforge.net>
parents:
1357
diff
changeset
|
1300 cell[-1] += ' -> %s'%current[k] |
|
1773
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1301 current[k] = old |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1302 |
|
1773
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1303 elif isinstance(prop, hyperdb.Date) and args[k]: |
|
3151
6feac4fcf883
Various bug fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
3127
diff
changeset
|
1304 if args[k] is None: |
|
6feac4fcf883
Various bug fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
3127
diff
changeset
|
1305 d = '' |
|
6feac4fcf883
Various bug fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
3127
diff
changeset
|
1306 else: |
|
6feac4fcf883
Various bug fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
3127
diff
changeset
|
1307 d = date.Date(args[k], |
|
6feac4fcf883
Various bug fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
3127
diff
changeset
|
1308 translator=self._client).local(timezone) |
|
2547
9b9c8fb52732
translate action names and property names in the history list
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2538
diff
changeset
|
1309 cell.append('%s: %s'%(self._(k), str(d))) |
|
5492
6b0c542642be
blobfiles now always stores/returns bytes
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5488
diff
changeset
|
1310 if k in current and current[k] is not None: |
|
1773
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1311 cell[-1] += ' -> %s' % current[k] |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1312 current[k] = str(d) |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1313 |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1314 elif isinstance(prop, hyperdb.Interval) and args[k]: |
|
2524
736115d374f2
use client instance to translate Date and Interval objects
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2520
diff
changeset
|
1315 val = str(date.Interval(args[k], |
|
736115d374f2
use client instance to translate Date and Interval objects
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2520
diff
changeset
|
1316 translator=self._client)) |
|
2547
9b9c8fb52732
translate action names and property names in the history list
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2538
diff
changeset
|
1317 cell.append('%s: %s'%(self._(k), val)) |
|
5492
6b0c542642be
blobfiles now always stores/returns bytes
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5488
diff
changeset
|
1318 if k in current and current[k] is not None: |
|
1773
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1319 cell[-1] += ' -> %s'%current[k] |
|
2170
0def552122af
handle Boolean values in history HTML display
Richard Jones <richard@users.sourceforge.net>
parents:
2157
diff
changeset
|
1320 current[k] = val |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1321 |
|
1773
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1322 elif isinstance(prop, hyperdb.String) and args[k]: |
|
5800
1a835db41674
Call cgi.escape only on python 2. Replace with html.escapeif it can be
John Rouillard <rouilj@ieee.org>
parents:
5684
diff
changeset
|
1323 val = html_escape(args[k]) |
|
2547
9b9c8fb52732
translate action names and property names in the history list
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2538
diff
changeset
|
1324 cell.append('%s: %s'%(self._(k), val)) |
|
5492
6b0c542642be
blobfiles now always stores/returns bytes
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5488
diff
changeset
|
1325 if k in current and current[k] is not None: |
|
1773
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1326 cell[-1] += ' -> %s'%current[k] |
|
2170
0def552122af
handle Boolean values in history HTML display
Richard Jones <richard@users.sourceforge.net>
parents:
2157
diff
changeset
|
1327 current[k] = val |
|
0def552122af
handle Boolean values in history HTML display
Richard Jones <richard@users.sourceforge.net>
parents:
2157
diff
changeset
|
1328 |
|
0def552122af
handle Boolean values in history HTML display
Richard Jones <richard@users.sourceforge.net>
parents:
2157
diff
changeset
|
1329 elif isinstance(prop, hyperdb.Boolean) and args[k] is not None: |
|
2547
9b9c8fb52732
translate action names and property names in the history list
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2538
diff
changeset
|
1330 val = args[k] and ''"Yes" or ''"No" |
|
9b9c8fb52732
translate action names and property names in the history list
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2538
diff
changeset
|
1331 cell.append('%s: %s'%(self._(k), val)) |
|
5492
6b0c542642be
blobfiles now always stores/returns bytes
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5488
diff
changeset
|
1332 if k in current and current[k] is not None: |
|
2170
0def552122af
handle Boolean values in history HTML display
Richard Jones <richard@users.sourceforge.net>
parents:
2157
diff
changeset
|
1333 cell[-1] += ' -> %s'%current[k] |
|
0def552122af
handle Boolean values in history HTML display
Richard Jones <richard@users.sourceforge.net>
parents:
2157
diff
changeset
|
1334 current[k] = val |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1335 |
|
4483
22bc0426e348
Second patch from issue2550688 -- with some changes:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4481
diff
changeset
|
1336 elif isinstance(prop, hyperdb.Password) and args[k] is not None: |
|
22bc0426e348
Second patch from issue2550688 -- with some changes:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4481
diff
changeset
|
1337 val = args[k].dummystr() |
|
22bc0426e348
Second patch from issue2550688 -- with some changes:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4481
diff
changeset
|
1338 cell.append('%s: %s'%(self._(k), val)) |
|
5492
6b0c542642be
blobfiles now always stores/returns bytes
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5488
diff
changeset
|
1339 if k in current and current[k] is not None: |
|
4483
22bc0426e348
Second patch from issue2550688 -- with some changes:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4481
diff
changeset
|
1340 cell[-1] += ' -> %s'%current[k] |
|
22bc0426e348
Second patch from issue2550688 -- with some changes:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4481
diff
changeset
|
1341 current[k] = val |
|
22bc0426e348
Second patch from issue2550688 -- with some changes:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4481
diff
changeset
|
1342 |
|
1773
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1343 elif not args[k]: |
|
5492
6b0c542642be
blobfiles now always stores/returns bytes
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5488
diff
changeset
|
1344 if k in current and current[k] is not None: |
|
2547
9b9c8fb52732
translate action names and property names in the history list
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2538
diff
changeset
|
1345 cell.append('%s: %s'%(self._(k), current[k])) |
|
1773
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1346 current[k] = '(no value)' |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1347 else: |
|
2547
9b9c8fb52732
translate action names and property names in the history list
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2538
diff
changeset
|
1348 cell.append(self._('%s: (no value)')%self._(k)) |
|
1773
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1349 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1350 else: |
|
2547
9b9c8fb52732
translate action names and property names in the history list
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2538
diff
changeset
|
1351 cell.append('%s: %s'%(self._(k), str(args[k]))) |
|
5492
6b0c542642be
blobfiles now always stores/returns bytes
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5488
diff
changeset
|
1352 if k in current and current[k] is not None: |
|
1773
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1353 cell[-1] += ' -> %s'%current[k] |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1354 current[k] = str(args[k]) |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1355 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1356 arg_s = '<br />'.join(cell) |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1357 else: |
|
7017
96be63649c92
flake8 fix additional spaces within () and []
John Rouillard <rouilj@ieee.org>
parents:
6856
diff
changeset
|
1358 if action in ('retired', 'restored'): |
|
5947
33914dd1160f
Retired and Restored were unhandled by history.
John Rouillard <rouilj@ieee.org>
parents:
5927
diff
changeset
|
1359 # args = None for these actions |
|
33914dd1160f
Retired and Restored were unhandled by history.
John Rouillard <rouilj@ieee.org>
parents:
5927
diff
changeset
|
1360 pass |
|
33914dd1160f
Retired and Restored were unhandled by history.
John Rouillard <rouilj@ieee.org>
parents:
5927
diff
changeset
|
1361 else: |
|
33914dd1160f
Retired and Restored were unhandled by history.
John Rouillard <rouilj@ieee.org>
parents:
5927
diff
changeset
|
1362 # unknown event!! |
|
33914dd1160f
Retired and Restored were unhandled by history.
John Rouillard <rouilj@ieee.org>
parents:
5927
diff
changeset
|
1363 comments['unknown'] = self._( |
|
33914dd1160f
Retired and Restored were unhandled by history.
John Rouillard <rouilj@ieee.org>
parents:
5927
diff
changeset
|
1364 "<strong><em>This event %s is not handled" |
|
33914dd1160f
Retired and Restored were unhandled by history.
John Rouillard <rouilj@ieee.org>
parents:
5927
diff
changeset
|
1365 " by the history display!</em></strong>"%action) |
|
33914dd1160f
Retired and Restored were unhandled by history.
John Rouillard <rouilj@ieee.org>
parents:
5927
diff
changeset
|
1366 arg_s = '<strong><em>' + str(args) + '</em></strong>' |
|
33914dd1160f
Retired and Restored were unhandled by history.
John Rouillard <rouilj@ieee.org>
parents:
5927
diff
changeset
|
1367 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1368 date_s = date_s.replace(' ', ' ') |
|
1258
de0f879f995d
fixed history to display username instead of userid
Richard Jones <richard@users.sourceforge.net>
parents:
1254
diff
changeset
|
1369 # if the user's an itemid, figure the username (older journals |
|
de0f879f995d
fixed history to display username instead of userid
Richard Jones <richard@users.sourceforge.net>
parents:
1254
diff
changeset
|
1370 # have the username) |
|
de0f879f995d
fixed history to display username instead of userid
Richard Jones <richard@users.sourceforge.net>
parents:
1254
diff
changeset
|
1371 if dre.match(user): |
|
de0f879f995d
fixed history to display username instead of userid
Richard Jones <richard@users.sourceforge.net>
parents:
1254
diff
changeset
|
1372 user = self._db.user.get(user, 'username') |
|
1074
954ad22eb7d9
more doc, more cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1073
diff
changeset
|
1373 l.append('<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>'%( |
|
5800
1a835db41674
Call cgi.escape only on python 2. Replace with html.escapeif it can be
John Rouillard <rouilj@ieee.org>
parents:
5684
diff
changeset
|
1374 date_s, html_escape(user), self._(action), arg_s)) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1375 if comments: |
|
2396
39cdddd313ca
HTMLInputMixin provides translation interface for all its hiers...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2390
diff
changeset
|
1376 l.append(self._( |
|
39cdddd313ca
HTMLInputMixin provides translation interface for all its hiers...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2390
diff
changeset
|
1377 '<tr><td colspan=4><strong>Note:</strong></td></tr>')) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1378 for entry in comments.values(): |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1379 l.append('<tr><td colspan=4>%s</td></tr>'%entry) |
|
2614
c64ea31a569b
merge from HEAD, with some additional code re-arranging
Richard Jones <richard@users.sourceforge.net>
parents:
2591
diff
changeset
|
1380 |
|
c64ea31a569b
merge from HEAD, with some additional code re-arranging
Richard Jones <richard@users.sourceforge.net>
parents:
2591
diff
changeset
|
1381 if direction == 'ascending': |
|
c64ea31a569b
merge from HEAD, with some additional code re-arranging
Richard Jones <richard@users.sourceforge.net>
parents:
2591
diff
changeset
|
1382 l.reverse() |
|
c64ea31a569b
merge from HEAD, with some additional code re-arranging
Richard Jones <richard@users.sourceforge.net>
parents:
2591
diff
changeset
|
1383 |
|
4696
57a64e591a00
Use bootstrap classes for displaying tables; bug.item is almost table free and uses bootstrap form classes and markup
Pradip Caulagi <caulagi@gmail.com>
parents:
4651
diff
changeset
|
1384 l[0:0] = ['<table class="history table table-condensed table-striped">' |
|
2614
c64ea31a569b
merge from HEAD, with some additional code re-arranging
Richard Jones <richard@users.sourceforge.net>
parents:
2591
diff
changeset
|
1385 '<tr><th colspan="4" class="header">', |
|
c64ea31a569b
merge from HEAD, with some additional code re-arranging
Richard Jones <richard@users.sourceforge.net>
parents:
2591
diff
changeset
|
1386 self._('History'), |
|
c64ea31a569b
merge from HEAD, with some additional code re-arranging
Richard Jones <richard@users.sourceforge.net>
parents:
2591
diff
changeset
|
1387 '</th></tr><tr>', |
|
c64ea31a569b
merge from HEAD, with some additional code re-arranging
Richard Jones <richard@users.sourceforge.net>
parents:
2591
diff
changeset
|
1388 self._('<th>Date</th>'), |
|
c64ea31a569b
merge from HEAD, with some additional code re-arranging
Richard Jones <richard@users.sourceforge.net>
parents:
2591
diff
changeset
|
1389 self._('<th>User</th>'), |
|
c64ea31a569b
merge from HEAD, with some additional code re-arranging
Richard Jones <richard@users.sourceforge.net>
parents:
2591
diff
changeset
|
1390 self._('<th>Action</th>'), |
|
c64ea31a569b
merge from HEAD, with some additional code re-arranging
Richard Jones <richard@users.sourceforge.net>
parents:
2591
diff
changeset
|
1391 self._('<th>Args</th>'), |
|
c64ea31a569b
merge from HEAD, with some additional code re-arranging
Richard Jones <richard@users.sourceforge.net>
parents:
2591
diff
changeset
|
1392 '</tr>'] |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1393 l.append('</table>') |
|
6422
91ae685405ba
- issue2550964 - History can (temporarily) show incorrect value...
John Rouillard <rouilj@ieee.org>
parents:
6421
diff
changeset
|
1394 |
|
91ae685405ba
- issue2550964 - History can (temporarily) show incorrect value...
John Rouillard <rouilj@ieee.org>
parents:
6421
diff
changeset
|
1395 self._client.form_wins = orig_form_wins |
|
7019
e1528860e591
flake8 remove space from blank lines W293
John Rouillard <rouilj@ieee.org>
parents:
7018
diff
changeset
|
1396 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1397 return '\n'.join(l) |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1398 |
|
1097
98f3d41f41d9
query "editing" now working, minus filling the form in with the query params
Richard Jones <richard@users.sourceforge.net>
parents:
1096
diff
changeset
|
1399 def renderQueryForm(self): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1400 """ Render this item, which is a query, as a search form. |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1401 """ |
|
1097
98f3d41f41d9
query "editing" now working, minus filling the form in with the query params
Richard Jones <richard@users.sourceforge.net>
parents:
1096
diff
changeset
|
1402 # create a new request and override the specified args |
|
98f3d41f41d9
query "editing" now working, minus filling the form in with the query params
Richard Jones <richard@users.sourceforge.net>
parents:
1096
diff
changeset
|
1403 req = HTMLRequest(self._client) |
|
98f3d41f41d9
query "editing" now working, minus filling the form in with the query params
Richard Jones <richard@users.sourceforge.net>
parents:
1096
diff
changeset
|
1404 req.classname = self._klass.get(self._nodeid, 'klass') |
|
1284
899c6ced2abe
include queryname in query template render ;)
Richard Jones <richard@users.sourceforge.net>
parents:
1272
diff
changeset
|
1405 name = self._klass.get(self._nodeid, 'name') |
|
899c6ced2abe
include queryname in query template render ;)
Richard Jones <richard@users.sourceforge.net>
parents:
1272
diff
changeset
|
1406 req.updateFromURL(self._klass.get(self._nodeid, 'url') + |
|
5402
88dbacd11cd1
Python 3 preparation: update urllib / urllib2 / urlparse imports.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5399
diff
changeset
|
1407 '&@queryname=%s'%urllib_.quote(name)) |
|
1097
98f3d41f41d9
query "editing" now working, minus filling the form in with the query params
Richard Jones <richard@users.sourceforge.net>
parents:
1096
diff
changeset
|
1408 |
|
98f3d41f41d9
query "editing" now working, minus filling the form in with the query params
Richard Jones <richard@users.sourceforge.net>
parents:
1096
diff
changeset
|
1409 # new template, using the specified classname and request |
|
4740
fe9568a6cbd6
Untangle template selection logic from template loading functionality.
anatoly techtonik <techtonik@gmail.com>
parents:
4737
diff
changeset
|
1410 # [ ] the custom logic for search page doesn't belong to |
|
fe9568a6cbd6
Untangle template selection logic from template loading functionality.
anatoly techtonik <techtonik@gmail.com>
parents:
4737
diff
changeset
|
1411 # generic templating module (techtonik) |
|
fe9568a6cbd6
Untangle template selection logic from template loading functionality.
anatoly techtonik <techtonik@gmail.com>
parents:
4737
diff
changeset
|
1412 tplname = self._client.selectTemplate(req.classname, 'search') |
|
fe9568a6cbd6
Untangle template selection logic from template loading functionality.
anatoly techtonik <techtonik@gmail.com>
parents:
4737
diff
changeset
|
1413 pt = self._client.instance.templates.load(tplname) |
|
4057
885069b5f328
Fix context for query form to be a class.
Stefan Seefeld <stefan@seefeld.name>
parents:
4056
diff
changeset
|
1414 # The context for a search page should be the class, not any |
|
885069b5f328
Fix context for query form to be a class.
Stefan Seefeld <stefan@seefeld.name>
parents:
4056
diff
changeset
|
1415 # node. |
|
885069b5f328
Fix context for query form to be a class.
Stefan Seefeld <stefan@seefeld.name>
parents:
4056
diff
changeset
|
1416 self._client.nodeid = None |
|
4115
d61066deae67
handle bogus pagination values (issue 2550530)
Richard Jones <richard@users.sourceforge.net>
parents:
4112
diff
changeset
|
1417 |
|
1097
98f3d41f41d9
query "editing" now working, minus filling the form in with the query params
Richard Jones <richard@users.sourceforge.net>
parents:
1096
diff
changeset
|
1418 # use our fabricated request |
|
98f3d41f41d9
query "editing" now working, minus filling the form in with the query params
Richard Jones <richard@users.sourceforge.net>
parents:
1096
diff
changeset
|
1419 return pt.render(self._client, req.classname, req) |
|
98f3d41f41d9
query "editing" now working, minus filling the form in with the query params
Richard Jones <richard@users.sourceforge.net>
parents:
1096
diff
changeset
|
1420 |
|
2180
58b6d1747973
Web interface tweaks.
Richard Jones <richard@users.sourceforge.net>
parents:
2170
diff
changeset
|
1421 def download_url(self): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1422 """ Assume that this item is a FileClass and that it has a name |
|
2180
58b6d1747973
Web interface tweaks.
Richard Jones <richard@users.sourceforge.net>
parents:
2170
diff
changeset
|
1423 and content. Construct a URL for the download of the content. |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1424 """ |
|
2180
58b6d1747973
Web interface tweaks.
Richard Jones <richard@users.sourceforge.net>
parents:
2170
diff
changeset
|
1425 name = self._klass.get(self._nodeid, 'name') |
|
58b6d1747973
Web interface tweaks.
Richard Jones <richard@users.sourceforge.net>
parents:
2170
diff
changeset
|
1426 url = '%s%s/%s'%(self._classname, self._nodeid, name) |
|
5402
88dbacd11cd1
Python 3 preparation: update urllib / urllib2 / urlparse imports.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5399
diff
changeset
|
1427 return urllib_.quote(url) |
|
2180
58b6d1747973
Web interface tweaks.
Richard Jones <richard@users.sourceforge.net>
parents:
2170
diff
changeset
|
1428 |
|
3509
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
1429 def copy_url(self, exclude=("messages", "files")): |
|
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
1430 """Construct a URL for creating a copy of this item |
|
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
1431 |
|
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
1432 "exclude" is an optional list of properties that should |
|
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
1433 not be copied to the new object. By default, this list |
|
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
1434 includes "messages" and "files" properties. Note that |
|
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
1435 "id" property cannot be copied. |
|
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
1436 |
|
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
1437 """ |
|
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
1438 exclude = ("id", "activity", "actor", "creation", "creator") \ |
|
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
1439 + tuple(exclude) |
|
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
1440 query = { |
|
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
1441 "@template": "item", |
|
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
1442 "@note": self._("Copy of %(class)s %(id)s") % { |
|
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
1443 "class": self._(self._classname), "id": self._nodeid}, |
|
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
1444 } |
|
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
1445 for name in self._props.keys(): |
|
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
1446 if name not in exclude: |
|
4839
c317147fd891
Fix copy_url to properly support properties that are mutlilinks.
John Rouillard <rouilj@ieee.org>
parents:
4804
diff
changeset
|
1447 prop = self._props[name] |
|
c317147fd891
Fix copy_url to properly support properties that are mutlilinks.
John Rouillard <rouilj@ieee.org>
parents:
4804
diff
changeset
|
1448 if not isinstance(prop, hyperdb.Multilink): |
|
c317147fd891
Fix copy_url to properly support properties that are mutlilinks.
John Rouillard <rouilj@ieee.org>
parents:
4804
diff
changeset
|
1449 query[name] = self[name].plain() |
|
c317147fd891
Fix copy_url to properly support properties that are mutlilinks.
John Rouillard <rouilj@ieee.org>
parents:
4804
diff
changeset
|
1450 else: |
|
c317147fd891
Fix copy_url to properly support properties that are mutlilinks.
John Rouillard <rouilj@ieee.org>
parents:
4804
diff
changeset
|
1451 query[name] = ",".join(self._klass.get(self._nodeid, name)) |
|
c317147fd891
Fix copy_url to properly support properties that are mutlilinks.
John Rouillard <rouilj@ieee.org>
parents:
4804
diff
changeset
|
1452 |
|
3509
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
1453 return self._classname + "?" + "&".join( |
|
5402
88dbacd11cd1
Python 3 preparation: update urllib / urllib2 / urlparse imports.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5399
diff
changeset
|
1454 ["%s=%s" % (key, urllib_.quote(value)) |
|
3509
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
1455 for key, value in query.items()]) |
|
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
1456 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
1457 |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
1458 class _HTMLUser(_HTMLItem): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1459 """Add ability to check for permissions on users. |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1460 """ |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1461 _marker = [] |
|
7019
e1528860e591
flake8 remove space from blank lines W293
John Rouillard <rouilj@ieee.org>
parents:
7018
diff
changeset
|
1462 |
|
2991
b9a55628a78d
more doc fixes
Richard Jones <richard@users.sourceforge.net>
parents:
2983
diff
changeset
|
1463 def hasPermission(self, permission, classname=_marker, |
|
b9a55628a78d
more doc fixes
Richard Jones <richard@users.sourceforge.net>
parents:
2983
diff
changeset
|
1464 property=None, itemid=None): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1465 """Determine if the user has the Permission. |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1466 |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
1467 The class being tested defaults to the template's class, but may |
|
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
1468 be overidden for this test by suppling an alternate classname. |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1469 """ |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1470 if classname is self._marker: |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
1471 classname = self._client.classname |
|
3535
75dc225613cc
fix security check for hasPermission(Permission, None)
Richard Jones <richard@users.sourceforge.net>
parents:
3509
diff
changeset
|
1472 return self._db.security.hasPermission(permission, |
|
3357
5c8822d10fdc
fix invocation of hasPermission from templating code [SF#1224172]
Richard Jones <richard@users.sourceforge.net>
parents:
3354
diff
changeset
|
1473 self._nodeid, classname, property, itemid) |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
1474 |
|
4306
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4288
diff
changeset
|
1475 def hasRole(self, *rolenames): |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4288
diff
changeset
|
1476 """Determine whether the user has any role in rolenames.""" |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4288
diff
changeset
|
1477 return self._db.user.has_role(self._nodeid, *rolenames) |
|
3535
75dc225613cc
fix security check for hasPermission(Permission, None)
Richard Jones <richard@users.sourceforge.net>
parents:
3509
diff
changeset
|
1478 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
1479 |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
1480 def HTMLItem(client, classname, nodeid, anonymous=0): |
|
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
1481 if classname == 'user': |
|
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
1482 return _HTMLUser(client, classname, nodeid, anonymous) |
|
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
1483 else: |
|
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
1484 return _HTMLItem(client, classname, nodeid, anonymous) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1485 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
1486 |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
1487 class HTMLProperty(HTMLInputMixin, HTMLPermissions): |
|
5067
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
1488 """ String, Integer, Number, Date, Interval HTMLProperty |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1489 |
|
1123
644d3075c2df
more documentation, fixed bug in request/description
Richard Jones <richard@users.sourceforge.net>
parents:
1122
diff
changeset
|
1490 Has useful attributes: |
|
1080
24c9e81fce85
bugfix, added some doc
Richard Jones <richard@users.sourceforge.net>
parents:
1079
diff
changeset
|
1491 |
|
24c9e81fce85
bugfix, added some doc
Richard Jones <richard@users.sourceforge.net>
parents:
1079
diff
changeset
|
1492 _name the name of the property |
|
24c9e81fce85
bugfix, added some doc
Richard Jones <richard@users.sourceforge.net>
parents:
1079
diff
changeset
|
1493 _value the value of the property if any |
|
24c9e81fce85
bugfix, added some doc
Richard Jones <richard@users.sourceforge.net>
parents:
1079
diff
changeset
|
1494 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1495 A wrapper object which may be stringified for the plain() behaviour. |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1496 """ |
|
1447
6118d4498db3
added "foo@" prefix to all but "context" form variable names
Richard Jones <richard@users.sourceforge.net>
parents:
1441
diff
changeset
|
1497 def __init__(self, client, classname, nodeid, prop, name, value, |
|
6118d4498db3
added "foo@" prefix to all but "context" form variable names
Richard Jones <richard@users.sourceforge.net>
parents:
1441
diff
changeset
|
1498 anonymous=0): |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
1499 self._client = client |
|
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
1500 self._db = client.db |
|
3164
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
1501 self._ = client._ |
|
1447
6118d4498db3
added "foo@" prefix to all but "context" form variable names
Richard Jones <richard@users.sourceforge.net>
parents:
1441
diff
changeset
|
1502 self._classname = classname |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
1503 self._nodeid = nodeid |
|
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
1504 self._prop = prop |
|
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
1505 self._value = value |
|
1447
6118d4498db3
added "foo@" prefix to all but "context" form variable names
Richard Jones <richard@users.sourceforge.net>
parents:
1441
diff
changeset
|
1506 self._anonymous = anonymous |
|
1468
f57759a5ee1a
Better form name mangling, doesn't confuse other things like generic editing.
Richard Jones <richard@users.sourceforge.net>
parents:
1467
diff
changeset
|
1507 self._name = name |
|
1447
6118d4498db3
added "foo@" prefix to all but "context" form variable names
Richard Jones <richard@users.sourceforge.net>
parents:
1441
diff
changeset
|
1508 if not anonymous: |
|
4286
f364978e6e3f
Do not create bogus non-anonymous objects.
Stefan Seefeld <stefan@seefeld.name>
parents:
4268
diff
changeset
|
1509 if nodeid: |
|
f364978e6e3f
Do not create bogus non-anonymous objects.
Stefan Seefeld <stefan@seefeld.name>
parents:
4268
diff
changeset
|
1510 self._formname = '%s%s@%s'%(classname, nodeid, name) |
|
f364978e6e3f
Do not create bogus non-anonymous objects.
Stefan Seefeld <stefan@seefeld.name>
parents:
4268
diff
changeset
|
1511 else: |
|
f364978e6e3f
Do not create bogus non-anonymous objects.
Stefan Seefeld <stefan@seefeld.name>
parents:
4268
diff
changeset
|
1512 # This case occurs when creating a property for a |
|
f364978e6e3f
Do not create bogus non-anonymous objects.
Stefan Seefeld <stefan@seefeld.name>
parents:
4268
diff
changeset
|
1513 # non-anonymous class. |
|
f364978e6e3f
Do not create bogus non-anonymous objects.
Stefan Seefeld <stefan@seefeld.name>
parents:
4268
diff
changeset
|
1514 self._formname = '%s@%s'%(classname, name) |
|
1447
6118d4498db3
added "foo@" prefix to all but "context" form variable names
Richard Jones <richard@users.sourceforge.net>
parents:
1441
diff
changeset
|
1515 else: |
|
1468
f57759a5ee1a
Better form name mangling, doesn't confuse other things like generic editing.
Richard Jones <richard@users.sourceforge.net>
parents:
1467
diff
changeset
|
1516 self._formname = name |
|
1952
c40ed9113285
Applied Stefan Seefeld's html4/xhtml patch with some changes.
Richard Jones <richard@users.sourceforge.net>
parents:
1932
diff
changeset
|
1517 |
| 4056 | 1518 # If no value is already present for this property, see if one |
| 1519 # is specified in the current form. | |
| 1520 form = self._client.form | |
|
4804
bc4144417861
More fixes for form TypeError
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4791
diff
changeset
|
1521 try: |
|
5381
0942fe89e82e
Python 3 preparation: change "x.has_key(y)" to "y in x".
Joseph Myers <jsm@polyomino.org.uk>
parents:
5378
diff
changeset
|
1522 is_in = self._formname in form |
|
4804
bc4144417861
More fixes for form TypeError
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4791
diff
changeset
|
1523 except TypeError: |
|
bc4144417861
More fixes for form TypeError
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4791
diff
changeset
|
1524 is_in = False |
|
5166
232c74973a56
issue1408570: fix that form values are lost
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5156
diff
changeset
|
1525 if is_in and (not self._value or self._client.form_wins): |
| 4056 | 1526 if isinstance(prop, hyperdb.Multilink): |
| 1527 value = lookupIds(self._db, prop, | |
| 1528 handleListCGIValue(form[self._formname]), | |
| 1529 fail_ok=1) | |
| 1530 elif isinstance(prop, hyperdb.Link): | |
| 1531 value = form.getfirst(self._formname).strip() | |
| 1532 if value: | |
| 1533 value = lookupIds(self._db, prop, [value], | |
| 1534 fail_ok=1)[0] | |
| 1535 else: | |
| 1536 value = None | |
| 1537 else: | |
| 1538 value = form.getfirst(self._formname).strip() or None | |
| 1539 self._value = value | |
| 1540 | |
|
6404
e29d5f4e0af4
issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents:
6398
diff
changeset
|
1541 # if self._value is None see if we have a default value |
|
e29d5f4e0af4
issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents:
6398
diff
changeset
|
1542 if self._value is None: |
|
e29d5f4e0af4
issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents:
6398
diff
changeset
|
1543 self._value = prop.get_default_value() |
|
e29d5f4e0af4
issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents:
6398
diff
changeset
|
1544 |
|
1956
1e2cccf6b53b
give access to the input() method all over the place
Richard Jones <richard@users.sourceforge.net>
parents:
1952
diff
changeset
|
1545 HTMLInputMixin.__init__(self) |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
1546 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1547 def __repr__(self): |
|
4463
1bd86e82422b
Make HTMLProperty report actual classname in repr().
Stefan Seefeld <stefan@seefeld.name>
parents:
4437
diff
changeset
|
1548 classname = self.__class__.__name__ |
|
1bd86e82422b
Make HTMLProperty report actual classname in repr().
Stefan Seefeld <stefan@seefeld.name>
parents:
4437
diff
changeset
|
1549 return '<%s(0x%x) %s %r %r>'%(classname, id(self), self._formname, |
|
1bd86e82422b
Make HTMLProperty report actual classname in repr().
Stefan Seefeld <stefan@seefeld.name>
parents:
4437
diff
changeset
|
1550 self._prop, self._value) |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
1551 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1552 def __str__(self): |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1553 return self.plain() |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
1554 |
|
5414
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
1555 def __lt__(self, other): |
|
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
1556 if isinstance(other, HTMLProperty): |
|
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
1557 return self._value < other._value |
|
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
1558 return self._value < other |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
1559 |
|
5414
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
1560 def __le__(self, other): |
|
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
1561 if isinstance(other, HTMLProperty): |
|
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
1562 return self._value <= other._value |
|
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
1563 return self._value <= other |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
1564 |
|
5414
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
1565 def __eq__(self, other): |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1566 if isinstance(other, HTMLProperty): |
|
5414
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
1567 return self._value == other._value |
|
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
1568 return self._value == other |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
1569 |
|
5414
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
1570 def __ne__(self, other): |
|
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
1571 if isinstance(other, HTMLProperty): |
|
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
1572 return self._value != other._value |
|
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
1573 return self._value != other |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
1574 |
|
5414
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
1575 def __gt__(self, other): |
|
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
1576 if isinstance(other, HTMLProperty): |
|
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
1577 return self._value > other._value |
|
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
1578 return self._value > other |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
1579 |
|
5414
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
1580 def __ge__(self, other): |
|
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
1581 if isinstance(other, HTMLProperty): |
|
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
1582 return self._value >= other._value |
|
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
1583 return self._value >= other |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1584 |
|
5404
3757449e00c4
Python 3 preparation: use __bool__ instead of __nonzero__.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5402
diff
changeset
|
1585 def __bool__(self): |
|
2347
fbbda3b1816d
implement __nonzero__ for HTMLProperty
Richard Jones <richard@users.sourceforge.net>
parents:
2327
diff
changeset
|
1586 return not not self._value |
|
5404
3757449e00c4
Python 3 preparation: use __bool__ instead of __nonzero__.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5402
diff
changeset
|
1587 # Python 2 compatibility: |
|
3757449e00c4
Python 3 preparation: use __bool__ instead of __nonzero__.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5402
diff
changeset
|
1588 __nonzero__ = __bool__ |
|
2347
fbbda3b1816d
implement __nonzero__ for HTMLProperty
Richard Jones <richard@users.sourceforge.net>
parents:
2327
diff
changeset
|
1589 |
|
2180
58b6d1747973
Web interface tweaks.
Richard Jones <richard@users.sourceforge.net>
parents:
2170
diff
changeset
|
1590 def isset(self): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1591 """Is my _value not None?""" |
|
2289
6d16b967f89d
HTML templating isset() inverted [SF#951779]
Richard Jones <richard@users.sourceforge.net>
parents:
2262
diff
changeset
|
1592 return self._value is not None |
|
2180
58b6d1747973
Web interface tweaks.
Richard Jones <richard@users.sourceforge.net>
parents:
2170
diff
changeset
|
1593 |
|
2002
b046b65e51db
if you're going to enforce class-level permissions...
Richard Jones <richard@users.sourceforge.net>
parents:
1983
diff
changeset
|
1594 def is_edit_ok(self): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1595 """Should the user be allowed to use an edit form field for this |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
1596 property. Check "Create" for new items, or "Edit" for existing |
|
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
1597 ones. |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1598 """ |
|
4328
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
1599 perm = self._db.security.hasPermission |
|
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
1600 userid = self._client.userid |
|
2002
b046b65e51db
if you're going to enforce class-level permissions...
Richard Jones <richard@users.sourceforge.net>
parents:
1983
diff
changeset
|
1601 if self._nodeid: |
|
4329
58b7ba47af87
fixes to make registration work again
Richard Jones <richard@users.sourceforge.net>
parents:
4328
diff
changeset
|
1602 if not perm('Web Access', userid): |
|
58b7ba47af87
fixes to make registration work again
Richard Jones <richard@users.sourceforge.net>
parents:
4328
diff
changeset
|
1603 return False |
|
4328
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
1604 return perm('Edit', userid, self._classname, self._name, |
|
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
1605 self._nodeid) |
|
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
1606 return perm('Create', userid, self._classname, self._name) or \ |
|
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
1607 perm('Register', userid, self._classname, self._name) |
|
2002
b046b65e51db
if you're going to enforce class-level permissions...
Richard Jones <richard@users.sourceforge.net>
parents:
1983
diff
changeset
|
1608 |
|
b046b65e51db
if you're going to enforce class-level permissions...
Richard Jones <richard@users.sourceforge.net>
parents:
1983
diff
changeset
|
1609 def is_view_ok(self): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1610 """ Is the user allowed to View the current class? |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1611 """ |
|
4328
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
1612 perm = self._db.security.hasPermission |
|
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
1613 if perm('Web Access', self._client.userid) and perm('View', |
|
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
1614 self._client.userid, self._classname, self._name, self._nodeid): |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
1615 return 1 |
|
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
1616 return self.is_edit_ok() |
|
2002
b046b65e51db
if you're going to enforce class-level permissions...
Richard Jones <richard@users.sourceforge.net>
parents:
1983
diff
changeset
|
1617 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
1618 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1619 class StringHTMLProperty(HTMLProperty): |
|
3991
13161539e5bd
improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents:
3972
diff
changeset
|
1620 hyper_re = re.compile(r'''( |
|
13161539e5bd
improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents:
3972
diff
changeset
|
1621 (?P<url> |
|
4009
e335ce40d6c8
Make URL matching code less matchy
Richard Jones <richard@users.sourceforge.net>
parents:
3991
diff
changeset
|
1622 ( |
|
e335ce40d6c8
Make URL matching code less matchy
Richard Jones <richard@users.sourceforge.net>
parents:
3991
diff
changeset
|
1623 (ht|f)tp(s?):// # protocol |
|
4010
797eacd945af
add tests for and fix alex's examples
Richard Jones <richard@users.sourceforge.net>
parents:
4009
diff
changeset
|
1624 ([\w]+(:\w+)?@)? # username/password |
|
797eacd945af
add tests for and fix alex's examples
Richard Jones <richard@users.sourceforge.net>
parents:
4009
diff
changeset
|
1625 ([\w\-]+) # hostname |
|
797eacd945af
add tests for and fix alex's examples
Richard Jones <richard@users.sourceforge.net>
parents:
4009
diff
changeset
|
1626 ((\.[\w-]+)+)? # .domain.etc |
|
4009
e335ce40d6c8
Make URL matching code less matchy
Richard Jones <richard@users.sourceforge.net>
parents:
3991
diff
changeset
|
1627 | # ... or ... |
|
4010
797eacd945af
add tests for and fix alex's examples
Richard Jones <richard@users.sourceforge.net>
parents:
4009
diff
changeset
|
1628 ([\w]+(:\w+)?@)? # username/password |
|
4009
e335ce40d6c8
Make URL matching code less matchy
Richard Jones <richard@users.sourceforge.net>
parents:
3991
diff
changeset
|
1629 www\. # "www." |
|
e335ce40d6c8
Make URL matching code less matchy
Richard Jones <richard@users.sourceforge.net>
parents:
3991
diff
changeset
|
1630 ([\w\-]+\.)+ # hostname |
|
e335ce40d6c8
Make URL matching code less matchy
Richard Jones <richard@users.sourceforge.net>
parents:
3991
diff
changeset
|
1631 [\w]{2,5} # TLD |
|
e335ce40d6c8
Make URL matching code less matchy
Richard Jones <richard@users.sourceforge.net>
parents:
3991
diff
changeset
|
1632 ) |
|
e335ce40d6c8
Make URL matching code less matchy
Richard Jones <richard@users.sourceforge.net>
parents:
3991
diff
changeset
|
1633 (:[\d]{1,5})? # port |
|
e335ce40d6c8
Make URL matching code less matchy
Richard Jones <richard@users.sourceforge.net>
parents:
3991
diff
changeset
|
1634 (/[\w\-$.+!*(),;:@&=?/~\\#%]*)? # path etc. |
|
3991
13161539e5bd
improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents:
3972
diff
changeset
|
1635 )| |
|
13161539e5bd
improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents:
3972
diff
changeset
|
1636 (?P<email>[-+=%/\w\.]+@[\w\.\-]+)| |
|
6564
21c7c2041a4b
issue2551181 - allow issueXXX#fragment to generate a link with fragment
John Rouillard <rouilj@ieee.org>
parents:
6542
diff
changeset
|
1637 (?P<item>(?P<class>[A-Za-z_]+)(\s*)(?P<id>\d+)(?P<fragment>\#[^][\#%^{}"<>\s]+)?) |
|
3991
13161539e5bd
improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents:
3972
diff
changeset
|
1638 )''', re.X | re.I) |
|
13161539e5bd
improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents:
3972
diff
changeset
|
1639 protocol_re = re.compile('^(ht|f)tp(s?)://', re.I) |
|
13161539e5bd
improved URL matching
Richard Jones <richard@users.sourceforge.net>
parents:
3972
diff
changeset
|
1640 |
|
6098
72a281a55a17
Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents:
6097
diff
changeset
|
1641 # disable rst directives that have security implications |
|
72a281a55a17
Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents:
6097
diff
changeset
|
1642 rst_defaults = {'file_insertion_enabled': 0, |
|
72a281a55a17
Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents:
6097
diff
changeset
|
1643 'raw_enabled': 0, |
|
72a281a55a17
Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents:
6097
diff
changeset
|
1644 '_disable_config': 1} |
|
4396
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
1645 |
|
7017
96be63649c92
flake8 fix additional spaces within () and []
John Rouillard <rouilj@ieee.org>
parents:
6856
diff
changeset
|
1646 valid_schemes = {} |
|
6103
af16c135fb98
url's with javascript scheme should not be links in reST
John Rouillard <rouilj@ieee.org>
parents:
6102
diff
changeset
|
1647 |
|
4396
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
1648 def _hyper_repl(self, match): |
|
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
1649 if match.group('url'): |
|
5684
97e2125e064c
When we generate links from URL's in messages, we add rel="nofollow"
John Rouillard <rouilj@ieee.org>
parents:
5548
diff
changeset
|
1650 return self._hyper_repl_url(match, '<a href="%s" rel="nofollow noopener">%s</a>%s') |
|
4396
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
1651 elif match.group('email'): |
|
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
1652 return self._hyper_repl_email(match, '<a href="mailto:%s">%s</a>') |
|
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
1653 elif len(match.group('id')) < 10: |
|
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
1654 return self._hyper_repl_item(match, |
|
6564
21c7c2041a4b
issue2551181 - allow issueXXX#fragment to generate a link with fragment
John Rouillard <rouilj@ieee.org>
parents:
6542
diff
changeset
|
1655 '<a href="%(cls)s%(id)s%(fragment)s">%(item)s</a>') |
|
4396
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
1656 else: |
|
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
1657 # just return the matched text |
|
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
1658 return match.group(0) |
|
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
1659 |
|
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
1660 def _hyper_repl_url(self, match, replacement): |
|
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
1661 u = s = match.group('url') |
|
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
1662 if not self.protocol_re.search(s): |
|
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
1663 u = 'http://' + s |
|
4413
66603a9051f9
improve handling of '>' when URLs are converted to links
Richard Jones <richard@users.sourceforge.net>
parents:
4396
diff
changeset
|
1664 end = '' |
|
66603a9051f9
improve handling of '>' when URLs are converted to links
Richard Jones <richard@users.sourceforge.net>
parents:
4396
diff
changeset
|
1665 if '>' in s: |
|
66603a9051f9
improve handling of '>' when URLs are converted to links
Richard Jones <richard@users.sourceforge.net>
parents:
4396
diff
changeset
|
1666 # catch an escaped ">" in the URL |
|
66603a9051f9
improve handling of '>' when URLs are converted to links
Richard Jones <richard@users.sourceforge.net>
parents:
4396
diff
changeset
|
1667 pos = s.find('>') |
|
66603a9051f9
improve handling of '>' when URLs are converted to links
Richard Jones <richard@users.sourceforge.net>
parents:
4396
diff
changeset
|
1668 end = s[pos:] |
|
66603a9051f9
improve handling of '>' when URLs are converted to links
Richard Jones <richard@users.sourceforge.net>
parents:
4396
diff
changeset
|
1669 u = s = s[:pos] |
|
4647
11b6601629d7
#2550759: Trailing punctuation is no longer included when URLs are converted to links.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
4587
diff
changeset
|
1670 if s.endswith(tuple('.,;:!')): |
|
11b6601629d7
#2550759: Trailing punctuation is no longer included when URLs are converted to links.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
4587
diff
changeset
|
1671 # don't include trailing punctuation |
|
11b6601629d7
#2550759: Trailing punctuation is no longer included when URLs are converted to links.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
4587
diff
changeset
|
1672 end = s[-1:] + end |
|
11b6601629d7
#2550759: Trailing punctuation is no longer included when URLs are converted to links.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
4587
diff
changeset
|
1673 u = s = s[:-1] |
|
4413
66603a9051f9
improve handling of '>' when URLs are converted to links
Richard Jones <richard@users.sourceforge.net>
parents:
4396
diff
changeset
|
1674 if ')' in s and s.count('(') != s.count(')'): |
|
4396
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
1675 # don't include extraneous ')' in the link |
|
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
1676 pos = s.rfind(')') |
|
4413
66603a9051f9
improve handling of '>' when URLs are converted to links
Richard Jones <richard@users.sourceforge.net>
parents:
4396
diff
changeset
|
1677 end = s[pos:] + end |
|
4396
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
1678 u = s = s[:pos] |
|
4413
66603a9051f9
improve handling of '>' when URLs are converted to links
Richard Jones <richard@users.sourceforge.net>
parents:
4396
diff
changeset
|
1679 return replacement % (u, s, end) |
|
4396
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
1680 |
|
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
1681 def _hyper_repl_email(self, match, replacement): |
|
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
1682 s = match.group('email') |
|
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
1683 return replacement % (s, s) |
|
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
1684 |
|
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
1685 def _hyper_repl_item(self, match, replacement): |
|
3862
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1686 item = match.group('item') |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1687 cls = match.group('class').lower() |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1688 id = match.group('id') |
|
6564
21c7c2041a4b
issue2551181 - allow issueXXX#fragment to generate a link with fragment
John Rouillard <rouilj@ieee.org>
parents:
6542
diff
changeset
|
1689 fragment = match.group('fragment') |
|
21c7c2041a4b
issue2551181 - allow issueXXX#fragment to generate a link with fragment
John Rouillard <rouilj@ieee.org>
parents:
6542
diff
changeset
|
1690 if fragment is None: |
|
21c7c2041a4b
issue2551181 - allow issueXXX#fragment to generate a link with fragment
John Rouillard <rouilj@ieee.org>
parents:
6542
diff
changeset
|
1691 fragment="" |
|
3862
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1692 try: |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1693 # make sure cls is a valid tracker classname |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1694 cl = self._db.getclass(cls) |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1695 if not cl.hasnode(id): |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1696 return item |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1697 return replacement % locals() |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1698 except KeyError: |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1699 return item |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1700 |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1701 def _hyper_repl_rst(self, match): |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1702 if match.group('url'): |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1703 s = match.group('url') |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1704 return '`%s <%s>`_'%(s, s) |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1705 elif match.group('email'): |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1706 s = match.group('email') |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1707 return '`%s <mailto:%s>`_'%(s, s) |
|
4288
ce684080e968
issue2550549: Some bugs issue classifiers were causing database lookup errors
Richard Jones <richard@users.sourceforge.net>
parents:
4286
diff
changeset
|
1708 elif len(match.group('id')) < 10: |
|
ce684080e968
issue2550549: Some bugs issue classifiers were causing database lookup errors
Richard Jones <richard@users.sourceforge.net>
parents:
4286
diff
changeset
|
1709 return self._hyper_repl_item(match,'`%(item)s <%(cls)s%(id)s>`_') |
|
3862
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1710 else: |
|
4288
ce684080e968
issue2550549: Some bugs issue classifiers were causing database lookup errors
Richard Jones <richard@users.sourceforge.net>
parents:
4286
diff
changeset
|
1711 # just return the matched text |
|
ce684080e968
issue2550549: Some bugs issue classifiers were causing database lookup errors
Richard Jones <richard@users.sourceforge.net>
parents:
4286
diff
changeset
|
1712 return match.group(0) |
|
1336
6a54b51b1784
hyperlinking of special message text
Richard Jones <richard@users.sourceforge.net>
parents:
1332
diff
changeset
|
1713 |
|
6097
90a1470edbea
added markdown rendering support using either markdown2 or markdown
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6095
diff
changeset
|
1714 def _hyper_repl_markdown(self, match): |
|
6280
6ed5152a92d0
issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents:
6279
diff
changeset
|
1715 for group in ['url', 'email']: |
|
6ed5152a92d0
issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents:
6279
diff
changeset
|
1716 if match.group(group): |
|
6ed5152a92d0
issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents:
6279
diff
changeset
|
1717 start = match.start(group) - 1 |
|
6ed5152a92d0
issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents:
6279
diff
changeset
|
1718 end = match.end(group) |
|
6ed5152a92d0
issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents:
6279
diff
changeset
|
1719 if start >= 0: |
|
6ed5152a92d0
issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents:
6279
diff
changeset
|
1720 prefix = match.string[start] |
|
6ed5152a92d0
issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents:
6279
diff
changeset
|
1721 if end < len(match.string): |
|
6ed5152a92d0
issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents:
6279
diff
changeset
|
1722 suffix = match.string[end] |
|
6ed5152a92d0
issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents:
6279
diff
changeset
|
1723 if (prefix, suffix) in { |
|
6ed5152a92d0
issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents:
6279
diff
changeset
|
1724 ('<', '>'), |
|
6ed5152a92d0
issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents:
6279
diff
changeset
|
1725 ('(', ')'), |
|
6ed5152a92d0
issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents:
6279
diff
changeset
|
1726 }: |
|
6ed5152a92d0
issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents:
6279
diff
changeset
|
1727 continue |
|
6299
fd0bdcbc68e4
issue2551104 - fix issue with markdown autolink next to punctuation
John Rouillard <rouilj@ieee.org>
parents:
6284
diff
changeset
|
1728 if prefix == '(' and ')' in match.group(group): |
|
6280
6ed5152a92d0
issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents:
6279
diff
changeset
|
1729 continue |
|
6ed5152a92d0
issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents:
6279
diff
changeset
|
1730 s = match.group(group) |
|
6ed5152a92d0
issue2551096 - enable markdown autolink for email and bare url's.
John Rouillard <rouilj@ieee.org>
parents:
6279
diff
changeset
|
1731 return '<%s>' % s |
|
6104
a1fd9551d416
don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6103
diff
changeset
|
1732 if match.group('id') and len(match.group('id')) < 10: |
|
6336
6f89cdc7c938
issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents:
6299
diff
changeset
|
1733 # Pass through markdown style links: |
|
6f89cdc7c938
issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents:
6299
diff
changeset
|
1734 # [issue1](https://....) |
|
6f89cdc7c938
issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents:
6299
diff
changeset
|
1735 # [issue1](issue1) |
|
6f89cdc7c938
issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents:
6299
diff
changeset
|
1736 # as 'issue1'. Don't convert issue1 into a link. |
|
6f89cdc7c938
issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents:
6299
diff
changeset
|
1737 # https://issues.roundup-tracker.org/issue2551108 |
|
6f89cdc7c938
issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents:
6299
diff
changeset
|
1738 start = match.start('item') - 1 |
|
6f89cdc7c938
issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents:
6299
diff
changeset
|
1739 end = match.end('item') |
|
6f89cdc7c938
issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents:
6299
diff
changeset
|
1740 if start >= 0: |
|
6f89cdc7c938
issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents:
6299
diff
changeset
|
1741 prefix = match.string[start] |
|
6f89cdc7c938
issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents:
6299
diff
changeset
|
1742 if end < len(match.string): |
|
6f89cdc7c938
issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents:
6299
diff
changeset
|
1743 suffix = match.string[end] |
|
6f89cdc7c938
issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents:
6299
diff
changeset
|
1744 if (prefix, suffix) in {('[', ']')}: |
|
7022
f4bfc1af5d95
flake8 inline comment spacing; too many leading #
John Rouillard <rouilj@ieee.org>
parents:
7021
diff
changeset
|
1745 if match.string[end+1] == '(': # find following ( |
|
6336
6f89cdc7c938
issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents:
6299
diff
changeset
|
1746 return match.group(0) |
|
6f89cdc7c938
issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents:
6299
diff
changeset
|
1747 if (prefix, suffix) in {('(',')')}: |
|
6f89cdc7c938
issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents:
6299
diff
changeset
|
1748 if match.string[start-1] == ']': |
|
6f89cdc7c938
issue2551108 - fix markdown formatted designator links
John Rouillard <rouilj@ieee.org>
parents:
6299
diff
changeset
|
1749 return match.group(0) |
|
6097
90a1470edbea
added markdown rendering support using either markdown2 or markdown
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6095
diff
changeset
|
1750 return self._hyper_repl_item(match,'[%(item)s](%(cls)s%(id)s)') |
|
90a1470edbea
added markdown rendering support using either markdown2 or markdown
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6095
diff
changeset
|
1751 else: |
|
90a1470edbea
added markdown rendering support using either markdown2 or markdown
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6095
diff
changeset
|
1752 # just return the matched text |
|
90a1470edbea
added markdown rendering support using either markdown2 or markdown
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6095
diff
changeset
|
1753 return match.group(0) |
|
90a1470edbea
added markdown rendering support using either markdown2 or markdown
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6095
diff
changeset
|
1754 |
|
5156
882fa4d9bead
issue2550795: @dispname query args in page.html search links
John Rouillard <rouilj@ieee.org>
parents:
5146
diff
changeset
|
1755 def url_quote(self): |
|
882fa4d9bead
issue2550795: @dispname query args in page.html search links
John Rouillard <rouilj@ieee.org>
parents:
5146
diff
changeset
|
1756 """ Return the string in plain format but escaped for use in a url """ |
|
5402
88dbacd11cd1
Python 3 preparation: update urllib / urllib2 / urlparse imports.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5399
diff
changeset
|
1757 return urllib_.quote(self.plain()) |
|
5156
882fa4d9bead
issue2550795: @dispname query args in page.html search links
John Rouillard <rouilj@ieee.org>
parents:
5146
diff
changeset
|
1758 |
|
1773
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1759 def hyperlinked(self): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1760 """ Render a "hyperlinked" version of the text """ |
|
1773
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1761 return self.plain(hyperlink=1) |
|
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1762 |
|
1374
8e4c3e8de96f
fix StringHTMLProperty hyperlinking
Richard Jones <richard@users.sourceforge.net>
parents:
1370
diff
changeset
|
1763 def plain(self, escape=0, hyperlink=0): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1764 """Render a "plain" representation of the property |
|
2327
36ae1b14aaab
remove excessive spaces in the translatable strings;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2324
diff
changeset
|
1765 |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
1766 - "escape" turns on/off HTML quoting |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
1767 - "hyperlink" turns on/off in-text hyperlinking of URLs, email |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
1768 addresses and designators |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1769 """ |
|
3117
460eb0209a9e
Permissions improvements.
Richard Jones <richard@users.sourceforge.net>
parents:
3104
diff
changeset
|
1770 if not self.is_view_ok(): |
|
3164
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
1771 return self._('[hidden]') |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
1772 |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
1773 if self._value is None: |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1774 return '' |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1775 if escape: |
|
5800
1a835db41674
Call cgi.escape only on python 2. Replace with html.escapeif it can be
John Rouillard <rouilj@ieee.org>
parents:
5684
diff
changeset
|
1776 s = html_escape(str(self._value)) |
|
1336
6a54b51b1784
hyperlinking of special message text
Richard Jones <richard@users.sourceforge.net>
parents:
1332
diff
changeset
|
1777 else: |
|
1374
8e4c3e8de96f
fix StringHTMLProperty hyperlinking
Richard Jones <richard@users.sourceforge.net>
parents:
1370
diff
changeset
|
1778 s = str(self._value) |
|
1336
6a54b51b1784
hyperlinking of special message text
Richard Jones <richard@users.sourceforge.net>
parents:
1332
diff
changeset
|
1779 if hyperlink: |
|
1773
5f15fb95180c
various cosmetic fixes
Richard Jones <richard@users.sourceforge.net>
parents:
1771
diff
changeset
|
1780 # no, we *must* escape this text |
|
1374
8e4c3e8de96f
fix StringHTMLProperty hyperlinking
Richard Jones <richard@users.sourceforge.net>
parents:
1370
diff
changeset
|
1781 if not escape: |
|
5800
1a835db41674
Call cgi.escape only on python 2. Replace with html.escapeif it can be
John Rouillard <rouilj@ieee.org>
parents:
5684
diff
changeset
|
1782 s = html_escape(s) |
|
1394
d5314bfab0c0
fix incorrect hyperlinking markup
Richard Jones <richard@users.sourceforge.net>
parents:
1374
diff
changeset
|
1783 s = self.hyper_re.sub(self._hyper_repl, s) |
|
1336
6a54b51b1784
hyperlinking of special message text
Richard Jones <richard@users.sourceforge.net>
parents:
1332
diff
changeset
|
1784 return s |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1785 |
|
3644
f35ece8f8ff7
added StringHTMLProperty wrapped() method to wrap long lines in issue display
Richard Jones <richard@users.sourceforge.net>
parents:
3635
diff
changeset
|
1786 def wrapped(self, escape=1, hyperlink=1): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1787 """Render a "wrapped" representation of the property. |
|
3644
f35ece8f8ff7
added StringHTMLProperty wrapped() method to wrap long lines in issue display
Richard Jones <richard@users.sourceforge.net>
parents:
3635
diff
changeset
|
1788 |
|
f35ece8f8ff7
added StringHTMLProperty wrapped() method to wrap long lines in issue display
Richard Jones <richard@users.sourceforge.net>
parents:
3635
diff
changeset
|
1789 We wrap long lines at 80 columns on the nearest whitespace. Lines |
|
f35ece8f8ff7
added StringHTMLProperty wrapped() method to wrap long lines in issue display
Richard Jones <richard@users.sourceforge.net>
parents:
3635
diff
changeset
|
1790 with no whitespace are not broken to force wrapping. |
|
f35ece8f8ff7
added StringHTMLProperty wrapped() method to wrap long lines in issue display
Richard Jones <richard@users.sourceforge.net>
parents:
3635
diff
changeset
|
1791 |
|
f35ece8f8ff7
added StringHTMLProperty wrapped() method to wrap long lines in issue display
Richard Jones <richard@users.sourceforge.net>
parents:
3635
diff
changeset
|
1792 Note that unlike plain() we default wrapped() to have the escaping |
|
f35ece8f8ff7
added StringHTMLProperty wrapped() method to wrap long lines in issue display
Richard Jones <richard@users.sourceforge.net>
parents:
3635
diff
changeset
|
1793 and hyperlinking turned on since that's the most common usage. |
|
f35ece8f8ff7
added StringHTMLProperty wrapped() method to wrap long lines in issue display
Richard Jones <richard@users.sourceforge.net>
parents:
3635
diff
changeset
|
1794 |
|
f35ece8f8ff7
added StringHTMLProperty wrapped() method to wrap long lines in issue display
Richard Jones <richard@users.sourceforge.net>
parents:
3635
diff
changeset
|
1795 - "escape" turns on/off HTML quoting |
|
f35ece8f8ff7
added StringHTMLProperty wrapped() method to wrap long lines in issue display
Richard Jones <richard@users.sourceforge.net>
parents:
3635
diff
changeset
|
1796 - "hyperlink" turns on/off in-text hyperlinking of URLs, email |
|
f35ece8f8ff7
added StringHTMLProperty wrapped() method to wrap long lines in issue display
Richard Jones <richard@users.sourceforge.net>
parents:
3635
diff
changeset
|
1797 addresses and designators |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1798 """ |
|
3644
f35ece8f8ff7
added StringHTMLProperty wrapped() method to wrap long lines in issue display
Richard Jones <richard@users.sourceforge.net>
parents:
3635
diff
changeset
|
1799 if not self.is_view_ok(): |
|
f35ece8f8ff7
added StringHTMLProperty wrapped() method to wrap long lines in issue display
Richard Jones <richard@users.sourceforge.net>
parents:
3635
diff
changeset
|
1800 return self._('[hidden]') |
|
f35ece8f8ff7
added StringHTMLProperty wrapped() method to wrap long lines in issue display
Richard Jones <richard@users.sourceforge.net>
parents:
3635
diff
changeset
|
1801 |
|
f35ece8f8ff7
added StringHTMLProperty wrapped() method to wrap long lines in issue display
Richard Jones <richard@users.sourceforge.net>
parents:
3635
diff
changeset
|
1802 if self._value is None: |
|
f35ece8f8ff7
added StringHTMLProperty wrapped() method to wrap long lines in issue display
Richard Jones <richard@users.sourceforge.net>
parents:
3635
diff
changeset
|
1803 return '' |
|
5043
ac0c117cd24c
Remove wrap and associated functions from roundup.support
John Kristensen <john@jerrykan.com>
parents:
5006
diff
changeset
|
1804 s = '\n'.join(textwrap.wrap(str(self._value), 80)) |
|
3644
f35ece8f8ff7
added StringHTMLProperty wrapped() method to wrap long lines in issue display
Richard Jones <richard@users.sourceforge.net>
parents:
3635
diff
changeset
|
1805 if escape: |
|
5800
1a835db41674
Call cgi.escape only on python 2. Replace with html.escapeif it can be
John Rouillard <rouilj@ieee.org>
parents:
5684
diff
changeset
|
1806 s = html_escape(s) |
|
3644
f35ece8f8ff7
added StringHTMLProperty wrapped() method to wrap long lines in issue display
Richard Jones <richard@users.sourceforge.net>
parents:
3635
diff
changeset
|
1807 if hyperlink: |
|
f35ece8f8ff7
added StringHTMLProperty wrapped() method to wrap long lines in issue display
Richard Jones <richard@users.sourceforge.net>
parents:
3635
diff
changeset
|
1808 # no, we *must* escape this text |
|
f35ece8f8ff7
added StringHTMLProperty wrapped() method to wrap long lines in issue display
Richard Jones <richard@users.sourceforge.net>
parents:
3635
diff
changeset
|
1809 if not escape: |
|
5800
1a835db41674
Call cgi.escape only on python 2. Replace with html.escapeif it can be
John Rouillard <rouilj@ieee.org>
parents:
5684
diff
changeset
|
1810 s = html_escape(s) |
|
3644
f35ece8f8ff7
added StringHTMLProperty wrapped() method to wrap long lines in issue display
Richard Jones <richard@users.sourceforge.net>
parents:
3635
diff
changeset
|
1811 s = self.hyper_re.sub(self._hyper_repl, s) |
|
f35ece8f8ff7
added StringHTMLProperty wrapped() method to wrap long lines in issue display
Richard Jones <richard@users.sourceforge.net>
parents:
3635
diff
changeset
|
1812 return s |
|
f35ece8f8ff7
added StringHTMLProperty wrapped() method to wrap long lines in issue display
Richard Jones <richard@users.sourceforge.net>
parents:
3635
diff
changeset
|
1813 |
|
3509
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
1814 def stext(self, escape=0, hyperlink=1): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1815 """ Render the value of the property as StructuredText. |
|
1123
644d3075c2df
more documentation, fixed bug in request/description
Richard Jones <richard@users.sourceforge.net>
parents:
1122
diff
changeset
|
1816 |
|
644d3075c2df
more documentation, fixed bug in request/description
Richard Jones <richard@users.sourceforge.net>
parents:
1122
diff
changeset
|
1817 This requires the StructureText module to be installed separately. |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1818 """ |
|
3117
460eb0209a9e
Permissions improvements.
Richard Jones <richard@users.sourceforge.net>
parents:
3104
diff
changeset
|
1819 if not self.is_view_ok(): |
|
3164
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
1820 return self._('[hidden]') |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
1821 |
|
3509
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
1822 s = self.plain(escape=escape, hyperlink=hyperlink) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1823 if not StructuredText: |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1824 return s |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1825 return StructuredText(s,level=1,header=0) |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1826 |
|
3862
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1827 def rst(self, hyperlink=1): |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1828 """ Render the value of the property as ReStructuredText. |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1829 |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1830 This requires docutils to be installed separately. |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1831 """ |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1832 if not self.is_view_ok(): |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1833 return self._('[hidden]') |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1834 |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1835 if not ReStructuredText: |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1836 return self.plain(escape=0, hyperlink=hyperlink) |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1837 s = self.plain(escape=0, hyperlink=0) |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1838 if hyperlink: |
|
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1839 s = self.hyper_re.sub(self._hyper_repl_rst, s) |
|
6103
af16c135fb98
url's with javascript scheme should not be links in reST
John Rouillard <rouilj@ieee.org>
parents:
6102
diff
changeset
|
1840 |
|
af16c135fb98
url's with javascript scheme should not be links in reST
John Rouillard <rouilj@ieee.org>
parents:
6102
diff
changeset
|
1841 # disable javascript and possibly other url schemes from working |
|
af16c135fb98
url's with javascript scheme should not be links in reST
John Rouillard <rouilj@ieee.org>
parents:
6102
diff
changeset
|
1842 from docutils.utils.urischemes import schemes |
|
6104
a1fd9551d416
don't allow javascript URLs in markdown content
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6103
diff
changeset
|
1843 for sch in _disable_url_schemes: |
|
6103
af16c135fb98
url's with javascript scheme should not be links in reST
John Rouillard <rouilj@ieee.org>
parents:
6102
diff
changeset
|
1844 # I catch KeyError but reraise if scheme didn't exist. |
|
af16c135fb98
url's with javascript scheme should not be links in reST
John Rouillard <rouilj@ieee.org>
parents:
6102
diff
changeset
|
1845 # Safer to fail if a disabled scheme isn't found. It may |
|
af16c135fb98
url's with javascript scheme should not be links in reST
John Rouillard <rouilj@ieee.org>
parents:
6102
diff
changeset
|
1846 # be a typo that keeps a bad scheme enabled. But this |
|
af16c135fb98
url's with javascript scheme should not be links in reST
John Rouillard <rouilj@ieee.org>
parents:
6102
diff
changeset
|
1847 # function can be called multiple times. On the first call |
|
af16c135fb98
url's with javascript scheme should not be links in reST
John Rouillard <rouilj@ieee.org>
parents:
6102
diff
changeset
|
1848 # the key will be deleted. On the second call the schemes |
|
af16c135fb98
url's with javascript scheme should not be links in reST
John Rouillard <rouilj@ieee.org>
parents:
6102
diff
changeset
|
1849 # variable isn't re-initialized so the key is missing |
|
af16c135fb98
url's with javascript scheme should not be links in reST
John Rouillard <rouilj@ieee.org>
parents:
6102
diff
changeset
|
1850 # causing a KeyError. So see if we removed it (and entered |
|
af16c135fb98
url's with javascript scheme should not be links in reST
John Rouillard <rouilj@ieee.org>
parents:
6102
diff
changeset
|
1851 # it into valid_schemes). If we didn't raise KeyError. |
|
af16c135fb98
url's with javascript scheme should not be links in reST
John Rouillard <rouilj@ieee.org>
parents:
6102
diff
changeset
|
1852 try: |
|
af16c135fb98
url's with javascript scheme should not be links in reST
John Rouillard <rouilj@ieee.org>
parents:
6102
diff
changeset
|
1853 del(schemes[sch]) |
|
af16c135fb98
url's with javascript scheme should not be links in reST
John Rouillard <rouilj@ieee.org>
parents:
6102
diff
changeset
|
1854 self.valid_schemes[sch] = True |
|
af16c135fb98
url's with javascript scheme should not be links in reST
John Rouillard <rouilj@ieee.org>
parents:
6102
diff
changeset
|
1855 except KeyError: |
|
af16c135fb98
url's with javascript scheme should not be links in reST
John Rouillard <rouilj@ieee.org>
parents:
6102
diff
changeset
|
1856 if sch in self.valid_schemes: |
|
af16c135fb98
url's with javascript scheme should not be links in reST
John Rouillard <rouilj@ieee.org>
parents:
6102
diff
changeset
|
1857 pass |
|
af16c135fb98
url's with javascript scheme should not be links in reST
John Rouillard <rouilj@ieee.org>
parents:
6102
diff
changeset
|
1858 else: |
|
af16c135fb98
url's with javascript scheme should not be links in reST
John Rouillard <rouilj@ieee.org>
parents:
6102
diff
changeset
|
1859 raise |
|
7019
e1528860e591
flake8 remove space from blank lines W293
John Rouillard <rouilj@ieee.org>
parents:
7018
diff
changeset
|
1860 |
|
6098
72a281a55a17
Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents:
6097
diff
changeset
|
1861 return u2s(ReStructuredText(s, writer_name="html", |
|
72a281a55a17
Disable rst raw and include directives.
John Rouillard <rouilj@ieee.org>
parents:
6097
diff
changeset
|
1862 settings_overrides=self.rst_defaults)["html_body"]) |
|
3862
b052820e86bf
Add a rst method to StringHTMLProperty...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3861
diff
changeset
|
1863 |
|
6097
90a1470edbea
added markdown rendering support using either markdown2 or markdown
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6095
diff
changeset
|
1864 def markdown(self, hyperlink=1): |
|
90a1470edbea
added markdown rendering support using either markdown2 or markdown
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6095
diff
changeset
|
1865 """ Render the value of the property as markdown. |
|
90a1470edbea
added markdown rendering support using either markdown2 or markdown
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6095
diff
changeset
|
1866 |
|
90a1470edbea
added markdown rendering support using either markdown2 or markdown
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6095
diff
changeset
|
1867 This requires markdown2 or markdown to be installed separately. |
|
90a1470edbea
added markdown rendering support using either markdown2 or markdown
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6095
diff
changeset
|
1868 """ |
|
90a1470edbea
added markdown rendering support using either markdown2 or markdown
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6095
diff
changeset
|
1869 if not self.is_view_ok(): |
|
90a1470edbea
added markdown rendering support using either markdown2 or markdown
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6095
diff
changeset
|
1870 return self._('[hidden]') |
|
90a1470edbea
added markdown rendering support using either markdown2 or markdown
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6095
diff
changeset
|
1871 |
|
90a1470edbea
added markdown rendering support using either markdown2 or markdown
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6095
diff
changeset
|
1872 if not markdown: |
|
90a1470edbea
added markdown rendering support using either markdown2 or markdown
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6095
diff
changeset
|
1873 return self.plain(escape=0, hyperlink=hyperlink) |
|
90a1470edbea
added markdown rendering support using either markdown2 or markdown
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6095
diff
changeset
|
1874 s = self.plain(escape=0, hyperlink=0) |
|
90a1470edbea
added markdown rendering support using either markdown2 or markdown
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6095
diff
changeset
|
1875 if hyperlink: |
|
90a1470edbea
added markdown rendering support using either markdown2 or markdown
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6095
diff
changeset
|
1876 s = self.hyper_re.sub(self._hyper_repl_markdown, s) |
|
6275
bda491248fd8
Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents:
6215
diff
changeset
|
1877 try: |
|
6277
957a0fc20021
issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents:
6275
diff
changeset
|
1878 s = u2s(markdown(s2u(s), self._db.config)) |
|
6275
bda491248fd8
Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents:
6215
diff
changeset
|
1879 except Exception: # when markdown formatting fails return markup |
|
bda491248fd8
Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents:
6215
diff
changeset
|
1880 return self.plain(escape=0, hyperlink=hyperlink) |
|
bda491248fd8
Handle exception raised from markdown processing
John Rouillard <rouilj@ieee.org>
parents:
6215
diff
changeset
|
1881 return s |
|
6097
90a1470edbea
added markdown rendering support using either markdown2 or markdown
Christof Meerwald <cmeerw@cmeerw.org>
parents:
6095
diff
changeset
|
1882 |
|
3509
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
1883 def field(self, **kwargs): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1884 """ Render the property as a field in HTML. |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
1885 |
|
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
1886 If not editable, just display the value via plain(). |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1887 """ |
|
3040
14322134dcef
fix permissions checks in cgi templating [SF#1082755]
Richard Jones <richard@users.sourceforge.net>
parents:
3006
diff
changeset
|
1888 if not self.is_edit_ok(): |
|
3971
ff3a8b7d1819
security fixes
Richard Jones <richard@users.sourceforge.net>
parents:
3968
diff
changeset
|
1889 return self.plain(escape=1) |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
1890 |
|
3782
51c07c04d258
clean up input field generation and quoting of values [SF#1615616]
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
1891 value = self._value |
|
51c07c04d258
clean up input field generation and quoting of values [SF#1615616]
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
1892 if value is None: |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1893 value = '' |
|
3509
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
1894 |
|
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
1895 kwargs.setdefault("size", 30) |
|
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
1896 kwargs.update({"name": self._formname, "value": value}) |
|
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
1897 return self.input(**kwargs) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1898 |
|
3905
6733a7cce7f4
multiline pass through extra keywords args
Justus Pendleton <jpend@users.sourceforge.net>
parents:
3903
diff
changeset
|
1899 def multiline(self, escape=0, rows=5, cols=40, **kwargs): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1900 """ Render a multiline form edit field for the property. |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
1901 |
|
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
1902 If not editable, just display the plain() value in a <pre> tag. |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1903 """ |
|
3040
14322134dcef
fix permissions checks in cgi templating [SF#1082755]
Richard Jones <richard@users.sourceforge.net>
parents:
3006
diff
changeset
|
1904 if not self.is_edit_ok(): |
|
14322134dcef
fix permissions checks in cgi templating [SF#1082755]
Richard Jones <richard@users.sourceforge.net>
parents:
3006
diff
changeset
|
1905 return '<pre>%s</pre>'%self.plain() |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
1906 |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
1907 if self._value is None: |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1908 value = '' |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1909 else: |
|
5800
1a835db41674
Call cgi.escape only on python 2. Replace with html.escapeif it can be
John Rouillard <rouilj@ieee.org>
parents:
5684
diff
changeset
|
1910 value = html_escape(str(self._value)) |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
1911 |
|
3710
2862cb0d9be4
default attributes for input fields:
Tobias Herp <tobias-herp@users.sourceforge.net>
parents:
3702
diff
changeset
|
1912 value = '"'.join(value.split('"')) |
|
2862cb0d9be4
default attributes for input fields:
Tobias Herp <tobias-herp@users.sourceforge.net>
parents:
3702
diff
changeset
|
1913 name = self._formname |
|
5988
39b8bc511ed7
Fix html generation errors for boolean options.
John Rouillard <rouilj@ieee.org>
parents:
5973
diff
changeset
|
1914 passthrough_args = self.cgi_escape_attrs(**kwargs) |
|
3905
6733a7cce7f4
multiline pass through extra keywords args
Justus Pendleton <jpend@users.sourceforge.net>
parents:
3903
diff
changeset
|
1915 return ('<textarea %(passthrough_args)s name="%(name)s" id="%(name)s"' |
|
3710
2862cb0d9be4
default attributes for input fields:
Tobias Herp <tobias-herp@users.sourceforge.net>
parents:
3702
diff
changeset
|
1916 ' rows="%(rows)s" cols="%(cols)s">' |
|
2862cb0d9be4
default attributes for input fields:
Tobias Herp <tobias-herp@users.sourceforge.net>
parents:
3702
diff
changeset
|
1917 '%(value)s</textarea>') % locals() |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1918 |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1919 def email(self, escape=1): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1920 """ Render the value of the property as an obscured email address |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1921 """ |
|
3117
460eb0209a9e
Permissions improvements.
Richard Jones <richard@users.sourceforge.net>
parents:
3104
diff
changeset
|
1922 if not self.is_view_ok(): |
|
3164
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
1923 return self._('[hidden]') |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
1924 |
|
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
1925 if self._value is None: |
|
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
1926 value = '' |
|
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
1927 else: |
|
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
1928 value = str(self._value) |
|
3573
d7bab396c228
email obfuscation code in html templating is more robust
Richard Jones <richard@users.sourceforge.net>
parents:
3565
diff
changeset
|
1929 split = value.split('@') |
|
d7bab396c228
email obfuscation code in html templating is more robust
Richard Jones <richard@users.sourceforge.net>
parents:
3565
diff
changeset
|
1930 if len(split) == 2: |
|
d7bab396c228
email obfuscation code in html templating is more robust
Richard Jones <richard@users.sourceforge.net>
parents:
3565
diff
changeset
|
1931 name, domain = split |
|
1133
36ec30d286ea
Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents:
1124
diff
changeset
|
1932 domain = ' '.join(domain.split('.')[:-1]) |
|
36ec30d286ea
Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents:
1124
diff
changeset
|
1933 name = name.replace('.', ' ') |
|
36ec30d286ea
Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents:
1124
diff
changeset
|
1934 value = '%s at %s ...'%(name, domain) |
|
36ec30d286ea
Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents:
1124
diff
changeset
|
1935 else: |
|
36ec30d286ea
Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents:
1124
diff
changeset
|
1936 value = value.replace('.', ' ') |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1937 if escape: |
|
5800
1a835db41674
Call cgi.escape only on python 2. Replace with html.escapeif it can be
John Rouillard <rouilj@ieee.org>
parents:
5684
diff
changeset
|
1938 value = html_escape(value) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1939 return value |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1940 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
1941 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1942 class PasswordHTMLProperty(HTMLProperty): |
|
3971
ff3a8b7d1819
security fixes
Richard Jones <richard@users.sourceforge.net>
parents:
3968
diff
changeset
|
1943 def plain(self, escape=0): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1944 """ Render a "plain" representation of the property |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1945 """ |
|
3117
460eb0209a9e
Permissions improvements.
Richard Jones <richard@users.sourceforge.net>
parents:
3104
diff
changeset
|
1946 if not self.is_view_ok(): |
|
3164
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
1947 return self._('[hidden]') |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
1948 |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
1949 if self._value is None: |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1950 return '' |
|
5182
dc657fbbc790
- issue2550933 - Fix Traceback in cgi/templating.py when a string is
John Rouillard <rouilj@ieee.org>
parents:
5180
diff
changeset
|
1951 try: |
|
dc657fbbc790
- issue2550933 - Fix Traceback in cgi/templating.py when a string is
John Rouillard <rouilj@ieee.org>
parents:
5180
diff
changeset
|
1952 value = self._value.dummystr() |
|
dc657fbbc790
- issue2550933 - Fix Traceback in cgi/templating.py when a string is
John Rouillard <rouilj@ieee.org>
parents:
5180
diff
changeset
|
1953 except AttributeError: |
|
dc657fbbc790
- issue2550933 - Fix Traceback in cgi/templating.py when a string is
John Rouillard <rouilj@ieee.org>
parents:
5180
diff
changeset
|
1954 value = self._('[hidden]') |
|
4483
22bc0426e348
Second patch from issue2550688 -- with some changes:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4481
diff
changeset
|
1955 if escape: |
|
5800
1a835db41674
Call cgi.escape only on python 2. Replace with html.escapeif it can be
John Rouillard <rouilj@ieee.org>
parents:
5684
diff
changeset
|
1956 value = html_escape(value) |
|
4483
22bc0426e348
Second patch from issue2550688 -- with some changes:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4481
diff
changeset
|
1957 return value |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1958 |
|
4267
c5f52c2c9e36
Provide ability to specify arbitrary HTML attributes.
Stefan Seefeld <stefan@seefeld.name>
parents:
4233
diff
changeset
|
1959 def field(self, size=30, **kwargs): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1960 """ Render a form edit field for the property. |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
1961 |
|
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
1962 If not editable, just display the value via plain(). |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1963 """ |
|
3040
14322134dcef
fix permissions checks in cgi templating [SF#1082755]
Richard Jones <richard@users.sourceforge.net>
parents:
3006
diff
changeset
|
1964 if not self.is_edit_ok(): |
|
3971
ff3a8b7d1819
security fixes
Richard Jones <richard@users.sourceforge.net>
parents:
3968
diff
changeset
|
1965 return self.plain(escape=1) |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
1966 |
|
4267
c5f52c2c9e36
Provide ability to specify arbitrary HTML attributes.
Stefan Seefeld <stefan@seefeld.name>
parents:
4233
diff
changeset
|
1967 return self.input(type="password", name=self._formname, size=size, |
|
c5f52c2c9e36
Provide ability to specify arbitrary HTML attributes.
Stefan Seefeld <stefan@seefeld.name>
parents:
4233
diff
changeset
|
1968 **kwargs) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1969 |
|
3710
2862cb0d9be4
default attributes for input fields:
Tobias Herp <tobias-herp@users.sourceforge.net>
parents:
3702
diff
changeset
|
1970 def confirm(self, size=30): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1971 """ Render a second form edit field for the property, used for |
|
1144
db13f46cb5f9
password edit now has a confirmation field
Richard Jones <richard@users.sourceforge.net>
parents:
1136
diff
changeset
|
1972 confirmation that the user typed the password correctly. Generates |
|
1911
f5c804379c85
fixed ZRoundup - mostly changes to classic template
Richard Jones <richard@users.sourceforge.net>
parents:
1857
diff
changeset
|
1973 a field with name "@confirm@name". |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
1974 |
|
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
1975 If not editable, display nothing. |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1976 """ |
|
3040
14322134dcef
fix permissions checks in cgi templating [SF#1082755]
Richard Jones <richard@users.sourceforge.net>
parents:
3006
diff
changeset
|
1977 if not self.is_edit_ok(): |
|
14322134dcef
fix permissions checks in cgi templating [SF#1082755]
Richard Jones <richard@users.sourceforge.net>
parents:
3006
diff
changeset
|
1978 return '' |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
1979 |
|
3040
14322134dcef
fix permissions checks in cgi templating [SF#1082755]
Richard Jones <richard@users.sourceforge.net>
parents:
3006
diff
changeset
|
1980 return self.input(type="password", |
|
3710
2862cb0d9be4
default attributes for input fields:
Tobias Herp <tobias-herp@users.sourceforge.net>
parents:
3702
diff
changeset
|
1981 name="@confirm@%s"%self._formname, |
|
2862cb0d9be4
default attributes for input fields:
Tobias Herp <tobias-herp@users.sourceforge.net>
parents:
3702
diff
changeset
|
1982 id="%s-confirm"%self._formname, |
|
2862cb0d9be4
default attributes for input fields:
Tobias Herp <tobias-herp@users.sourceforge.net>
parents:
3702
diff
changeset
|
1983 size=size) |
|
1144
db13f46cb5f9
password edit now has a confirmation field
Richard Jones <richard@users.sourceforge.net>
parents:
1136
diff
changeset
|
1984 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
1985 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1986 class NumberHTMLProperty(HTMLProperty): |
|
3971
ff3a8b7d1819
security fixes
Richard Jones <richard@users.sourceforge.net>
parents:
3968
diff
changeset
|
1987 def plain(self, escape=0): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1988 """ Render a "plain" representation of the property |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
1989 """ |
|
3117
460eb0209a9e
Permissions improvements.
Richard Jones <richard@users.sourceforge.net>
parents:
3104
diff
changeset
|
1990 if not self.is_view_ok(): |
|
3164
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
1991 return self._('[hidden]') |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
1992 |
|
2884
6d6fdd1daf92
NumberHTMLProperty should return "" not "None" if not set
Richard Jones <richard@users.sourceforge.net>
parents:
2883
diff
changeset
|
1993 if self._value is None: |
|
6d6fdd1daf92
NumberHTMLProperty should return "" not "None" if not set
Richard Jones <richard@users.sourceforge.net>
parents:
2883
diff
changeset
|
1994 return '' |
|
6d6fdd1daf92
NumberHTMLProperty should return "" not "None" if not set
Richard Jones <richard@users.sourceforge.net>
parents:
2883
diff
changeset
|
1995 |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
1996 return str(self._value) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1997 |
|
6832
234fefd7568a
issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents:
6823
diff
changeset
|
1998 def pretty(self, format="%0.3f"): |
|
234fefd7568a
issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents:
6823
diff
changeset
|
1999 '''Pretty print number using printf format specifier. |
|
7019
e1528860e591
flake8 remove space from blank lines W293
John Rouillard <rouilj@ieee.org>
parents:
7018
diff
changeset
|
2000 |
|
6832
234fefd7568a
issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents:
6823
diff
changeset
|
2001 If value is not convertable, returns str(_value) or "" |
|
234fefd7568a
issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents:
6823
diff
changeset
|
2002 if None. |
|
234fefd7568a
issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents:
6823
diff
changeset
|
2003 ''' |
|
234fefd7568a
issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents:
6823
diff
changeset
|
2004 try: |
|
234fefd7568a
issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents:
6823
diff
changeset
|
2005 return format%self._value |
|
234fefd7568a
issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents:
6823
diff
changeset
|
2006 except TypeError: |
|
234fefd7568a
issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents:
6823
diff
changeset
|
2007 value = self._value |
|
234fefd7568a
issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents:
6823
diff
changeset
|
2008 if value is None: |
|
234fefd7568a
issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents:
6823
diff
changeset
|
2009 return '' |
|
234fefd7568a
issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents:
6823
diff
changeset
|
2010 else: |
|
234fefd7568a
issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents:
6823
diff
changeset
|
2011 return str(value) |
|
234fefd7568a
issue2550559 - Pretty printing / formatting for Number types.
John Rouillard <rouilj@ieee.org>
parents:
6823
diff
changeset
|
2012 |
|
4267
c5f52c2c9e36
Provide ability to specify arbitrary HTML attributes.
Stefan Seefeld <stefan@seefeld.name>
parents:
4233
diff
changeset
|
2013 def field(self, size=30, **kwargs): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2014 """ Render a form edit field for the property. |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2015 |
|
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2016 If not editable, just display the value via plain(). |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2017 """ |
|
3040
14322134dcef
fix permissions checks in cgi templating [SF#1082755]
Richard Jones <richard@users.sourceforge.net>
parents:
3006
diff
changeset
|
2018 if not self.is_edit_ok(): |
|
3971
ff3a8b7d1819
security fixes
Richard Jones <richard@users.sourceforge.net>
parents:
3968
diff
changeset
|
2019 return self.plain(escape=1) |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2020 |
|
3782
51c07c04d258
clean up input field generation and quoting of values [SF#1615616]
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
2021 value = self._value |
|
51c07c04d258
clean up input field generation and quoting of values [SF#1615616]
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
2022 if value is None: |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2023 value = '' |
|
3782
51c07c04d258
clean up input field generation and quoting of values [SF#1615616]
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
2024 |
|
4267
c5f52c2c9e36
Provide ability to specify arbitrary HTML attributes.
Stefan Seefeld <stefan@seefeld.name>
parents:
4233
diff
changeset
|
2025 return self.input(name=self._formname, value=value, size=size, |
|
c5f52c2c9e36
Provide ability to specify arbitrary HTML attributes.
Stefan Seefeld <stefan@seefeld.name>
parents:
4233
diff
changeset
|
2026 **kwargs) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2027 |
|
1518
bb843662b708
basic numeric support for NumberHTMLProperty
Richard Jones <richard@users.sourceforge.net>
parents:
1513
diff
changeset
|
2028 def __int__(self): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2029 """ Return an int of me |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2030 """ |
|
1518
bb843662b708
basic numeric support for NumberHTMLProperty
Richard Jones <richard@users.sourceforge.net>
parents:
1513
diff
changeset
|
2031 return int(self._value) |
|
bb843662b708
basic numeric support for NumberHTMLProperty
Richard Jones <richard@users.sourceforge.net>
parents:
1513
diff
changeset
|
2032 |
|
bb843662b708
basic numeric support for NumberHTMLProperty
Richard Jones <richard@users.sourceforge.net>
parents:
1513
diff
changeset
|
2033 def __float__(self): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2034 """ Return a float of me |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2035 """ |
|
1518
bb843662b708
basic numeric support for NumberHTMLProperty
Richard Jones <richard@users.sourceforge.net>
parents:
1513
diff
changeset
|
2036 return float(self._value) |
|
bb843662b708
basic numeric support for NumberHTMLProperty
Richard Jones <richard@users.sourceforge.net>
parents:
1513
diff
changeset
|
2037 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
2038 |
|
5067
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2039 class IntegerHTMLProperty(HTMLProperty): |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2040 def plain(self, escape=0): |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2041 """ Render a "plain" representation of the property |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2042 """ |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2043 if not self.is_view_ok(): |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2044 return self._('[hidden]') |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2045 |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2046 if self._value is None: |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2047 return '' |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2048 |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2049 return str(self._value) |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2050 |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2051 def field(self, size=30, **kwargs): |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2052 """ Render a form edit field for the property. |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2053 |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2054 If not editable, just display the value via plain(). |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2055 """ |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2056 if not self.is_edit_ok(): |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2057 return self.plain(escape=1) |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2058 |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2059 value = self._value |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2060 if value is None: |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2061 value = '' |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2062 |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2063 return self.input(name=self._formname, value=value, size=size, |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2064 **kwargs) |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2065 |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2066 def __int__(self): |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2067 """ Return an int of me |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2068 """ |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2069 return int(self._value) |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2070 |
|
1518
bb843662b708
basic numeric support for NumberHTMLProperty
Richard Jones <richard@users.sourceforge.net>
parents:
1513
diff
changeset
|
2071 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2072 class BooleanHTMLProperty(HTMLProperty): |
|
3971
ff3a8b7d1819
security fixes
Richard Jones <richard@users.sourceforge.net>
parents:
3968
diff
changeset
|
2073 def plain(self, escape=0): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2074 """ Render a "plain" representation of the property |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2075 """ |
|
3117
460eb0209a9e
Permissions improvements.
Richard Jones <richard@users.sourceforge.net>
parents:
3104
diff
changeset
|
2076 if not self.is_view_ok(): |
|
3164
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
2077 return self._('[hidden]') |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2078 |
|
1289
257f0ab00d50
bugfix in boolean templating
Richard Jones <richard@users.sourceforge.net>
parents:
1284
diff
changeset
|
2079 if self._value is None: |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2080 return '' |
|
3354
201dbcf63a30
use translation for boolean property rendering [SF#1225152]
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3338
diff
changeset
|
2081 return self._value and self._("Yes") or self._("No") |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2082 |
|
4784
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2083 def field(self, labelfirst=False, y_label=None, n_label=None, |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2084 u_label=None, **kwargs): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2085 """ Render a form edit field for the property |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2086 |
|
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2087 If not editable, just display the value via plain(). |
|
4784
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2088 |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2089 In addition to being able to set arbitrary html properties |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2090 using prop=val arguments, the thre arguments: |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2091 |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2092 y_label, n_label, u_label let you control the labels |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2093 associated with the yes, no (and optionally unknown/empty) |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2094 values. |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2095 |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2096 Also the labels can be placed before the radiobuttons by setting |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2097 labelfirst=True. |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2098 """ |
|
2113
30aeb17e5b04
Boolean HTML templating was broken
Richard Jones <richard@users.sourceforge.net>
parents:
2106
diff
changeset
|
2099 if not self.is_edit_ok(): |
|
3971
ff3a8b7d1819
security fixes
Richard Jones <richard@users.sourceforge.net>
parents:
3968
diff
changeset
|
2100 return self.plain(escape=1) |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2101 |
|
3151
6feac4fcf883
Various bug fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
3127
diff
changeset
|
2102 value = self._value |
|
5416
56c9bcdea47f
Python 3 preparation: unicode.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5414
diff
changeset
|
2103 if is_us(value): |
|
3151
6feac4fcf883
Various bug fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
3127
diff
changeset
|
2104 value = value.strip().lower() in ('checked', 'yes', 'true', |
|
6feac4fcf883
Various bug fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
3127
diff
changeset
|
2105 'on', '1') |
|
6feac4fcf883
Various bug fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
3127
diff
changeset
|
2106 |
|
7017
96be63649c92
flake8 fix additional spaces within () and []
John Rouillard <rouilj@ieee.org>
parents:
6856
diff
changeset
|
2107 if (not y_label): |
|
4784
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2108 y_label = '<label class="rblabel" for="%s_%s">'%(self._formname, 'yes') |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2109 y_label += self._('Yes') |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2110 y_label += '</label>' |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2111 |
|
7017
96be63649c92
flake8 fix additional spaces within () and []
John Rouillard <rouilj@ieee.org>
parents:
6856
diff
changeset
|
2112 if (not n_label): |
|
4784
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2113 n_label = '<label class="rblabel" for="%s_%s">'%(self._formname, 'no') |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2114 n_label += self._('No') |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2115 n_label += '</label>' |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2116 |
|
3151
6feac4fcf883
Various bug fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
3127
diff
changeset
|
2117 checked = value and "checked" or "" |
|
6feac4fcf883
Various bug fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
3127
diff
changeset
|
2118 if value: |
|
4784
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2119 y_rb = self.input(type="radio", name=self._formname, value="yes", |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2120 checked="checked", id="%s_%s"%(self._formname, 'yes'), **kwargs) |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2121 |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2122 n_rb =self.input(type="radio", name=self._formname, value="no", |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2123 id="%s_%s"%(self._formname, 'no'), **kwargs) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2124 else: |
|
4784
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2125 y_rb = self.input(type="radio", name=self._formname, value="yes", |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2126 id="%s_%s"%(self._formname, 'yes'), **kwargs) |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2127 |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2128 n_rb = self.input(type="radio", name=self._formname, value="no", |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2129 checked="checked", id="%s_%s"%(self._formname, 'no'), **kwargs) |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2130 |
|
7017
96be63649c92
flake8 fix additional spaces within () and []
John Rouillard <rouilj@ieee.org>
parents:
6856
diff
changeset
|
2131 if (u_label): |
|
7022
f4bfc1af5d95
flake8 inline comment spacing; too many leading #
John Rouillard <rouilj@ieee.org>
parents:
7021
diff
changeset
|
2132 if (u_label is True): # it was set via u_label=True |
|
f4bfc1af5d95
flake8 inline comment spacing; too many leading #
John Rouillard <rouilj@ieee.org>
parents:
7021
diff
changeset
|
2133 u_label = '' # make it empty but a string not boolean |
|
4784
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2134 u_rb = self.input(type="radio", name=self._formname, value="", |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2135 id="%s_%s"%(self._formname, 'unk'), **kwargs) |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2136 else: |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2137 # don't generate a trivalue radiobutton. |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2138 u_label = '' |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2139 u_rb='' |
|
7019
e1528860e591
flake8 remove space from blank lines W293
John Rouillard <rouilj@ieee.org>
parents:
7018
diff
changeset
|
2140 |
|
7017
96be63649c92
flake8 fix additional spaces within () and []
John Rouillard <rouilj@ieee.org>
parents:
6856
diff
changeset
|
2141 if (labelfirst): |
|
4784
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2142 s = u_label + u_rb + y_label + y_rb + n_label + n_rb |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2143 else: |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2144 s = u_label + u_rb +y_rb + y_label + n_rb + n_label |
|
888676704342
issue2550808 BooleanHTMLProperty::field method html needs to be more
John Rouillard <rouilj@ieee.org>
parents:
4783
diff
changeset
|
2145 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2146 return s |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2147 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
2148 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2149 class DateHTMLProperty(HTMLProperty): |
|
2956
4511fd6c5dbf
format parameter for DateHTMLProperty.field() (based on patch [SF#1072834])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2884
diff
changeset
|
2150 |
|
4511fd6c5dbf
format parameter for DateHTMLProperty.field() (based on patch [SF#1072834])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2884
diff
changeset
|
2151 _marker = [] |
|
4511fd6c5dbf
format parameter for DateHTMLProperty.field() (based on patch [SF#1072834])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2884
diff
changeset
|
2152 |
|
2314
7c8d2e9a0566
fix DateHTMLProperty so local() can override user timezone [SF#953678]
Richard Jones <richard@users.sourceforge.net>
parents:
2289
diff
changeset
|
2153 def __init__(self, client, classname, nodeid, prop, name, value, |
|
7c8d2e9a0566
fix DateHTMLProperty so local() can override user timezone [SF#953678]
Richard Jones <richard@users.sourceforge.net>
parents:
2289
diff
changeset
|
2154 anonymous=0, offset=None): |
|
7c8d2e9a0566
fix DateHTMLProperty so local() can override user timezone [SF#953678]
Richard Jones <richard@users.sourceforge.net>
parents:
2289
diff
changeset
|
2155 HTMLProperty.__init__(self, client, classname, nodeid, prop, name, |
|
7c8d2e9a0566
fix DateHTMLProperty so local() can override user timezone [SF#953678]
Richard Jones <richard@users.sourceforge.net>
parents:
2289
diff
changeset
|
2156 value, anonymous=anonymous) |
|
5416
56c9bcdea47f
Python 3 preparation: unicode.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5414
diff
changeset
|
2157 if self._value and not is_us(self._value): |
|
2561
0dd3dca6bd01
always use translation service set in the tracker client instance;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2558
diff
changeset
|
2158 self._value.setTranslator(self._client.translator) |
|
2314
7c8d2e9a0566
fix DateHTMLProperty so local() can override user timezone [SF#953678]
Richard Jones <richard@users.sourceforge.net>
parents:
2289
diff
changeset
|
2159 self._offset = offset |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
2160 if self._offset is None: |
|
7020
86312ca47ad7
flake8 E211 remove space before ( in function calls
John Rouillard <rouilj@ieee.org>
parents:
7019
diff
changeset
|
2161 self._offset = self._prop.offset(self._db) |
|
2314
7c8d2e9a0566
fix DateHTMLProperty so local() can override user timezone [SF#953678]
Richard Jones <richard@users.sourceforge.net>
parents:
2289
diff
changeset
|
2162 |
|
3971
ff3a8b7d1819
security fixes
Richard Jones <richard@users.sourceforge.net>
parents:
3968
diff
changeset
|
2163 def plain(self, escape=0): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2164 """ Render a "plain" representation of the property |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2165 """ |
|
3117
460eb0209a9e
Permissions improvements.
Richard Jones <richard@users.sourceforge.net>
parents:
3104
diff
changeset
|
2166 if not self.is_view_ok(): |
|
3164
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
2167 return self._('[hidden]') |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2168 |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
2169 if self._value is None: |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2170 return '' |
|
2314
7c8d2e9a0566
fix DateHTMLProperty so local() can override user timezone [SF#953678]
Richard Jones <richard@users.sourceforge.net>
parents:
2289
diff
changeset
|
2171 if self._offset is None: |
|
7c8d2e9a0566
fix DateHTMLProperty so local() can override user timezone [SF#953678]
Richard Jones <richard@users.sourceforge.net>
parents:
2289
diff
changeset
|
2172 offset = self._db.getUserTimezone() |
|
7c8d2e9a0566
fix DateHTMLProperty so local() can override user timezone [SF#953678]
Richard Jones <richard@users.sourceforge.net>
parents:
2289
diff
changeset
|
2173 else: |
|
7c8d2e9a0566
fix DateHTMLProperty so local() can override user timezone [SF#953678]
Richard Jones <richard@users.sourceforge.net>
parents:
2289
diff
changeset
|
2174 offset = self._offset |
|
4842
1e4c45a4254b
Allow using plain() on unsaved dates in HTML forms
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4839
diff
changeset
|
2175 try: |
|
1e4c45a4254b
Allow using plain() on unsaved dates in HTML forms
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4839
diff
changeset
|
2176 return str(self._value.local(offset)) |
|
1e4c45a4254b
Allow using plain() on unsaved dates in HTML forms
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4839
diff
changeset
|
2177 except AttributeError: |
|
1e4c45a4254b
Allow using plain() on unsaved dates in HTML forms
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4839
diff
changeset
|
2178 # not a date value, e.g. from unsaved form data |
|
1e4c45a4254b
Allow using plain() on unsaved dates in HTML forms
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4839
diff
changeset
|
2179 return str(self._value) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2180 |
|
2580
e90d63c7eceb
fixed DateHTMLProperty for invalid date entry [SF#986538]
Richard Jones <richard@users.sourceforge.net>
parents:
2574
diff
changeset
|
2181 def now(self, str_interval=None): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2182 """ Return the current time. |
|
1436
2f6647cf5345
bugger, dropping support for "+" special char
Richard Jones <richard@users.sourceforge.net>
parents:
1421
diff
changeset
|
2183 |
|
2f6647cf5345
bugger, dropping support for "+" special char
Richard Jones <richard@users.sourceforge.net>
parents:
1421
diff
changeset
|
2184 This is useful for defaulting a new value. Returns a |
|
2f6647cf5345
bugger, dropping support for "+" special char
Richard Jones <richard@users.sourceforge.net>
parents:
1421
diff
changeset
|
2185 DateHTMLProperty. |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2186 """ |
|
3117
460eb0209a9e
Permissions improvements.
Richard Jones <richard@users.sourceforge.net>
parents:
3104
diff
changeset
|
2187 if not self.is_view_ok(): |
|
3164
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
2188 return self._('[hidden]') |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2189 |
|
3040
14322134dcef
fix permissions checks in cgi templating [SF#1082755]
Richard Jones <richard@users.sourceforge.net>
parents:
3006
diff
changeset
|
2190 ret = date.Date('.', translator=self._client) |
|
2471
31cd032291c5
new templating features
Richard Jones <richard@users.sourceforge.net>
parents:
2466
diff
changeset
|
2191 |
|
5438
e2382945d302
Python 3 preparation: avoid basestring.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5423
diff
changeset
|
2192 if is_us(str_interval): |
|
3040
14322134dcef
fix permissions checks in cgi templating [SF#1082755]
Richard Jones <richard@users.sourceforge.net>
parents:
3006
diff
changeset
|
2193 sign = 1 |
|
14322134dcef
fix permissions checks in cgi templating [SF#1082755]
Richard Jones <richard@users.sourceforge.net>
parents:
3006
diff
changeset
|
2194 if str_interval[0] == '-': |
|
14322134dcef
fix permissions checks in cgi templating [SF#1082755]
Richard Jones <richard@users.sourceforge.net>
parents:
3006
diff
changeset
|
2195 sign = -1 |
|
14322134dcef
fix permissions checks in cgi templating [SF#1082755]
Richard Jones <richard@users.sourceforge.net>
parents:
3006
diff
changeset
|
2196 str_interval = str_interval[1:] |
|
14322134dcef
fix permissions checks in cgi templating [SF#1082755]
Richard Jones <richard@users.sourceforge.net>
parents:
3006
diff
changeset
|
2197 interval = date.Interval(str_interval, translator=self._client) |
|
14322134dcef
fix permissions checks in cgi templating [SF#1082755]
Richard Jones <richard@users.sourceforge.net>
parents:
3006
diff
changeset
|
2198 if sign > 0: |
|
14322134dcef
fix permissions checks in cgi templating [SF#1082755]
Richard Jones <richard@users.sourceforge.net>
parents:
3006
diff
changeset
|
2199 ret = ret + interval |
|
14322134dcef
fix permissions checks in cgi templating [SF#1082755]
Richard Jones <richard@users.sourceforge.net>
parents:
3006
diff
changeset
|
2200 else: |
|
14322134dcef
fix permissions checks in cgi templating [SF#1082755]
Richard Jones <richard@users.sourceforge.net>
parents:
3006
diff
changeset
|
2201 ret = ret - interval |
|
2520
0914d72bb15b
fix single string split into three separate MsgIDs
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2471
diff
changeset
|
2202 |
| 2037 | 2203 return DateHTMLProperty(self._client, self._classname, self._nodeid, |
|
2471
31cd032291c5
new templating features
Richard Jones <richard@users.sourceforge.net>
parents:
2466
diff
changeset
|
2204 self._prop, self._formname, ret) |
|
1436
2f6647cf5345
bugger, dropping support for "+" special char
Richard Jones <richard@users.sourceforge.net>
parents:
1421
diff
changeset
|
2205 |
|
4267
c5f52c2c9e36
Provide ability to specify arbitrary HTML attributes.
Stefan Seefeld <stefan@seefeld.name>
parents:
4233
diff
changeset
|
2206 def field(self, size=30, default=None, format=_marker, popcal=True, |
|
c5f52c2c9e36
Provide ability to specify arbitrary HTML attributes.
Stefan Seefeld <stefan@seefeld.name>
parents:
4233
diff
changeset
|
2207 **kwargs): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2208 """Render a form edit field for the property |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2209 |
|
2956
4511fd6c5dbf
format parameter for DateHTMLProperty.field() (based on patch [SF#1072834])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2884
diff
changeset
|
2210 If not editable, just display the value via plain(). |
|
4511fd6c5dbf
format parameter for DateHTMLProperty.field() (based on patch [SF#1072834])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2884
diff
changeset
|
2211 |
|
3649
12633662ff63
include the popcal in Date field editing and search fields by default
Richard Jones <richard@users.sourceforge.net>
parents:
3644
diff
changeset
|
2212 If "popcal" then include the Javascript calendar editor. |
|
12633662ff63
include the popcal in Date field editing and search fields by default
Richard Jones <richard@users.sourceforge.net>
parents:
3644
diff
changeset
|
2213 Default=yes. |
|
12633662ff63
include the popcal in Date field editing and search fields by default
Richard Jones <richard@users.sourceforge.net>
parents:
3644
diff
changeset
|
2214 |
|
2956
4511fd6c5dbf
format parameter for DateHTMLProperty.field() (based on patch [SF#1072834])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2884
diff
changeset
|
2215 The format string is a standard python strftime format string. |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2216 """ |
|
2956
4511fd6c5dbf
format parameter for DateHTMLProperty.field() (based on patch [SF#1072834])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2884
diff
changeset
|
2217 if not self.is_edit_ok(): |
|
4511fd6c5dbf
format parameter for DateHTMLProperty.field() (based on patch [SF#1072834])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2884
diff
changeset
|
2218 if format is self._marker: |
|
3971
ff3a8b7d1819
security fixes
Richard Jones <richard@users.sourceforge.net>
parents:
3968
diff
changeset
|
2219 return self.plain(escape=1) |
|
2956
4511fd6c5dbf
format parameter for DateHTMLProperty.field() (based on patch [SF#1072834])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2884
diff
changeset
|
2220 else: |
|
4511fd6c5dbf
format parameter for DateHTMLProperty.field() (based on patch [SF#1072834])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2884
diff
changeset
|
2221 return self.pretty(format) |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2222 |
|
3151
6feac4fcf883
Various bug fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
3127
diff
changeset
|
2223 value = self._value |
|
6feac4fcf883
Various bug fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
3127
diff
changeset
|
2224 |
|
6feac4fcf883
Various bug fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
3127
diff
changeset
|
2225 if value is None: |
|
2471
31cd032291c5
new templating features
Richard Jones <richard@users.sourceforge.net>
parents:
2466
diff
changeset
|
2226 if default is None: |
|
31cd032291c5
new templating features
Richard Jones <richard@users.sourceforge.net>
parents:
2466
diff
changeset
|
2227 raw_value = None |
|
31cd032291c5
new templating features
Richard Jones <richard@users.sourceforge.net>
parents:
2466
diff
changeset
|
2228 else: |
|
5438
e2382945d302
Python 3 preparation: avoid basestring.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5423
diff
changeset
|
2229 if is_us(default): |
|
3832
bbc977e1cd2c
Fix handling of defaults for date fields
Richard Jones <richard@users.sourceforge.net>
parents:
3785
diff
changeset
|
2230 raw_value = date.Date(default, translator=self._client) |
|
2471
31cd032291c5
new templating features
Richard Jones <richard@users.sourceforge.net>
parents:
2466
diff
changeset
|
2231 elif isinstance(default, date.Date): |
|
31cd032291c5
new templating features
Richard Jones <richard@users.sourceforge.net>
parents:
2466
diff
changeset
|
2232 raw_value = default |
|
3040
14322134dcef
fix permissions checks in cgi templating [SF#1082755]
Richard Jones <richard@users.sourceforge.net>
parents:
3006
diff
changeset
|
2233 elif isinstance(default, DateHTMLProperty): |
|
14322134dcef
fix permissions checks in cgi templating [SF#1082755]
Richard Jones <richard@users.sourceforge.net>
parents:
3006
diff
changeset
|
2234 raw_value = default._value |
|
2471
31cd032291c5
new templating features
Richard Jones <richard@users.sourceforge.net>
parents:
2466
diff
changeset
|
2235 else: |
|
5378
35ea9b1efc14
Python 3 preparation: "raise" syntax.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5356
diff
changeset
|
2236 raise ValueError(self._('default value for ' |
|
2520
0914d72bb15b
fix single string split into three separate MsgIDs
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2471
diff
changeset
|
2237 'DateHTMLProperty must be either DateHTMLProperty ' |
|
5378
35ea9b1efc14
Python 3 preparation: "raise" syntax.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5356
diff
changeset
|
2238 'or string date representation.')) |
|
5416
56c9bcdea47f
Python 3 preparation: unicode.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5414
diff
changeset
|
2239 elif is_us(value): |
|
3151
6feac4fcf883
Various bug fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
3127
diff
changeset
|
2240 # most likely erroneous input to be passed back to user |
|
5416
56c9bcdea47f
Python 3 preparation: unicode.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5414
diff
changeset
|
2241 value = us2s(value) |
|
4927
c120f747e0b4
In case of an error, date fields would lose the calendar help, fixed.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4880
diff
changeset
|
2242 s = self.input(name=self._formname, value=value, size=size, |
|
4267
c5f52c2c9e36
Provide ability to specify arbitrary HTML attributes.
Stefan Seefeld <stefan@seefeld.name>
parents:
4233
diff
changeset
|
2243 **kwargs) |
|
4927
c120f747e0b4
In case of an error, date fields would lose the calendar help, fixed.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4880
diff
changeset
|
2244 if popcal: |
|
c120f747e0b4
In case of an error, date fields would lose the calendar help, fixed.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4880
diff
changeset
|
2245 s += self.popcal() |
|
c120f747e0b4
In case of an error, date fields would lose the calendar help, fixed.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4880
diff
changeset
|
2246 return s |
|
2471
31cd032291c5
new templating features
Richard Jones <richard@users.sourceforge.net>
parents:
2466
diff
changeset
|
2247 else: |
|
3151
6feac4fcf883
Various bug fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
3127
diff
changeset
|
2248 raw_value = value |
|
2471
31cd032291c5
new templating features
Richard Jones <richard@users.sourceforge.net>
parents:
2466
diff
changeset
|
2249 |
|
31cd032291c5
new templating features
Richard Jones <richard@users.sourceforge.net>
parents:
2466
diff
changeset
|
2250 if raw_value is None: |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2251 value = '' |
|
5416
56c9bcdea47f
Python 3 preparation: unicode.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5414
diff
changeset
|
2252 elif is_us(raw_value): |
|
2956
4511fd6c5dbf
format parameter for DateHTMLProperty.field() (based on patch [SF#1072834])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2884
diff
changeset
|
2253 if format is self._marker: |
|
4511fd6c5dbf
format parameter for DateHTMLProperty.field() (based on patch [SF#1072834])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2884
diff
changeset
|
2254 value = raw_value |
|
4511fd6c5dbf
format parameter for DateHTMLProperty.field() (based on patch [SF#1072834])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2884
diff
changeset
|
2255 else: |
|
4511fd6c5dbf
format parameter for DateHTMLProperty.field() (based on patch [SF#1072834])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2884
diff
changeset
|
2256 value = date.Date(raw_value).pretty(format) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2257 else: |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
2258 if self._offset is None: |
|
3383
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3369
diff
changeset
|
2259 offset = self._db.getUserTimezone() |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
2260 else: |
|
3383
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3369
diff
changeset
|
2261 offset = self._offset |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3369
diff
changeset
|
2262 value = raw_value.local(offset) |
|
2956
4511fd6c5dbf
format parameter for DateHTMLProperty.field() (based on patch [SF#1072834])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2884
diff
changeset
|
2263 if format is not self._marker: |
|
4511fd6c5dbf
format parameter for DateHTMLProperty.field() (based on patch [SF#1072834])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2884
diff
changeset
|
2264 value = value.pretty(format) |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2265 |
|
4267
c5f52c2c9e36
Provide ability to specify arbitrary HTML attributes.
Stefan Seefeld <stefan@seefeld.name>
parents:
4233
diff
changeset
|
2266 s = self.input(name=self._formname, value=value, size=size, |
|
c5f52c2c9e36
Provide ability to specify arbitrary HTML attributes.
Stefan Seefeld <stefan@seefeld.name>
parents:
4233
diff
changeset
|
2267 **kwargs) |
|
3649
12633662ff63
include the popcal in Date field editing and search fields by default
Richard Jones <richard@users.sourceforge.net>
parents:
3644
diff
changeset
|
2268 if popcal: |
|
12633662ff63
include the popcal in Date field editing and search fields by default
Richard Jones <richard@users.sourceforge.net>
parents:
3644
diff
changeset
|
2269 s += self.popcal() |
|
12633662ff63
include the popcal in Date field editing and search fields by default
Richard Jones <richard@users.sourceforge.net>
parents:
3644
diff
changeset
|
2270 return s |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2271 |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2272 def reldate(self, pretty=1): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2273 """ Render the interval between the date and now. |
|
1124
1fc1f92c5f31
more doc, bugfix in Batch
Richard Jones <richard@users.sourceforge.net>
parents:
1123
diff
changeset
|
2274 |
|
1fc1f92c5f31
more doc, bugfix in Batch
Richard Jones <richard@users.sourceforge.net>
parents:
1123
diff
changeset
|
2275 If the "pretty" flag is true, then make the display pretty. |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2276 """ |
|
3117
460eb0209a9e
Permissions improvements.
Richard Jones <richard@users.sourceforge.net>
parents:
3104
diff
changeset
|
2277 if not self.is_view_ok(): |
|
3164
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
2278 return self._('[hidden]') |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2279 |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
2280 if not self._value: |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2281 return '' |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2282 |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2283 # figure the interval |
|
2524
736115d374f2
use client instance to translate Date and Interval objects
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2520
diff
changeset
|
2284 interval = self._value - date.Date('.', translator=self._client) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2285 if pretty: |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2286 return interval.pretty() |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2287 return str(interval) |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2288 |
|
1453
b72f422d1e5e
better handling of format param
Richard Jones <richard@users.sourceforge.net>
parents:
1451
diff
changeset
|
2289 def pretty(self, format=_marker): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2290 """ Render the date in a pretty format (eg. month names, spaces). |
|
1272
cae50587fb96
expose the Date.pretty method to templating
Richard Jones <richard@users.sourceforge.net>
parents:
1270
diff
changeset
|
2291 |
|
cae50587fb96
expose the Date.pretty method to templating
Richard Jones <richard@users.sourceforge.net>
parents:
1270
diff
changeset
|
2292 The format string is a standard python strftime format string. |
|
cae50587fb96
expose the Date.pretty method to templating
Richard Jones <richard@users.sourceforge.net>
parents:
1270
diff
changeset
|
2293 Note that if the day is zero, and appears at the start of the |
|
cae50587fb96
expose the Date.pretty method to templating
Richard Jones <richard@users.sourceforge.net>
parents:
1270
diff
changeset
|
2294 string, then it'll be stripped from the output. This is handy |
|
3479
86d6131847e8
timezone now applied to date for pretty-format [SF#1406861]
Richard Jones <richard@users.sourceforge.net>
parents:
3472
diff
changeset
|
2295 for the situation when a date only specifies a month and a year. |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2296 """ |
|
3117
460eb0209a9e
Permissions improvements.
Richard Jones <richard@users.sourceforge.net>
parents:
3104
diff
changeset
|
2297 if not self.is_view_ok(): |
|
3164
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
2298 return self._('[hidden]') |
|
3509
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
2299 |
|
3479
86d6131847e8
timezone now applied to date for pretty-format [SF#1406861]
Richard Jones <richard@users.sourceforge.net>
parents:
3472
diff
changeset
|
2300 if self._offset is None: |
|
86d6131847e8
timezone now applied to date for pretty-format [SF#1406861]
Richard Jones <richard@users.sourceforge.net>
parents:
3472
diff
changeset
|
2301 offset = self._db.getUserTimezone() |
|
86d6131847e8
timezone now applied to date for pretty-format [SF#1406861]
Richard Jones <richard@users.sourceforge.net>
parents:
3472
diff
changeset
|
2302 else: |
|
86d6131847e8
timezone now applied to date for pretty-format [SF#1406861]
Richard Jones <richard@users.sourceforge.net>
parents:
3472
diff
changeset
|
2303 offset = self._offset |
|
3509
dcaa366b2cc8
fix StructuredText import;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3505
diff
changeset
|
2304 |
|
6377
a7e7314fb7d9
issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents:
6336
diff
changeset
|
2305 try: |
|
a7e7314fb7d9
issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents:
6336
diff
changeset
|
2306 if not self._value: |
|
a7e7314fb7d9
issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents:
6336
diff
changeset
|
2307 return '' |
|
a7e7314fb7d9
issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents:
6336
diff
changeset
|
2308 elif format is not self._marker: |
|
a7e7314fb7d9
issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents:
6336
diff
changeset
|
2309 return self._value.local(offset).pretty(format) |
|
a7e7314fb7d9
issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents:
6336
diff
changeset
|
2310 else: |
|
a7e7314fb7d9
issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents:
6336
diff
changeset
|
2311 return self._value.local(offset).pretty() |
|
a7e7314fb7d9
issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents:
6336
diff
changeset
|
2312 except AttributeError: |
|
a7e7314fb7d9
issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents:
6336
diff
changeset
|
2313 # not a date value, e.g. from unsaved form data |
|
a7e7314fb7d9
issue2551126 - AttributeError: 'str' object has no attribute 'local'.
John Rouillard <rouilj@ieee.org>
parents:
6336
diff
changeset
|
2314 return str(self._value) |
|
1272
cae50587fb96
expose the Date.pretty method to templating
Richard Jones <richard@users.sourceforge.net>
parents:
1270
diff
changeset
|
2315 |
|
1320
3758a5af985f
Lots of little fixes in this update:
Richard Jones <richard@users.sourceforge.net>
parents:
1289
diff
changeset
|
2316 def local(self, offset): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2317 """ Return the date/time as a local (timezone offset) date/time. |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2318 """ |
|
3117
460eb0209a9e
Permissions improvements.
Richard Jones <richard@users.sourceforge.net>
parents:
3104
diff
changeset
|
2319 if not self.is_view_ok(): |
|
3164
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
2320 return self._('[hidden]') |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2321 |
|
2036
bc5ff0519b8b
fixed bug in args to new DateHTMLProperty in the local() method [SF#901444]
Richard Jones <richard@users.sourceforge.net>
parents:
2031
diff
changeset
|
2322 return DateHTMLProperty(self._client, self._classname, self._nodeid, |
|
2314
7c8d2e9a0566
fix DateHTMLProperty so local() can override user timezone [SF#953678]
Richard Jones <richard@users.sourceforge.net>
parents:
2289
diff
changeset
|
2323 self._prop, self._formname, self._value, offset=offset) |
|
1320
3758a5af985f
Lots of little fixes in this update:
Richard Jones <richard@users.sourceforge.net>
parents:
1289
diff
changeset
|
2324 |
|
3710
2862cb0d9be4
default attributes for input fields:
Tobias Herp <tobias-herp@users.sourceforge.net>
parents:
3702
diff
changeset
|
2325 def popcal(self, width=300, height=200, label="(cal)", |
|
3292
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
2326 form="itemSynopsis"): |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
2327 """Generate a link to a calendar pop-up window. |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
2328 |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
2329 item: HTMLProperty e.g.: context.deadline |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
2330 """ |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
2331 if self.isset(): |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
2332 date = "&date=%s"%self._value |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
2333 else: |
|
3292
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
2334 date = "" |
|
6215
af372b9372f6
Add data attributes to classhelp to allow use with CSP.
John Rouillard <rouilj@ieee.org>
parents:
6150
diff
changeset
|
2335 |
|
af372b9372f6
Add data attributes to classhelp to allow use with CSP.
John Rouillard <rouilj@ieee.org>
parents:
6150
diff
changeset
|
2336 data_attr = { |
|
af372b9372f6
Add data attributes to classhelp to allow use with CSP.
John Rouillard <rouilj@ieee.org>
parents:
6150
diff
changeset
|
2337 "data-calurl": '%s?@template=calendar&property=%s&form=%s%s' % (self._classname, self._name, form, date), |
|
af372b9372f6
Add data attributes to classhelp to allow use with CSP.
John Rouillard <rouilj@ieee.org>
parents:
6150
diff
changeset
|
2338 "data-width": width, |
|
af372b9372f6
Add data attributes to classhelp to allow use with CSP.
John Rouillard <rouilj@ieee.org>
parents:
6150
diff
changeset
|
2339 "data-height": height |
|
af372b9372f6
Add data attributes to classhelp to allow use with CSP.
John Rouillard <rouilj@ieee.org>
parents:
6150
diff
changeset
|
2340 } |
|
7019
e1528860e591
flake8 remove space from blank lines W293
John Rouillard <rouilj@ieee.org>
parents:
7018
diff
changeset
|
2341 |
|
6215
af372b9372f6
Add data attributes to classhelp to allow use with CSP.
John Rouillard <rouilj@ieee.org>
parents:
6150
diff
changeset
|
2342 return ('<a class="classhelp" %s href="javascript:help_window(' |
|
4052
f8ba421ee4b0
Quote ampersands in URLs.
Stefan Seefeld <stefan@seefeld.name>
parents:
4051
diff
changeset
|
2343 "'%s?@template=calendar&property=%s&form=%s%s', %d, %d)" |
|
6215
af372b9372f6
Add data attributes to classhelp to allow use with CSP.
John Rouillard <rouilj@ieee.org>
parents:
6150
diff
changeset
|
2344 '">%s</a>'%(self.cgi_escape_attrs(**data_attr),self._classname, self._name, form, date, width, |
|
3292
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
2345 height, label)) |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
2346 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
2347 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2348 class IntervalHTMLProperty(HTMLProperty): |
|
2389
2ff93cee9c63
StaticTranslationService got methods gettext() and ngettext()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2377
diff
changeset
|
2349 def __init__(self, client, classname, nodeid, prop, name, value, |
|
2ff93cee9c63
StaticTranslationService got methods gettext() and ngettext()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2377
diff
changeset
|
2350 anonymous=0): |
|
2ff93cee9c63
StaticTranslationService got methods gettext() and ngettext()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2377
diff
changeset
|
2351 HTMLProperty.__init__(self, client, classname, nodeid, prop, |
|
2ff93cee9c63
StaticTranslationService got methods gettext() and ngettext()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2377
diff
changeset
|
2352 name, value, anonymous) |
|
5416
56c9bcdea47f
Python 3 preparation: unicode.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5414
diff
changeset
|
2353 if self._value and not is_us(self._value): |
|
2561
0dd3dca6bd01
always use translation service set in the tracker client instance;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2558
diff
changeset
|
2354 self._value.setTranslator(self._client.translator) |
|
2389
2ff93cee9c63
StaticTranslationService got methods gettext() and ngettext()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2377
diff
changeset
|
2355 |
|
3971
ff3a8b7d1819
security fixes
Richard Jones <richard@users.sourceforge.net>
parents:
3968
diff
changeset
|
2356 def plain(self, escape=0): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2357 """ Render a "plain" representation of the property |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2358 """ |
|
3117
460eb0209a9e
Permissions improvements.
Richard Jones <richard@users.sourceforge.net>
parents:
3104
diff
changeset
|
2359 if not self.is_view_ok(): |
|
3164
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
2360 return self._('[hidden]') |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2361 |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
2362 if self._value is None: |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2363 return '' |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
2364 return str(self._value) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2365 |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2366 def pretty(self): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2367 """ Render the interval in a pretty format (eg. "yesterday") |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2368 """ |
|
3117
460eb0209a9e
Permissions improvements.
Richard Jones <richard@users.sourceforge.net>
parents:
3104
diff
changeset
|
2369 if not self.is_view_ok(): |
|
3164
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
2370 return self._('[hidden]') |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2371 |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
2372 return self._value.pretty() |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2373 |
|
4267
c5f52c2c9e36
Provide ability to specify arbitrary HTML attributes.
Stefan Seefeld <stefan@seefeld.name>
parents:
4233
diff
changeset
|
2374 def field(self, size=30, **kwargs): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2375 """ Render a form edit field for the property |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2376 |
|
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2377 If not editable, just display the value via plain(). |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2378 """ |
|
3040
14322134dcef
fix permissions checks in cgi templating [SF#1082755]
Richard Jones <richard@users.sourceforge.net>
parents:
3006
diff
changeset
|
2379 if not self.is_edit_ok(): |
|
3971
ff3a8b7d1819
security fixes
Richard Jones <richard@users.sourceforge.net>
parents:
3968
diff
changeset
|
2380 return self.plain(escape=1) |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2381 |
|
3782
51c07c04d258
clean up input field generation and quoting of values [SF#1615616]
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
2382 value = self._value |
|
51c07c04d258
clean up input field generation and quoting of values [SF#1615616]
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
2383 if value is None: |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2384 value = '' |
|
3782
51c07c04d258
clean up input field generation and quoting of values [SF#1615616]
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
2385 |
|
4267
c5f52c2c9e36
Provide ability to specify arbitrary HTML attributes.
Stefan Seefeld <stefan@seefeld.name>
parents:
4233
diff
changeset
|
2386 return self.input(name=self._formname, value=value, size=size, |
|
c5f52c2c9e36
Provide ability to specify arbitrary HTML attributes.
Stefan Seefeld <stefan@seefeld.name>
parents:
4233
diff
changeset
|
2387 **kwargs) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2388 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
2389 |
|
4878
f6e76a03b502
HTML* classes for cgi are now all new-style
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4875
diff
changeset
|
2390 class LinkHTMLProperty(HTMLProperty): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2391 """ Link HTMLProperty |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2392 Include the above as well as being able to access the class |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2393 information. Stringifying the object itself results in the value |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2394 from the item being displayed. Accessing attributes of this object |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2395 result in the appropriate entry from the class being queried for the |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2396 property accessed (so item/assignedto/name would look up the user |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2397 entry identified by the assignedto property on item, and then the |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2398 name property of that user) |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2399 """ |
|
1447
6118d4498db3
added "foo@" prefix to all but "context" form variable names
Richard Jones <richard@users.sourceforge.net>
parents:
1441
diff
changeset
|
2400 def __init__(self, *args, **kw): |
|
6118d4498db3
added "foo@" prefix to all but "context" form variable names
Richard Jones <richard@users.sourceforge.net>
parents:
1441
diff
changeset
|
2401 HTMLProperty.__init__(self, *args, **kw) |
|
1323
80eef084069a
Fix to handle bad form submissions, Links and the magic -1 form value.
Richard Jones <richard@users.sourceforge.net>
parents:
1322
diff
changeset
|
2402 # if we're representing a form value, then the -1 from the form really |
|
80eef084069a
Fix to handle bad form submissions, Links and the magic -1 form value.
Richard Jones <richard@users.sourceforge.net>
parents:
1322
diff
changeset
|
2403 # should be a None |
|
80eef084069a
Fix to handle bad form submissions, Links and the magic -1 form value.
Richard Jones <richard@users.sourceforge.net>
parents:
1322
diff
changeset
|
2404 if str(self._value) == '-1': |
|
80eef084069a
Fix to handle bad form submissions, Links and the magic -1 form value.
Richard Jones <richard@users.sourceforge.net>
parents:
1322
diff
changeset
|
2405 self._value = None |
|
80eef084069a
Fix to handle bad form submissions, Links and the magic -1 form value.
Richard Jones <richard@users.sourceforge.net>
parents:
1322
diff
changeset
|
2406 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2407 def __getattr__(self, attr): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2408 """ return a new HTMLItem """ |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
2409 if not self._value: |
|
3394
5c7ff95fecad
work around pagetemplate oddity
Richard Jones <richard@users.sourceforge.net>
parents:
3383
diff
changeset
|
2410 # handle a special page templates lookup |
|
5c7ff95fecad
work around pagetemplate oddity
Richard Jones <richard@users.sourceforge.net>
parents:
3383
diff
changeset
|
2411 if attr == '__render_with_namespace__': |
|
5c7ff95fecad
work around pagetemplate oddity
Richard Jones <richard@users.sourceforge.net>
parents:
3383
diff
changeset
|
2412 def nothing(*args, **kw): |
|
5c7ff95fecad
work around pagetemplate oddity
Richard Jones <richard@users.sourceforge.net>
parents:
3383
diff
changeset
|
2413 return '' |
|
5c7ff95fecad
work around pagetemplate oddity
Richard Jones <richard@users.sourceforge.net>
parents:
3383
diff
changeset
|
2414 return nothing |
|
3164
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
2415 msg = self._('Attempt to look up %(attr)s on a missing value') |
|
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
2416 return MissingValue(msg%locals()) |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
2417 i = HTMLItem(self._client, self._prop.classname, self._value) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2418 return getattr(i, attr) |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2419 |
|
4878
f6e76a03b502
HTML* classes for cgi are now all new-style
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4875
diff
changeset
|
2420 def __getitem__(self, item): |
|
f6e76a03b502
HTML* classes for cgi are now all new-style
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4875
diff
changeset
|
2421 """Explicitly define __getitem__ -- this used to work earlier |
|
f6e76a03b502
HTML* classes for cgi are now all new-style
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4875
diff
changeset
|
2422 due to __getattr__ returning the __getitem__ of HTMLItem -- this |
|
f6e76a03b502
HTML* classes for cgi are now all new-style
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4875
diff
changeset
|
2423 lookup doesn't work for new-style classes. |
|
f6e76a03b502
HTML* classes for cgi are now all new-style
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4875
diff
changeset
|
2424 """ |
|
4879
302c967d710c
HTML* classes for cgi: handle MissingValue case
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4878
diff
changeset
|
2425 if not self._value: |
|
302c967d710c
HTML* classes for cgi: handle MissingValue case
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4878
diff
changeset
|
2426 msg = self._('Attempt to look up %(item)s on a missing value') |
|
302c967d710c
HTML* classes for cgi: handle MissingValue case
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4878
diff
changeset
|
2427 return MissingValue(msg%locals()) |
|
4878
f6e76a03b502
HTML* classes for cgi are now all new-style
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4875
diff
changeset
|
2428 i = HTMLItem(self._client, self._prop.classname, self._value) |
|
f6e76a03b502
HTML* classes for cgi are now all new-style
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4875
diff
changeset
|
2429 return i[item] |
|
f6e76a03b502
HTML* classes for cgi are now all new-style
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4875
diff
changeset
|
2430 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2431 def plain(self, escape=0): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2432 """ Render a "plain" representation of the property |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2433 """ |
|
3117
460eb0209a9e
Permissions improvements.
Richard Jones <richard@users.sourceforge.net>
parents:
3104
diff
changeset
|
2434 if not self.is_view_ok(): |
|
3164
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
2435 return self._('[hidden]') |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2436 |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
2437 if self._value is None: |
|
1099
7362dc1f0226
Made "creator" property a String like it should be (we can't lookup()
Richard Jones <richard@users.sourceforge.net>
parents:
1097
diff
changeset
|
2438 return '' |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
2439 linkcl = self._db.classes[self._prop.classname] |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2440 k = linkcl.labelprop(1) |
|
3936
63d58cc1394a
make LinkHTMLProperty handle non-existing keys (patch [SF#1815895])
Richard Jones <richard@users.sourceforge.net>
parents:
3909
diff
changeset
|
2441 if num_re.match(self._value): |
|
4058
3057092623e1
Robustify (Multi)linkHTMLProperty.plain.
Stefan Seefeld <stefan@seefeld.name>
parents:
4057
diff
changeset
|
2442 try: |
|
6620
b7093aa16895
issue2551196 - Unset labelprop of a Multilink can lead to Python error when using context/history
John Rouillard <rouilj@ieee.org>
parents:
6593
diff
changeset
|
2443 value = str(linkcl.get(self._value, k, |
|
b7093aa16895
issue2551196 - Unset labelprop of a Multilink can lead to Python error when using context/history
John Rouillard <rouilj@ieee.org>
parents:
6593
diff
changeset
|
2444 default=self._("[label is missing]"))) |
|
4058
3057092623e1
Robustify (Multi)linkHTMLProperty.plain.
Stefan Seefeld <stefan@seefeld.name>
parents:
4057
diff
changeset
|
2445 except IndexError: |
|
3057092623e1
Robustify (Multi)linkHTMLProperty.plain.
Stefan Seefeld <stefan@seefeld.name>
parents:
4057
diff
changeset
|
2446 value = self._value |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
2447 else: |
|
3936
63d58cc1394a
make LinkHTMLProperty handle non-existing keys (patch [SF#1815895])
Richard Jones <richard@users.sourceforge.net>
parents:
3909
diff
changeset
|
2448 value = self._value |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2449 if escape: |
|
5800
1a835db41674
Call cgi.escape only on python 2. Replace with html.escapeif it can be
John Rouillard <rouilj@ieee.org>
parents:
5684
diff
changeset
|
2450 value = html_escape(value) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2451 return value |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2452 |
|
4267
c5f52c2c9e36
Provide ability to specify arbitrary HTML attributes.
Stefan Seefeld <stefan@seefeld.name>
parents:
4233
diff
changeset
|
2453 def field(self, showid=0, size=None, **kwargs): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2454 """ Render a form edit field for the property |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2455 |
|
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2456 If not editable, just display the value via plain(). |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2457 """ |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2458 if not self.is_edit_ok(): |
|
3971
ff3a8b7d1819
security fixes
Richard Jones <richard@users.sourceforge.net>
parents:
3968
diff
changeset
|
2459 return self.plain(escape=1) |
|
1322
c0546b95aad1
finished off handling of retired flag in filter() [SF#635260]
Richard Jones <richard@users.sourceforge.net>
parents:
1320
diff
changeset
|
2460 |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2461 # edit field |
|
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2462 linkcl = self._db.getclass(self._prop.classname) |
|
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2463 if self._value is None: |
|
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2464 value = '' |
|
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2465 else: |
|
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2466 k = linkcl.getkey() |
|
4958
9b1302f9fb11
Fix for 'try_id_parsing'
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4945
diff
changeset
|
2467 idparse = self._prop.try_id_parsing |
|
4959
177b77302262
Another fix for 'try_id_parsing'
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4958
diff
changeset
|
2468 if k and num_re.match(self._value): |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
2469 try: |
|
4959
177b77302262
Another fix for 'try_id_parsing'
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4958
diff
changeset
|
2470 value = linkcl.get(self._value, k) |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
2471 except IndexError: |
|
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
2472 if idparse: |
|
4959
177b77302262
Another fix for 'try_id_parsing'
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4958
diff
changeset
|
2473 raise |
|
177b77302262
Another fix for 'try_id_parsing'
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4958
diff
changeset
|
2474 value = '' |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2475 else: |
|
2116
1ef1b050b785
fix Link HTML field()
Richard Jones <richard@users.sourceforge.net>
parents:
2113
diff
changeset
|
2476 value = self._value |
|
4267
c5f52c2c9e36
Provide ability to specify arbitrary HTML attributes.
Stefan Seefeld <stefan@seefeld.name>
parents:
4233
diff
changeset
|
2477 return self.input(name=self._formname, value=value, size=size, |
|
c5f52c2c9e36
Provide ability to specify arbitrary HTML attributes.
Stefan Seefeld <stefan@seefeld.name>
parents:
4233
diff
changeset
|
2478 **kwargs) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2479 |
|
3470
fd32170475f5
allow preselection of values in templating menu()s (patch [SF#1396085])
Richard Jones <richard@users.sourceforge.net>
parents:
3461
diff
changeset
|
2480 def menu(self, size=None, height=None, showid=0, additional=[], value=None, |
|
5181
496f30da72f8
Add a new argument "showdef" to the template function menu(). When set
John Rouillard <rouilj@ieee.org>
parents:
5180
diff
changeset
|
2481 sort_on=None, html_kwargs={}, translate=True, showdef=None, **conditions): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2482 """ Render a form select list for this property |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2483 |
|
3127
021b131bd816
doc fixes, one more fix to the permissions-in-listings fix
Richard Jones <richard@users.sourceforge.net>
parents:
3126
diff
changeset
|
2484 "size" is used to limit the length of the list labels |
|
021b131bd816
doc fixes, one more fix to the permissions-in-listings fix
Richard Jones <richard@users.sourceforge.net>
parents:
3126
diff
changeset
|
2485 "height" is used to set the <select> tag's "size" attribute |
|
021b131bd816
doc fixes, one more fix to the permissions-in-listings fix
Richard Jones <richard@users.sourceforge.net>
parents:
3126
diff
changeset
|
2486 "showid" includes the item ids in the list labels |
|
3470
fd32170475f5
allow preselection of values in templating menu()s (patch [SF#1396085])
Richard Jones <richard@users.sourceforge.net>
parents:
3461
diff
changeset
|
2487 "value" specifies which item is pre-selected |
|
3127
021b131bd816
doc fixes, one more fix to the permissions-in-listings fix
Richard Jones <richard@users.sourceforge.net>
parents:
3126
diff
changeset
|
2488 "additional" lists properties which should be included in the |
|
021b131bd816
doc fixes, one more fix to the permissions-in-listings fix
Richard Jones <richard@users.sourceforge.net>
parents:
3126
diff
changeset
|
2489 label |
|
021b131bd816
doc fixes, one more fix to the permissions-in-listings fix
Richard Jones <richard@users.sourceforge.net>
parents:
3126
diff
changeset
|
2490 "sort_on" indicates the property to sort the list on as |
|
3361
64cc03598c8a
fixed templating menu() sort_on handling [SF#1221936]
Richard Jones <richard@users.sourceforge.net>
parents:
3357
diff
changeset
|
2491 (direction, property) where direction is '+' or '-'. A |
|
64cc03598c8a
fixed templating menu() sort_on handling [SF#1221936]
Richard Jones <richard@users.sourceforge.net>
parents:
3357
diff
changeset
|
2492 single string with the direction prepended may be used. |
|
64cc03598c8a
fixed templating menu() sort_on handling [SF#1221936]
Richard Jones <richard@users.sourceforge.net>
parents:
3357
diff
changeset
|
2493 For example: ('-', 'order'), '+name'. |
|
4537
61cd652da1cd
Allow to turn off translation of generated html options in menu method...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4524
diff
changeset
|
2494 "html_kwargs" specified additional html args for the |
|
61cd652da1cd
Allow to turn off translation of generated html options in menu method...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4524
diff
changeset
|
2495 generated html <select> |
|
61cd652da1cd
Allow to turn off translation of generated html options in menu method...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4524
diff
changeset
|
2496 "translate" indicates if we should do translation of labels |
|
61cd652da1cd
Allow to turn off translation of generated html options in menu method...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4524
diff
changeset
|
2497 using gettext -- this is often desired (e.g. for status |
|
61cd652da1cd
Allow to turn off translation of generated html options in menu method...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4524
diff
changeset
|
2498 labels) but sometimes not. |
|
5181
496f30da72f8
Add a new argument "showdef" to the template function menu(). When set
John Rouillard <rouilj@ieee.org>
parents:
5180
diff
changeset
|
2499 "showdef" marks the default value with the string passed |
|
496f30da72f8
Add a new argument "showdef" to the template function menu(). When set
John Rouillard <rouilj@ieee.org>
parents:
5180
diff
changeset
|
2500 as the showdef argument. It is appended to the selected |
|
496f30da72f8
Add a new argument "showdef" to the template function menu(). When set
John Rouillard <rouilj@ieee.org>
parents:
5180
diff
changeset
|
2501 value so the user can reset the menu to the original value. |
|
496f30da72f8
Add a new argument "showdef" to the template function menu(). When set
John Rouillard <rouilj@ieee.org>
parents:
5180
diff
changeset
|
2502 Note that the marker may be removed if the length of |
|
496f30da72f8
Add a new argument "showdef" to the template function menu(). When set
John Rouillard <rouilj@ieee.org>
parents:
5180
diff
changeset
|
2503 the option label and the marker exceed the size. |
|
3270
e4607e12d030
ignore sorting errors in MultilinkHTMLProperty instantiation [SF#1177602]
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3253
diff
changeset
|
2504 |
|
3127
021b131bd816
doc fixes, one more fix to the permissions-in-listings fix
Richard Jones <richard@users.sourceforge.net>
parents:
3126
diff
changeset
|
2505 The remaining keyword arguments are used as conditions for |
|
021b131bd816
doc fixes, one more fix to the permissions-in-listings fix
Richard Jones <richard@users.sourceforge.net>
parents:
3126
diff
changeset
|
2506 filtering the items in the list - they're passed as the |
|
021b131bd816
doc fixes, one more fix to the permissions-in-listings fix
Richard Jones <richard@users.sourceforge.net>
parents:
3126
diff
changeset
|
2507 "filterspec" argument to a Class.filter() call. |
|
021b131bd816
doc fixes, one more fix to the permissions-in-listings fix
Richard Jones <richard@users.sourceforge.net>
parents:
3126
diff
changeset
|
2508 |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2509 If not editable, just display the value via plain(). |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2510 """ |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2511 if not self.is_edit_ok(): |
|
3971
ff3a8b7d1819
security fixes
Richard Jones <richard@users.sourceforge.net>
parents:
3968
diff
changeset
|
2512 return self.plain(escape=1) |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2513 |
|
4043
32965347a663
Allow 'no value' to be selected in LinkHTMLProperty.menu()
Stefan Seefeld <stefan@seefeld.name>
parents:
4042
diff
changeset
|
2514 # Since None indicates the default, we need another way to |
|
32965347a663
Allow 'no value' to be selected in LinkHTMLProperty.menu()
Stefan Seefeld <stefan@seefeld.name>
parents:
4042
diff
changeset
|
2515 # indicate "no selection". We use -1 for this purpose, as |
|
32965347a663
Allow 'no value' to be selected in LinkHTMLProperty.menu()
Stefan Seefeld <stefan@seefeld.name>
parents:
4042
diff
changeset
|
2516 # that is the value we use when submitting a form without the |
|
32965347a663
Allow 'no value' to be selected in LinkHTMLProperty.menu()
Stefan Seefeld <stefan@seefeld.name>
parents:
4042
diff
changeset
|
2517 # value set. |
|
3470
fd32170475f5
allow preselection of values in templating menu()s (patch [SF#1396085])
Richard Jones <richard@users.sourceforge.net>
parents:
3461
diff
changeset
|
2518 if value is None: |
|
fd32170475f5
allow preselection of values in templating menu()s (patch [SF#1396085])
Richard Jones <richard@users.sourceforge.net>
parents:
3461
diff
changeset
|
2519 value = self._value |
|
4043
32965347a663
Allow 'no value' to be selected in LinkHTMLProperty.menu()
Stefan Seefeld <stefan@seefeld.name>
parents:
4042
diff
changeset
|
2520 elif value == '-1': |
|
32965347a663
Allow 'no value' to be selected in LinkHTMLProperty.menu()
Stefan Seefeld <stefan@seefeld.name>
parents:
4042
diff
changeset
|
2521 value = None |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2522 |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
2523 linkcl = self._db.getclass(self._prop.classname) |
|
5988
39b8bc511ed7
Fix html generation errors for boolean options.
John Rouillard <rouilj@ieee.org>
parents:
5973
diff
changeset
|
2524 l = ['<select %s>'%self.cgi_escape_attrs(name = self._formname, |
|
4267
c5f52c2c9e36
Provide ability to specify arbitrary HTML attributes.
Stefan Seefeld <stefan@seefeld.name>
parents:
4233
diff
changeset
|
2525 **html_kwargs)] |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2526 k = linkcl.labelprop(1) |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2527 s = '' |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2528 if value is None: |
|
1952
c40ed9113285
Applied Stefan Seefeld's html4/xhtml patch with some changes.
Richard Jones <richard@users.sourceforge.net>
parents:
1932
diff
changeset
|
2529 s = 'selected="selected" ' |
|
2396
39cdddd313ca
HTMLInputMixin provides translation interface for all its hiers...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2390
diff
changeset
|
2530 l.append(self._('<option %svalue="-1">- no selection -</option>')%s) |
|
3363
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
2531 |
|
3361
64cc03598c8a
fixed templating menu() sort_on handling [SF#1221936]
Richard Jones <richard@users.sourceforge.net>
parents:
3357
diff
changeset
|
2532 if sort_on is not None: |
|
64cc03598c8a
fixed templating menu() sort_on handling [SF#1221936]
Richard Jones <richard@users.sourceforge.net>
parents:
3357
diff
changeset
|
2533 if not isinstance(sort_on, tuple): |
|
64cc03598c8a
fixed templating menu() sort_on handling [SF#1221936]
Richard Jones <richard@users.sourceforge.net>
parents:
3357
diff
changeset
|
2534 if sort_on[0] in '+-': |
|
64cc03598c8a
fixed templating menu() sort_on handling [SF#1221936]
Richard Jones <richard@users.sourceforge.net>
parents:
3357
diff
changeset
|
2535 sort_on = (sort_on[0], sort_on[1:]) |
|
64cc03598c8a
fixed templating menu() sort_on handling [SF#1221936]
Richard Jones <richard@users.sourceforge.net>
parents:
3357
diff
changeset
|
2536 else: |
|
64cc03598c8a
fixed templating menu() sort_on handling [SF#1221936]
Richard Jones <richard@users.sourceforge.net>
parents:
3357
diff
changeset
|
2537 sort_on = ('+', sort_on) |
|
2327
36ae1b14aaab
remove excessive spaces in the translatable strings;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2324
diff
changeset
|
2538 else: |
| 4032 | 2539 sort_on = ('+', linkcl.orderprop()) |
|
3363
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
2540 |
|
3565
32343bfc3da0
add permission filter to menu() implementations [SF#1431188]
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3562
diff
changeset
|
2541 options = [opt |
|
32343bfc3da0
add permission filter to menu() implementations [SF#1431188]
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3562
diff
changeset
|
2542 for opt in linkcl.filter(None, conditions, sort_on, (None, None)) |
|
32343bfc3da0
add permission filter to menu() implementations [SF#1431188]
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3562
diff
changeset
|
2543 if self._db.security.hasPermission("View", self._client.userid, |
|
3594
b5b6a6f7743a
fix bug in menu() permission filter [SF#1444440]
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3584
diff
changeset
|
2544 linkcl.classname, itemid=opt)] |
|
1322
c0546b95aad1
finished off handling of retired flag in filter() [SF#635260]
Richard Jones <richard@users.sourceforge.net>
parents:
1320
diff
changeset
|
2545 |
|
c0546b95aad1
finished off handling of retired flag in filter() [SF#635260]
Richard Jones <richard@users.sourceforge.net>
parents:
1320
diff
changeset
|
2546 # make sure we list the current value if it's retired |
|
3151
6feac4fcf883
Various bug fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
3127
diff
changeset
|
2547 if value and value not in options: |
|
6feac4fcf883
Various bug fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
3127
diff
changeset
|
2548 options.insert(0, value) |
|
1322
c0546b95aad1
finished off handling of retired flag in filter() [SF#635260]
Richard Jones <richard@users.sourceforge.net>
parents:
1320
diff
changeset
|
2549 |
|
4053
f2030089dac6
Extend "additional" parameter to work with (multi)links.
Stefan Seefeld <stefan@seefeld.name>
parents:
4052
diff
changeset
|
2550 if additional: |
|
f2030089dac6
Extend "additional" parameter to work with (multi)links.
Stefan Seefeld <stefan@seefeld.name>
parents:
4052
diff
changeset
|
2551 additional_fns = [] |
|
f2030089dac6
Extend "additional" parameter to work with (multi)links.
Stefan Seefeld <stefan@seefeld.name>
parents:
4052
diff
changeset
|
2552 props = linkcl.getprops() |
|
f2030089dac6
Extend "additional" parameter to work with (multi)links.
Stefan Seefeld <stefan@seefeld.name>
parents:
4052
diff
changeset
|
2553 for propname in additional: |
|
f2030089dac6
Extend "additional" parameter to work with (multi)links.
Stefan Seefeld <stefan@seefeld.name>
parents:
4052
diff
changeset
|
2554 prop = props[propname] |
|
f2030089dac6
Extend "additional" parameter to work with (multi)links.
Stefan Seefeld <stefan@seefeld.name>
parents:
4052
diff
changeset
|
2555 if isinstance(prop, hyperdb.Link): |
|
f2030089dac6
Extend "additional" parameter to work with (multi)links.
Stefan Seefeld <stefan@seefeld.name>
parents:
4052
diff
changeset
|
2556 cl = self._db.getclass(prop.classname) |
|
f2030089dac6
Extend "additional" parameter to work with (multi)links.
Stefan Seefeld <stefan@seefeld.name>
parents:
4052
diff
changeset
|
2557 labelprop = cl.labelprop() |
|
5062
2ac11cc397eb
Fix arguments to 'menu cgi method
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5061
diff
changeset
|
2558 fn = lambda optionid, cl=cl, linkcl=linkcl, \ |
|
4847
843886af0ea1
Reformat previous change (3e36a3bc0335) to 80 chars
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4846
diff
changeset
|
2559 propname=propname, labelprop=labelprop: \ |
|
843886af0ea1
Reformat previous change (3e36a3bc0335) to 80 chars
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4846
diff
changeset
|
2560 cl.get(linkcl.get(optionid, propname), labelprop) |
|
4053
f2030089dac6
Extend "additional" parameter to work with (multi)links.
Stefan Seefeld <stefan@seefeld.name>
parents:
4052
diff
changeset
|
2561 else: |
|
5062
2ac11cc397eb
Fix arguments to 'menu cgi method
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5061
diff
changeset
|
2562 fn = lambda optionid, linkcl=linkcl, propname=propname: \ |
|
4847
843886af0ea1
Reformat previous change (3e36a3bc0335) to 80 chars
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4846
diff
changeset
|
2563 linkcl.get(optionid, propname) |
|
4846
3e36a3bc0335
issue2550822: Fix showing more than one additional property in class menu
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4842
diff
changeset
|
2564 additional_fns.append(fn) |
|
4115
d61066deae67
handle bogus pagination values (issue 2550530)
Richard Jones <richard@users.sourceforge.net>
parents:
4112
diff
changeset
|
2565 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2566 for optionid in options: |
|
1169
7b448a2425fd
bugfix to (multi)link menu() label generation
Richard Jones <richard@users.sourceforge.net>
parents:
1163
diff
changeset
|
2567 # get the option value, and if it's None use an empty string |
|
6404
e29d5f4e0af4
issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents:
6398
diff
changeset
|
2568 try: |
|
e29d5f4e0af4
issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents:
6398
diff
changeset
|
2569 option = linkcl.get(optionid, k) or '' |
|
e29d5f4e0af4
issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents:
6398
diff
changeset
|
2570 except IndexError: |
|
e29d5f4e0af4
issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents:
6398
diff
changeset
|
2571 # optionid does not exist. E.G. |
|
e29d5f4e0af4
issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents:
6398
diff
changeset
|
2572 # IndexError: no such queue z |
|
e29d5f4e0af4
issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents:
6398
diff
changeset
|
2573 # can be set using ?queue=z in URL for |
|
e29d5f4e0af4
issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents:
6398
diff
changeset
|
2574 # a new issue |
|
e29d5f4e0af4
issue2551132 - Setting form value in query string --- issues
John Rouillard <rouilj@ieee.org>
parents:
6398
diff
changeset
|
2575 continue |
|
1169
7b448a2425fd
bugfix to (multi)link menu() label generation
Richard Jones <richard@users.sourceforge.net>
parents:
1163
diff
changeset
|
2576 |
|
7b448a2425fd
bugfix to (multi)link menu() label generation
Richard Jones <richard@users.sourceforge.net>
parents:
1163
diff
changeset
|
2577 # figure if this option is selected |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2578 s = '' |
|
5181
496f30da72f8
Add a new argument "showdef" to the template function menu(). When set
John Rouillard <rouilj@ieee.org>
parents:
5180
diff
changeset
|
2579 # record the marker for the selected item if requested |
|
496f30da72f8
Add a new argument "showdef" to the template function menu(). When set
John Rouillard <rouilj@ieee.org>
parents:
5180
diff
changeset
|
2580 selected_mark='' |
|
496f30da72f8
Add a new argument "showdef" to the template function menu(). When set
John Rouillard <rouilj@ieee.org>
parents:
5180
diff
changeset
|
2581 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2582 if value in [optionid, option]: |
|
1952
c40ed9113285
Applied Stefan Seefeld's html4/xhtml patch with some changes.
Richard Jones <richard@users.sourceforge.net>
parents:
1932
diff
changeset
|
2583 s = 'selected="selected" ' |
|
7017
96be63649c92
flake8 fix additional spaces within () and []
John Rouillard <rouilj@ieee.org>
parents:
6856
diff
changeset
|
2584 if (showdef): |
|
5181
496f30da72f8
Add a new argument "showdef" to the template function menu(). When set
John Rouillard <rouilj@ieee.org>
parents:
5180
diff
changeset
|
2585 selected_mark = showdef |
|
1169
7b448a2425fd
bugfix to (multi)link menu() label generation
Richard Jones <richard@users.sourceforge.net>
parents:
1163
diff
changeset
|
2586 |
|
7b448a2425fd
bugfix to (multi)link menu() label generation
Richard Jones <richard@users.sourceforge.net>
parents:
1163
diff
changeset
|
2587 # figure the label |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2588 if showid: |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
2589 lab = '%s%s: %s'%(self._prop.classname, optionid, option) |
|
3151
6feac4fcf883
Various bug fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
3127
diff
changeset
|
2590 elif not option: |
|
6feac4fcf883
Various bug fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
3127
diff
changeset
|
2591 lab = '%s%s'%(self._prop.classname, optionid) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2592 else: |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2593 lab = option |
|
1169
7b448a2425fd
bugfix to (multi)link menu() label generation
Richard Jones <richard@users.sourceforge.net>
parents:
1163
diff
changeset
|
2594 |
|
5181
496f30da72f8
Add a new argument "showdef" to the template function menu(). When set
John Rouillard <rouilj@ieee.org>
parents:
5180
diff
changeset
|
2595 lab = lab + selected_mark |
|
1169
7b448a2425fd
bugfix to (multi)link menu() label generation
Richard Jones <richard@users.sourceforge.net>
parents:
1163
diff
changeset
|
2596 # truncate if it's too long |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2597 if size is not None and len(lab) > size: |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2598 lab = lab[:size-3] + '...' |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2599 if additional: |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2600 m = [] |
|
4053
f2030089dac6
Extend "additional" parameter to work with (multi)links.
Stefan Seefeld <stefan@seefeld.name>
parents:
4052
diff
changeset
|
2601 for fn in additional_fns: |
|
f2030089dac6
Extend "additional" parameter to work with (multi)links.
Stefan Seefeld <stefan@seefeld.name>
parents:
4052
diff
changeset
|
2602 m.append(str(fn(optionid))) |
|
f2030089dac6
Extend "additional" parameter to work with (multi)links.
Stefan Seefeld <stefan@seefeld.name>
parents:
4052
diff
changeset
|
2603 lab = lab + ' (%s)'%', '.join(m) |
|
1169
7b448a2425fd
bugfix to (multi)link menu() label generation
Richard Jones <richard@users.sourceforge.net>
parents:
1163
diff
changeset
|
2604 |
|
7b448a2425fd
bugfix to (multi)link menu() label generation
Richard Jones <richard@users.sourceforge.net>
parents:
1163
diff
changeset
|
2605 # and generate |
|
4537
61cd652da1cd
Allow to turn off translation of generated html options in menu method...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4524
diff
changeset
|
2606 tr = str |
|
61cd652da1cd
Allow to turn off translation of generated html options in menu method...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4524
diff
changeset
|
2607 if translate: |
|
61cd652da1cd
Allow to turn off translation of generated html options in menu method...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4524
diff
changeset
|
2608 tr = self._ |
|
5800
1a835db41674
Call cgi.escape only on python 2. Replace with html.escapeif it can be
John Rouillard <rouilj@ieee.org>
parents:
5684
diff
changeset
|
2609 lab = html_escape(tr(lab)) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2610 l.append('<option %svalue="%s">%s</option>'%(s, optionid, lab)) |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2611 l.append('</select>') |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2612 return '\n'.join(l) |
|
7025
66149a18f09e
flake8 E303 too many blank lines
John Rouillard <rouilj@ieee.org>
parents:
7024
diff
changeset
|
2613 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2614 # def checklist(self, ...) |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2615 |
|
3194
f887e55edc94
replaced MutlilinkIterator with multilinkGenerator (thanks Bob Ippolito)
Richard Jones <richard@users.sourceforge.net>
parents:
3188
diff
changeset
|
2616 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2617 class MultilinkHTMLProperty(HTMLProperty): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2618 """ Multilink HTMLProperty |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2619 |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2620 Also be iterable, returning a wrapper object like the Link case for |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2621 each entry in the multilink. |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2622 """ |
|
1931
f1e5e5115c29
Always sort MultilinkHTMLProperty in the correct order...
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
1917
diff
changeset
|
2623 def __init__(self, *args, **kwargs): |
|
f1e5e5115c29
Always sort MultilinkHTMLProperty in the correct order...
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
1917
diff
changeset
|
2624 HTMLProperty.__init__(self, *args, **kwargs) |
|
f1e5e5115c29
Always sort MultilinkHTMLProperty in the correct order...
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
1917
diff
changeset
|
2625 if self._value: |
|
3270
e4607e12d030
ignore sorting errors in MultilinkHTMLProperty instantiation [SF#1177602]
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3253
diff
changeset
|
2626 display_value = lookupIds(self._db, self._prop, self._value, |
|
3860
c672b15ddae6
- fix id-lookup in case we already *know* that the value is an id (in
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3857
diff
changeset
|
2627 fail_ok=1, do_lookup=False) |
|
5414
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
2628 keyfun = make_key_function(self._db, self._prop.classname) |
|
3270
e4607e12d030
ignore sorting errors in MultilinkHTMLProperty instantiation [SF#1177602]
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3253
diff
changeset
|
2629 # sorting fails if the value contains |
|
e4607e12d030
ignore sorting errors in MultilinkHTMLProperty instantiation [SF#1177602]
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3253
diff
changeset
|
2630 # items not yet stored in the database |
|
e4607e12d030
ignore sorting errors in MultilinkHTMLProperty instantiation [SF#1177602]
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3253
diff
changeset
|
2631 # ignore these errors to preserve user input |
|
e4607e12d030
ignore sorting errors in MultilinkHTMLProperty instantiation [SF#1177602]
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3253
diff
changeset
|
2632 try: |
|
5414
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
2633 display_value.sort(key=keyfun) |
|
3270
e4607e12d030
ignore sorting errors in MultilinkHTMLProperty instantiation [SF#1177602]
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3253
diff
changeset
|
2634 except: |
|
e4607e12d030
ignore sorting errors in MultilinkHTMLProperty instantiation [SF#1177602]
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3253
diff
changeset
|
2635 pass |
|
3271
572bbe7fa236
typo in recent fix
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3270
diff
changeset
|
2636 self._value = display_value |
|
2327
36ae1b14aaab
remove excessive spaces in the translatable strings;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2324
diff
changeset
|
2637 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2638 def __len__(self): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2639 """ length of the multilink """ |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
2640 return len(self._value) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2641 |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2642 def __getattr__(self, attr): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2643 """ no extended attribute accesses make sense here """ |
|
5378
35ea9b1efc14
Python 3 preparation: "raise" syntax.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5356
diff
changeset
|
2644 raise AttributeError(attr) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2645 |
|
3200
d2b1a946fdf4
change ZTUtils Iterator to always iter() its sequence argument
Richard Jones <richard@users.sourceforge.net>
parents:
3198
diff
changeset
|
2646 def viewableGenerator(self, values): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2647 """Used to iterate over only the View'able items in a class.""" |
|
3198
0b7990f54778
fixed broken csv import in roundup.admin module
Richard Jones <richard@users.sourceforge.net>
parents:
3194
diff
changeset
|
2648 check = self._db.security.hasPermission |
|
0b7990f54778
fixed broken csv import in roundup.admin module
Richard Jones <richard@users.sourceforge.net>
parents:
3194
diff
changeset
|
2649 userid = self._client.userid |
|
0b7990f54778
fixed broken csv import in roundup.admin module
Richard Jones <richard@users.sourceforge.net>
parents:
3194
diff
changeset
|
2650 classname = self._prop.classname |
|
4328
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
2651 if check('Web Access', userid): |
|
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
2652 for value in values: |
|
5221
24945480d24c
Iterate over multilink items if they labelprop is accessible to the
John Rouillard <rouilj@ieee.org>
parents:
5217
diff
changeset
|
2653 if check('View', userid, classname, |
|
24945480d24c
Iterate over multilink items if they labelprop is accessible to the
John Rouillard <rouilj@ieee.org>
parents:
5217
diff
changeset
|
2654 itemid=value, |
|
24945480d24c
Iterate over multilink items if they labelprop is accessible to the
John Rouillard <rouilj@ieee.org>
parents:
5217
diff
changeset
|
2655 property=self._db.getclass(classname).labelprop(default_to_id=1)): |
|
4328
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
2656 yield HTMLItem(self._client, classname, value) |
|
3198
0b7990f54778
fixed broken csv import in roundup.admin module
Richard Jones <richard@users.sourceforge.net>
parents:
3194
diff
changeset
|
2657 |
|
3126
a2889d22db4a
the cgi templating code now checks item-level
Richard Jones <richard@users.sourceforge.net>
parents:
3117
diff
changeset
|
2658 def __iter__(self): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2659 """ iterate and return a new HTMLItem |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2660 """ |
|
3200
d2b1a946fdf4
change ZTUtils Iterator to always iter() its sequence argument
Richard Jones <richard@users.sourceforge.net>
parents:
3198
diff
changeset
|
2661 return self.viewableGenerator(self._value) |
|
3126
a2889d22db4a
the cgi templating code now checks item-level
Richard Jones <richard@users.sourceforge.net>
parents:
3117
diff
changeset
|
2662 |
|
a2889d22db4a
the cgi templating code now checks item-level
Richard Jones <richard@users.sourceforge.net>
parents:
3117
diff
changeset
|
2663 def reverse(self): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2664 """ return the list in reverse order |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2665 """ |
|
3126
a2889d22db4a
the cgi templating code now checks item-level
Richard Jones <richard@users.sourceforge.net>
parents:
3117
diff
changeset
|
2666 l = self._value[:] |
|
a2889d22db4a
the cgi templating code now checks item-level
Richard Jones <richard@users.sourceforge.net>
parents:
3117
diff
changeset
|
2667 l.reverse() |
|
3200
d2b1a946fdf4
change ZTUtils Iterator to always iter() its sequence argument
Richard Jones <richard@users.sourceforge.net>
parents:
3198
diff
changeset
|
2668 return self.viewableGenerator(l) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2669 |
|
6414
3dbf1bc5e567
issue2551120 - The sorted method of MultilinkHTMLProperty crashes ...
John Rouillard <rouilj@ieee.org>
parents:
6404
diff
changeset
|
2670 def sorted(self, property, reverse=False, NoneFirst=False): |
|
7021
4e25815961a7
flake8: remove trailing whitespace; blank lines for definitions
John Rouillard <rouilj@ieee.org>
parents:
7020
diff
changeset
|
2671 """ Return this multilink sorted by the given property |
|
6414
3dbf1bc5e567
issue2551120 - The sorted method of MultilinkHTMLProperty crashes ...
John Rouillard <rouilj@ieee.org>
parents:
6404
diff
changeset
|
2672 |
|
3dbf1bc5e567
issue2551120 - The sorted method of MultilinkHTMLProperty crashes ...
John Rouillard <rouilj@ieee.org>
parents:
6404
diff
changeset
|
2673 Set Nonefirst to True to sort None/unset property |
|
3dbf1bc5e567
issue2551120 - The sorted method of MultilinkHTMLProperty crashes ...
John Rouillard <rouilj@ieee.org>
parents:
6404
diff
changeset
|
2674 before a property with a valid value. |
|
7019
e1528860e591
flake8 remove space from blank lines W293
John Rouillard <rouilj@ieee.org>
parents:
7018
diff
changeset
|
2675 |
|
6414
3dbf1bc5e567
issue2551120 - The sorted method of MultilinkHTMLProperty crashes ...
John Rouillard <rouilj@ieee.org>
parents:
6404
diff
changeset
|
2676 """ |
|
3dbf1bc5e567
issue2551120 - The sorted method of MultilinkHTMLProperty crashes ...
John Rouillard <rouilj@ieee.org>
parents:
6404
diff
changeset
|
2677 |
|
3dbf1bc5e567
issue2551120 - The sorted method of MultilinkHTMLProperty crashes ...
John Rouillard <rouilj@ieee.org>
parents:
6404
diff
changeset
|
2678 # use 2 if NoneFirst is False to sort None last |
|
3dbf1bc5e567
issue2551120 - The sorted method of MultilinkHTMLProperty crashes ...
John Rouillard <rouilj@ieee.org>
parents:
6404
diff
changeset
|
2679 # 0 to sort to sort None first |
|
3dbf1bc5e567
issue2551120 - The sorted method of MultilinkHTMLProperty crashes ...
John Rouillard <rouilj@ieee.org>
parents:
6404
diff
changeset
|
2680 # 1 is used to sort the integer values. |
|
3dbf1bc5e567
issue2551120 - The sorted method of MultilinkHTMLProperty crashes ...
John Rouillard <rouilj@ieee.org>
parents:
6404
diff
changeset
|
2681 NoneCode = (2,0)[NoneFirst] |
|
6421
9c57f2814597
Fix issue2551122 (MultilinkHTMLProperty sorted method issue)
John Rouillard <rouilj@ieee.org>
parents:
6414
diff
changeset
|
2682 |
|
9c57f2814597
Fix issue2551122 (MultilinkHTMLProperty sorted method issue)
John Rouillard <rouilj@ieee.org>
parents:
6414
diff
changeset
|
2683 value = list(self.__iter__()) |
|
9c57f2814597
Fix issue2551122 (MultilinkHTMLProperty sorted method issue)
John Rouillard <rouilj@ieee.org>
parents:
6414
diff
changeset
|
2684 |
|
6444
3ca8b6145167
issue2551122 - fixing order by a link/multilink broke other props
John Rouillard <rouilj@ieee.org>
parents:
6428
diff
changeset
|
2685 if not value: |
|
3ca8b6145167
issue2551122 - fixing order by a link/multilink broke other props
John Rouillard <rouilj@ieee.org>
parents:
6428
diff
changeset
|
2686 # return empty list, nothing to sort. |
|
6421
9c57f2814597
Fix issue2551122 (MultilinkHTMLProperty sorted method issue)
John Rouillard <rouilj@ieee.org>
parents:
6414
diff
changeset
|
2687 return value |
|
9c57f2814597
Fix issue2551122 (MultilinkHTMLProperty sorted method issue)
John Rouillard <rouilj@ieee.org>
parents:
6414
diff
changeset
|
2688 |
|
6444
3ca8b6145167
issue2551122 - fixing order by a link/multilink broke other props
John Rouillard <rouilj@ieee.org>
parents:
6428
diff
changeset
|
2689 # determine orderprop for property if property is a link or multilink |
|
3ca8b6145167
issue2551122 - fixing order by a link/multilink broke other props
John Rouillard <rouilj@ieee.org>
parents:
6428
diff
changeset
|
2690 prop = self._db.getclass(self._classname).getprops()[property] |
|
3ca8b6145167
issue2551122 - fixing order by a link/multilink broke other props
John Rouillard <rouilj@ieee.org>
parents:
6428
diff
changeset
|
2691 if type(prop) in [hyperdb.Link, hyperdb.Multilink]: |
|
3ca8b6145167
issue2551122 - fixing order by a link/multilink broke other props
John Rouillard <rouilj@ieee.org>
parents:
6428
diff
changeset
|
2692 orderprop = value[0]._db.getclass(prop.classname).orderprop() |
|
3ca8b6145167
issue2551122 - fixing order by a link/multilink broke other props
John Rouillard <rouilj@ieee.org>
parents:
6428
diff
changeset
|
2693 sort_by_link = True |
|
7021
4e25815961a7
flake8: remove trailing whitespace; blank lines for definitions
John Rouillard <rouilj@ieee.org>
parents:
7020
diff
changeset
|
2694 else: |
|
6444
3ca8b6145167
issue2551122 - fixing order by a link/multilink broke other props
John Rouillard <rouilj@ieee.org>
parents:
6428
diff
changeset
|
2695 orderprop = property |
|
3ca8b6145167
issue2551122 - fixing order by a link/multilink broke other props
John Rouillard <rouilj@ieee.org>
parents:
6428
diff
changeset
|
2696 sort_by_link = False |
|
3ca8b6145167
issue2551122 - fixing order by a link/multilink broke other props
John Rouillard <rouilj@ieee.org>
parents:
6428
diff
changeset
|
2697 |
|
6414
3dbf1bc5e567
issue2551120 - The sorted method of MultilinkHTMLProperty crashes ...
John Rouillard <rouilj@ieee.org>
parents:
6404
diff
changeset
|
2698 def keyfunc(v): |
|
3dbf1bc5e567
issue2551120 - The sorted method of MultilinkHTMLProperty crashes ...
John Rouillard <rouilj@ieee.org>
parents:
6404
diff
changeset
|
2699 # Return tuples made of (group order (int), base python |
|
3dbf1bc5e567
issue2551120 - The sorted method of MultilinkHTMLProperty crashes ...
John Rouillard <rouilj@ieee.org>
parents:
6404
diff
changeset
|
2700 # type) to sort function. |
|
3dbf1bc5e567
issue2551120 - The sorted method of MultilinkHTMLProperty crashes ...
John Rouillard <rouilj@ieee.org>
parents:
6404
diff
changeset
|
2701 # Do not return v[property] as that returns an HTMLProperty |
|
3dbf1bc5e567
issue2551120 - The sorted method of MultilinkHTMLProperty crashes ...
John Rouillard <rouilj@ieee.org>
parents:
6404
diff
changeset
|
2702 # type/subtype that throws an exception when sorting |
|
3dbf1bc5e567
issue2551120 - The sorted method of MultilinkHTMLProperty crashes ...
John Rouillard <rouilj@ieee.org>
parents:
6404
diff
changeset
|
2703 # python type (int. str ...) against None. |
|
6421
9c57f2814597
Fix issue2551122 (MultilinkHTMLProperty sorted method issue)
John Rouillard <rouilj@ieee.org>
parents:
6414
diff
changeset
|
2704 prop = v[property] |
|
9c57f2814597
Fix issue2551122 (MultilinkHTMLProperty sorted method issue)
John Rouillard <rouilj@ieee.org>
parents:
6414
diff
changeset
|
2705 if not prop._value: |
|
6414
3dbf1bc5e567
issue2551120 - The sorted method of MultilinkHTMLProperty crashes ...
John Rouillard <rouilj@ieee.org>
parents:
6404
diff
changeset
|
2706 return (NoneCode, None) |
|
3dbf1bc5e567
issue2551120 - The sorted method of MultilinkHTMLProperty crashes ...
John Rouillard <rouilj@ieee.org>
parents:
6404
diff
changeset
|
2707 |
|
6444
3ca8b6145167
issue2551122 - fixing order by a link/multilink broke other props
John Rouillard <rouilj@ieee.org>
parents:
6428
diff
changeset
|
2708 if sort_by_link: |
|
3ca8b6145167
issue2551122 - fixing order by a link/multilink broke other props
John Rouillard <rouilj@ieee.org>
parents:
6428
diff
changeset
|
2709 val = prop[orderprop]._value |
|
3ca8b6145167
issue2551122 - fixing order by a link/multilink broke other props
John Rouillard <rouilj@ieee.org>
parents:
6428
diff
changeset
|
2710 else: |
|
3ca8b6145167
issue2551122 - fixing order by a link/multilink broke other props
John Rouillard <rouilj@ieee.org>
parents:
6428
diff
changeset
|
2711 val = prop._value |
|
6421
9c57f2814597
Fix issue2551122 (MultilinkHTMLProperty sorted method issue)
John Rouillard <rouilj@ieee.org>
parents:
6414
diff
changeset
|
2712 |
|
7022
f4bfc1af5d95
flake8 inline comment spacing; too many leading #
John Rouillard <rouilj@ieee.org>
parents:
7021
diff
changeset
|
2713 if val is None: # verify orderprop is set to a value |
|
6421
9c57f2814597
Fix issue2551122 (MultilinkHTMLProperty sorted method issue)
John Rouillard <rouilj@ieee.org>
parents:
6414
diff
changeset
|
2714 return (NoneCode, None) |
|
9c57f2814597
Fix issue2551122 (MultilinkHTMLProperty sorted method issue)
John Rouillard <rouilj@ieee.org>
parents:
6414
diff
changeset
|
2715 return (1, val) # val should be base python type |
|
9c57f2814597
Fix issue2551122 (MultilinkHTMLProperty sorted method issue)
John Rouillard <rouilj@ieee.org>
parents:
6414
diff
changeset
|
2716 |
|
6414
3dbf1bc5e567
issue2551120 - The sorted method of MultilinkHTMLProperty crashes ...
John Rouillard <rouilj@ieee.org>
parents:
6404
diff
changeset
|
2717 value.sort(key=keyfunc, reverse=reverse) |
|
2883
1ca5ebe9b16a
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
2880
diff
changeset
|
2718 return value |
|
1ca5ebe9b16a
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
2880
diff
changeset
|
2719 |
|
1103
db787cef1385
handled some XXXs
Richard Jones <richard@users.sourceforge.net>
parents:
1099
diff
changeset
|
2720 def __contains__(self, value): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2721 """ Support the "in" operator. We have to make sure the passed-in |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
2722 value is a string first, not a HTMLProperty. |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2723 """ |
|
1325
2e5a9fc7abd5
allow StringHTMLProperty in MultilinkHTMLProperty test to work
Richard Jones <richard@users.sourceforge.net>
parents:
1323
diff
changeset
|
2724 return str(value) in self._value |
|
1103
db787cef1385
handled some XXXs
Richard Jones <richard@users.sourceforge.net>
parents:
1099
diff
changeset
|
2725 |
|
2180
58b6d1747973
Web interface tweaks.
Richard Jones <richard@users.sourceforge.net>
parents:
2170
diff
changeset
|
2726 def isset(self): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2727 """Is my _value not []?""" |
|
2289
6d16b967f89d
HTML templating isset() inverted [SF#951779]
Richard Jones <richard@users.sourceforge.net>
parents:
2262
diff
changeset
|
2728 return self._value != [] |
|
2180
58b6d1747973
Web interface tweaks.
Richard Jones <richard@users.sourceforge.net>
parents:
2170
diff
changeset
|
2729 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2730 def plain(self, escape=0): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2731 """ Render a "plain" representation of the property |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2732 """ |
|
3117
460eb0209a9e
Permissions improvements.
Richard Jones <richard@users.sourceforge.net>
parents:
3104
diff
changeset
|
2733 if not self.is_view_ok(): |
|
3164
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
2734 return self._('[hidden]') |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2735 |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
2736 linkcl = self._db.classes[self._prop.classname] |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2737 k = linkcl.labelprop(1) |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2738 labels = [] |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
2739 for v in self._value: |
|
4058
3057092623e1
Robustify (Multi)linkHTMLProperty.plain.
Stefan Seefeld <stefan@seefeld.name>
parents:
4057
diff
changeset
|
2740 if num_re.match(v): |
|
3057092623e1
Robustify (Multi)linkHTMLProperty.plain.
Stefan Seefeld <stefan@seefeld.name>
parents:
4057
diff
changeset
|
2741 try: |
|
6620
b7093aa16895
issue2551196 - Unset labelprop of a Multilink can lead to Python error when using context/history
John Rouillard <rouilj@ieee.org>
parents:
6593
diff
changeset
|
2742 label = linkcl.get(v, k, |
|
b7093aa16895
issue2551196 - Unset labelprop of a Multilink can lead to Python error when using context/history
John Rouillard <rouilj@ieee.org>
parents:
6593
diff
changeset
|
2743 default=self._("[label is missing]")) |
|
4058
3057092623e1
Robustify (Multi)linkHTMLProperty.plain.
Stefan Seefeld <stefan@seefeld.name>
parents:
4057
diff
changeset
|
2744 except IndexError: |
|
3057092623e1
Robustify (Multi)linkHTMLProperty.plain.
Stefan Seefeld <stefan@seefeld.name>
parents:
4057
diff
changeset
|
2745 label = None |
|
3057092623e1
Robustify (Multi)linkHTMLProperty.plain.
Stefan Seefeld <stefan@seefeld.name>
parents:
4057
diff
changeset
|
2746 # fall back to designator if label is None |
|
3057092623e1
Robustify (Multi)linkHTMLProperty.plain.
Stefan Seefeld <stefan@seefeld.name>
parents:
4057
diff
changeset
|
2747 if label is None: label = '%s%s'%(self._prop.classname, k) |
|
3057092623e1
Robustify (Multi)linkHTMLProperty.plain.
Stefan Seefeld <stefan@seefeld.name>
parents:
4057
diff
changeset
|
2748 else: |
|
3057092623e1
Robustify (Multi)linkHTMLProperty.plain.
Stefan Seefeld <stefan@seefeld.name>
parents:
4057
diff
changeset
|
2749 label = v |
|
3401
62e4032cb280
merge from maint-0-8
Richard Jones <richard@users.sourceforge.net>
parents:
3394
diff
changeset
|
2750 labels.append(label) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2751 value = ', '.join(labels) |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2752 if escape: |
|
5800
1a835db41674
Call cgi.escape only on python 2. Replace with html.escapeif it can be
John Rouillard <rouilj@ieee.org>
parents:
5684
diff
changeset
|
2753 value = html_escape(value) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2754 return value |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2755 |
|
4267
c5f52c2c9e36
Provide ability to specify arbitrary HTML attributes.
Stefan Seefeld <stefan@seefeld.name>
parents:
4233
diff
changeset
|
2756 def field(self, size=30, showid=0, **kwargs): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2757 """ Render a form edit field for the property |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2758 |
|
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2759 If not editable, just display the value via plain(). |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2760 """ |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2761 if not self.is_edit_ok(): |
|
3971
ff3a8b7d1819
security fixes
Richard Jones <richard@users.sourceforge.net>
parents:
3968
diff
changeset
|
2762 return self.plain(escape=1) |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2763 |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
2764 linkcl = self._db.getclass(self._prop.classname) |
|
4339
663664c4e626
Allow value to be specified to multilink form element templating
Richard Jones <richard@users.sourceforge.net>
parents:
4333
diff
changeset
|
2765 |
|
663664c4e626
Allow value to be specified to multilink form element templating
Richard Jones <richard@users.sourceforge.net>
parents:
4333
diff
changeset
|
2766 if 'value' not in kwargs: |
|
663664c4e626
Allow value to be specified to multilink form element templating
Richard Jones <richard@users.sourceforge.net>
parents:
4333
diff
changeset
|
2767 value = self._value[:] |
|
663664c4e626
Allow value to be specified to multilink form element templating
Richard Jones <richard@users.sourceforge.net>
parents:
4333
diff
changeset
|
2768 # map the id to the label property |
|
663664c4e626
Allow value to be specified to multilink form element templating
Richard Jones <richard@users.sourceforge.net>
parents:
4333
diff
changeset
|
2769 if not linkcl.getkey(): |
|
663664c4e626
Allow value to be specified to multilink form element templating
Richard Jones <richard@users.sourceforge.net>
parents:
4333
diff
changeset
|
2770 showid=1 |
|
663664c4e626
Allow value to be specified to multilink form element templating
Richard Jones <richard@users.sourceforge.net>
parents:
4333
diff
changeset
|
2771 if not showid: |
|
663664c4e626
Allow value to be specified to multilink form element templating
Richard Jones <richard@users.sourceforge.net>
parents:
4333
diff
changeset
|
2772 k = linkcl.labelprop(1) |
|
663664c4e626
Allow value to be specified to multilink form element templating
Richard Jones <richard@users.sourceforge.net>
parents:
4333
diff
changeset
|
2773 value = lookupKeys(linkcl, k, value) |
|
663664c4e626
Allow value to be specified to multilink form element templating
Richard Jones <richard@users.sourceforge.net>
parents:
4333
diff
changeset
|
2774 value = ','.join(value) |
|
4356
05a65559d873
undo regression in 1.4.12: Multilink edit fields lose their values
Richard Jones <richard@users.sourceforge.net>
parents:
4339
diff
changeset
|
2775 kwargs["value"] = value |
|
4339
663664c4e626
Allow value to be specified to multilink form element templating
Richard Jones <richard@users.sourceforge.net>
parents:
4333
diff
changeset
|
2776 |
|
663664c4e626
Allow value to be specified to multilink form element templating
Richard Jones <richard@users.sourceforge.net>
parents:
4333
diff
changeset
|
2777 return self.input(name=self._formname, size=size, **kwargs) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2778 |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2779 def menu(self, size=None, height=None, showid=0, additional=[], |
|
4537
61cd652da1cd
Allow to turn off translation of generated html options in menu method...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4524
diff
changeset
|
2780 value=None, sort_on=None, html_kwargs={}, translate=True, |
|
61cd652da1cd
Allow to turn off translation of generated html options in menu method...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4524
diff
changeset
|
2781 **conditions): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2782 """ Render a form <select> list for this property. |
|
3127
021b131bd816
doc fixes, one more fix to the permissions-in-listings fix
Richard Jones <richard@users.sourceforge.net>
parents:
3126
diff
changeset
|
2783 |
|
021b131bd816
doc fixes, one more fix to the permissions-in-listings fix
Richard Jones <richard@users.sourceforge.net>
parents:
3126
diff
changeset
|
2784 "size" is used to limit the length of the list labels |
|
021b131bd816
doc fixes, one more fix to the permissions-in-listings fix
Richard Jones <richard@users.sourceforge.net>
parents:
3126
diff
changeset
|
2785 "height" is used to set the <select> tag's "size" attribute |
|
021b131bd816
doc fixes, one more fix to the permissions-in-listings fix
Richard Jones <richard@users.sourceforge.net>
parents:
3126
diff
changeset
|
2786 "showid" includes the item ids in the list labels |
|
021b131bd816
doc fixes, one more fix to the permissions-in-listings fix
Richard Jones <richard@users.sourceforge.net>
parents:
3126
diff
changeset
|
2787 "additional" lists properties which should be included in the |
|
021b131bd816
doc fixes, one more fix to the permissions-in-listings fix
Richard Jones <richard@users.sourceforge.net>
parents:
3126
diff
changeset
|
2788 label |
|
3470
fd32170475f5
allow preselection of values in templating menu()s (patch [SF#1396085])
Richard Jones <richard@users.sourceforge.net>
parents:
3461
diff
changeset
|
2789 "value" specifies which item is pre-selected |
|
3127
021b131bd816
doc fixes, one more fix to the permissions-in-listings fix
Richard Jones <richard@users.sourceforge.net>
parents:
3126
diff
changeset
|
2790 "sort_on" indicates the property to sort the list on as |
|
3363
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
2791 (direction, property) where direction is '+' or '-'. A |
|
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
2792 single string with the direction prepended may be used. |
|
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
2793 For example: ('-', 'order'), '+name'. |
|
3270
e4607e12d030
ignore sorting errors in MultilinkHTMLProperty instantiation [SF#1177602]
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3253
diff
changeset
|
2794 |
|
3127
021b131bd816
doc fixes, one more fix to the permissions-in-listings fix
Richard Jones <richard@users.sourceforge.net>
parents:
3126
diff
changeset
|
2795 The remaining keyword arguments are used as conditions for |
|
021b131bd816
doc fixes, one more fix to the permissions-in-listings fix
Richard Jones <richard@users.sourceforge.net>
parents:
3126
diff
changeset
|
2796 filtering the items in the list - they're passed as the |
|
021b131bd816
doc fixes, one more fix to the permissions-in-listings fix
Richard Jones <richard@users.sourceforge.net>
parents:
3126
diff
changeset
|
2797 "filterspec" argument to a Class.filter() call. |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2798 |
|
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2799 If not editable, just display the value via plain(). |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2800 """ |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2801 if not self.is_edit_ok(): |
|
3971
ff3a8b7d1819
security fixes
Richard Jones <richard@users.sourceforge.net>
parents:
3968
diff
changeset
|
2802 return self.plain(escape=1) |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2803 |
|
3470
fd32170475f5
allow preselection of values in templating menu()s (patch [SF#1396085])
Richard Jones <richard@users.sourceforge.net>
parents:
3461
diff
changeset
|
2804 if value is None: |
|
fd32170475f5
allow preselection of values in templating menu()s (patch [SF#1396085])
Richard Jones <richard@users.sourceforge.net>
parents:
3461
diff
changeset
|
2805 value = self._value |
|
5548
fea11d05110e
Avoid errors from selecting "no selection" on multilink (issue2550722).
Joseph Myers <jsm@polyomino.org.uk>
parents:
5492
diff
changeset
|
2806 # When rendering from form contents, 'value' may contain |
|
fea11d05110e
Avoid errors from selecting "no selection" on multilink (issue2550722).
Joseph Myers <jsm@polyomino.org.uk>
parents:
5492
diff
changeset
|
2807 # elements starting '-' from '- no selection -' having been |
|
fea11d05110e
Avoid errors from selecting "no selection" on multilink (issue2550722).
Joseph Myers <jsm@polyomino.org.uk>
parents:
5492
diff
changeset
|
2808 # selected on a previous form submission. |
|
fea11d05110e
Avoid errors from selecting "no selection" on multilink (issue2550722).
Joseph Myers <jsm@polyomino.org.uk>
parents:
5492
diff
changeset
|
2809 value = [v for v in value if not v.startswith('-')] |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2810 |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
2811 linkcl = self._db.getclass(self._prop.classname) |
|
3363
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
2812 |
|
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
2813 if sort_on is not None: |
|
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
2814 if not isinstance(sort_on, tuple): |
|
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
2815 if sort_on[0] in '+-': |
|
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
2816 sort_on = (sort_on[0], sort_on[1:]) |
|
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
2817 else: |
|
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
2818 sort_on = ('+', sort_on) |
|
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
2819 else: |
| 4032 | 2820 sort_on = ('+', linkcl.orderprop()) |
|
3363
7bc1e9c42a26
allow specification of pagesize, sorting and filtering in "classhelp" popups
Richard Jones <richard@users.sourceforge.net>
parents:
3361
diff
changeset
|
2821 |
|
3565
32343bfc3da0
add permission filter to menu() implementations [SF#1431188]
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3562
diff
changeset
|
2822 options = [opt |
|
32343bfc3da0
add permission filter to menu() implementations [SF#1431188]
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3562
diff
changeset
|
2823 for opt in linkcl.filter(None, conditions, sort_on) |
|
32343bfc3da0
add permission filter to menu() implementations [SF#1431188]
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3562
diff
changeset
|
2824 if self._db.security.hasPermission("View", self._client.userid, |
|
3594
b5b6a6f7743a
fix bug in menu() permission filter [SF#1444440]
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3584
diff
changeset
|
2825 linkcl.classname, itemid=opt)] |
|
4115
d61066deae67
handle bogus pagination values (issue 2550530)
Richard Jones <richard@users.sourceforge.net>
parents:
4112
diff
changeset
|
2826 |
|
4042
8831882170fc
Fix height calculation for Multilink.menu()
Stefan Seefeld <stefan@seefeld.name>
parents:
4040
diff
changeset
|
2827 # make sure we list the current values if they're retired |
|
8831882170fc
Fix height calculation for Multilink.menu()
Stefan Seefeld <stefan@seefeld.name>
parents:
4040
diff
changeset
|
2828 for val in value: |
|
8831882170fc
Fix height calculation for Multilink.menu()
Stefan Seefeld <stefan@seefeld.name>
parents:
4040
diff
changeset
|
2829 if val not in options: |
|
8831882170fc
Fix height calculation for Multilink.menu()
Stefan Seefeld <stefan@seefeld.name>
parents:
4040
diff
changeset
|
2830 options.insert(0, val) |
|
8831882170fc
Fix height calculation for Multilink.menu()
Stefan Seefeld <stefan@seefeld.name>
parents:
4040
diff
changeset
|
2831 |
|
8831882170fc
Fix height calculation for Multilink.menu()
Stefan Seefeld <stefan@seefeld.name>
parents:
4040
diff
changeset
|
2832 if not height: |
|
8831882170fc
Fix height calculation for Multilink.menu()
Stefan Seefeld <stefan@seefeld.name>
parents:
4040
diff
changeset
|
2833 height = len(options) |
|
8831882170fc
Fix height calculation for Multilink.menu()
Stefan Seefeld <stefan@seefeld.name>
parents:
4040
diff
changeset
|
2834 if value: |
|
8831882170fc
Fix height calculation for Multilink.menu()
Stefan Seefeld <stefan@seefeld.name>
parents:
4040
diff
changeset
|
2835 # The "no selection" option. |
|
8831882170fc
Fix height calculation for Multilink.menu()
Stefan Seefeld <stefan@seefeld.name>
parents:
4040
diff
changeset
|
2836 height += 1 |
|
8831882170fc
Fix height calculation for Multilink.menu()
Stefan Seefeld <stefan@seefeld.name>
parents:
4040
diff
changeset
|
2837 height = min(height, 7) |
|
5988
39b8bc511ed7
Fix html generation errors for boolean options.
John Rouillard <rouilj@ieee.org>
parents:
5973
diff
changeset
|
2838 l = ['<select multiple %s>'%self.cgi_escape_attrs(name = self._formname, |
|
4267
c5f52c2c9e36
Provide ability to specify arbitrary HTML attributes.
Stefan Seefeld <stefan@seefeld.name>
parents:
4233
diff
changeset
|
2839 size = height, |
|
c5f52c2c9e36
Provide ability to specify arbitrary HTML attributes.
Stefan Seefeld <stefan@seefeld.name>
parents:
4233
diff
changeset
|
2840 **html_kwargs)] |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2841 k = linkcl.labelprop(1) |
|
1322
c0546b95aad1
finished off handling of retired flag in filter() [SF#635260]
Richard Jones <richard@users.sourceforge.net>
parents:
1320
diff
changeset
|
2842 |
|
5995
b4b5b7afacd9
issue2551007 - Selection fields are not translated
John Rouillard <rouilj@ieee.org>
parents:
5991
diff
changeset
|
2843 if value: # FIXME '- no selection -' mark for translation |
|
4054
6070bc4935fa
Provide a a "no selection" option; cleanup.
Stefan Seefeld <stefan@seefeld.name>
parents:
4053
diff
changeset
|
2844 l.append('<option value="%s">- no selection -</option>' |
|
6070bc4935fa
Provide a a "no selection" option; cleanup.
Stefan Seefeld <stefan@seefeld.name>
parents:
4053
diff
changeset
|
2845 % ','.join(['-' + v for v in value])) |
|
1322
c0546b95aad1
finished off handling of retired flag in filter() [SF#635260]
Richard Jones <richard@users.sourceforge.net>
parents:
1320
diff
changeset
|
2846 |
|
4053
f2030089dac6
Extend "additional" parameter to work with (multi)links.
Stefan Seefeld <stefan@seefeld.name>
parents:
4052
diff
changeset
|
2847 if additional: |
|
f2030089dac6
Extend "additional" parameter to work with (multi)links.
Stefan Seefeld <stefan@seefeld.name>
parents:
4052
diff
changeset
|
2848 additional_fns = [] |
|
f2030089dac6
Extend "additional" parameter to work with (multi)links.
Stefan Seefeld <stefan@seefeld.name>
parents:
4052
diff
changeset
|
2849 props = linkcl.getprops() |
|
f2030089dac6
Extend "additional" parameter to work with (multi)links.
Stefan Seefeld <stefan@seefeld.name>
parents:
4052
diff
changeset
|
2850 for propname in additional: |
|
f2030089dac6
Extend "additional" parameter to work with (multi)links.
Stefan Seefeld <stefan@seefeld.name>
parents:
4052
diff
changeset
|
2851 prop = props[propname] |
|
f2030089dac6
Extend "additional" parameter to work with (multi)links.
Stefan Seefeld <stefan@seefeld.name>
parents:
4052
diff
changeset
|
2852 if isinstance(prop, hyperdb.Link): |
|
f2030089dac6
Extend "additional" parameter to work with (multi)links.
Stefan Seefeld <stefan@seefeld.name>
parents:
4052
diff
changeset
|
2853 cl = self._db.getclass(prop.classname) |
|
f2030089dac6
Extend "additional" parameter to work with (multi)links.
Stefan Seefeld <stefan@seefeld.name>
parents:
4052
diff
changeset
|
2854 labelprop = cl.labelprop() |
|
5062
2ac11cc397eb
Fix arguments to 'menu cgi method
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5061
diff
changeset
|
2855 fn = lambda optionid, cl=cl, linkcl=linkcl, \ |
|
4848
e8ae54db8b95
Fix issue2550822 (3e36a3bc0335 and 843886af0ea1) for multilinks, too
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4847
diff
changeset
|
2856 propname=propname, labelprop=labelprop: \ |
|
e8ae54db8b95
Fix issue2550822 (3e36a3bc0335 and 843886af0ea1) for multilinks, too
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4847
diff
changeset
|
2857 cl.get(linkcl.get(optionid, propname), labelprop) |
|
4053
f2030089dac6
Extend "additional" parameter to work with (multi)links.
Stefan Seefeld <stefan@seefeld.name>
parents:
4052
diff
changeset
|
2858 else: |
|
5062
2ac11cc397eb
Fix arguments to 'menu cgi method
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5061
diff
changeset
|
2859 fn = lambda optionid, linkcl=linkcl, propname=propname: \ |
|
4848
e8ae54db8b95
Fix issue2550822 (3e36a3bc0335 and 843886af0ea1) for multilinks, too
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4847
diff
changeset
|
2860 linkcl.get(optionid, propname) |
|
e8ae54db8b95
Fix issue2550822 (3e36a3bc0335 and 843886af0ea1) for multilinks, too
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4847
diff
changeset
|
2861 additional_fns.append(fn) |
|
4115
d61066deae67
handle bogus pagination values (issue 2550530)
Richard Jones <richard@users.sourceforge.net>
parents:
4112
diff
changeset
|
2862 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2863 for optionid in options: |
|
1169
7b448a2425fd
bugfix to (multi)link menu() label generation
Richard Jones <richard@users.sourceforge.net>
parents:
1163
diff
changeset
|
2864 # get the option value, and if it's None use an empty string |
|
7b448a2425fd
bugfix to (multi)link menu() label generation
Richard Jones <richard@users.sourceforge.net>
parents:
1163
diff
changeset
|
2865 option = linkcl.get(optionid, k) or '' |
|
7b448a2425fd
bugfix to (multi)link menu() label generation
Richard Jones <richard@users.sourceforge.net>
parents:
1163
diff
changeset
|
2866 |
|
7b448a2425fd
bugfix to (multi)link menu() label generation
Richard Jones <richard@users.sourceforge.net>
parents:
1163
diff
changeset
|
2867 # figure if this option is selected |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2868 s = '' |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2869 if optionid in value or option in value: |
|
1952
c40ed9113285
Applied Stefan Seefeld's html4/xhtml patch with some changes.
Richard Jones <richard@users.sourceforge.net>
parents:
1932
diff
changeset
|
2870 s = 'selected="selected" ' |
|
1169
7b448a2425fd
bugfix to (multi)link menu() label generation
Richard Jones <richard@users.sourceforge.net>
parents:
1163
diff
changeset
|
2871 |
|
7b448a2425fd
bugfix to (multi)link menu() label generation
Richard Jones <richard@users.sourceforge.net>
parents:
1163
diff
changeset
|
2872 # figure the label |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2873 if showid: |
|
1079
04b44df7af1d
removed some property name clashes
Richard Jones <richard@users.sourceforge.net>
parents:
1078
diff
changeset
|
2874 lab = '%s%s: %s'%(self._prop.classname, optionid, option) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2875 else: |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2876 lab = option |
|
1169
7b448a2425fd
bugfix to (multi)link menu() label generation
Richard Jones <richard@users.sourceforge.net>
parents:
1163
diff
changeset
|
2877 # truncate if it's too long |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2878 if size is not None and len(lab) > size: |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2879 lab = lab[:size-3] + '...' |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2880 if additional: |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2881 m = [] |
|
4053
f2030089dac6
Extend "additional" parameter to work with (multi)links.
Stefan Seefeld <stefan@seefeld.name>
parents:
4052
diff
changeset
|
2882 for fn in additional_fns: |
|
f2030089dac6
Extend "additional" parameter to work with (multi)links.
Stefan Seefeld <stefan@seefeld.name>
parents:
4052
diff
changeset
|
2883 m.append(str(fn(optionid))) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2884 lab = lab + ' (%s)'%', '.join(m) |
|
1169
7b448a2425fd
bugfix to (multi)link menu() label generation
Richard Jones <richard@users.sourceforge.net>
parents:
1163
diff
changeset
|
2885 |
|
7b448a2425fd
bugfix to (multi)link menu() label generation
Richard Jones <richard@users.sourceforge.net>
parents:
1163
diff
changeset
|
2886 # and generate |
|
4537
61cd652da1cd
Allow to turn off translation of generated html options in menu method...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4524
diff
changeset
|
2887 tr = str |
|
61cd652da1cd
Allow to turn off translation of generated html options in menu method...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4524
diff
changeset
|
2888 if translate: |
|
61cd652da1cd
Allow to turn off translation of generated html options in menu method...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4524
diff
changeset
|
2889 tr = self._ |
|
5800
1a835db41674
Call cgi.escape only on python 2. Replace with html.escapeif it can be
John Rouillard <rouilj@ieee.org>
parents:
5684
diff
changeset
|
2890 lab = html_escape(tr(lab)) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2891 l.append('<option %svalue="%s">%s</option>'%(s, optionid, |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2892 lab)) |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2893 l.append('</select>') |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2894 return '\n'.join(l) |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2895 |
|
4396
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
2896 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2897 # set the propclasses for HTMLItem |
|
4396
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
2898 propclasses = [ |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2899 (hyperdb.String, StringHTMLProperty), |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2900 (hyperdb.Number, NumberHTMLProperty), |
|
5067
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5062
diff
changeset
|
2901 (hyperdb.Integer, IntegerHTMLProperty), |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2902 (hyperdb.Boolean, BooleanHTMLProperty), |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2903 (hyperdb.Date, DateHTMLProperty), |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2904 (hyperdb.Interval, IntervalHTMLProperty), |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2905 (hyperdb.Password, PasswordHTMLProperty), |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2906 (hyperdb.Link, LinkHTMLProperty), |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2907 (hyperdb.Multilink, MultilinkHTMLProperty), |
|
4396
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
2908 ] |
|
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
2909 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
2910 |
|
4396
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
2911 def register_propclass(prop, cls): |
|
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
2912 for index,propclass in enumerate(propclasses): |
|
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
2913 p, c = propclass |
|
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
2914 if prop == p: |
|
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
2915 propclasses[index] = (prop, cls) |
|
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
2916 break |
|
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
2917 else: |
|
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
2918 propclasses.append((prop, cls)) |
|
172489ea9e07
allow trackers to override the classes used to render properties...
Richard Jones <richard@users.sourceforge.net>
parents:
4391
diff
changeset
|
2919 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2920 |
|
5414
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
2921 def make_key_function(db, classname, sort_on=None): |
|
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
2922 """Make a sort key function for a given class. |
|
4417
cc36be59ebd8
make sort more robust
Richard Jones <richard@users.sourceforge.net>
parents:
4413
diff
changeset
|
2923 |
|
cc36be59ebd8
make sort more robust
Richard Jones <richard@users.sourceforge.net>
parents:
4413
diff
changeset
|
2924 The list being sorted may contain mixed ids and labels. |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2925 """ |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2926 linkcl = db.getclass(classname) |
|
1983
75437090134e
implement built-in permission checks for rendered fields...
Richard Jones <richard@users.sourceforge.net>
parents:
1956
diff
changeset
|
2927 if sort_on is None: |
| 4032 | 2928 sort_on = linkcl.orderprop() |
|
7021
4e25815961a7
flake8: remove trailing whitespace; blank lines for definitions
John Rouillard <rouilj@ieee.org>
parents:
7020
diff
changeset
|
2929 |
|
5414
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
2930 def keyfunc(a): |
|
4417
cc36be59ebd8
make sort more robust
Richard Jones <richard@users.sourceforge.net>
parents:
4413
diff
changeset
|
2931 if num_re.match(a): |
|
cc36be59ebd8
make sort more robust
Richard Jones <richard@users.sourceforge.net>
parents:
4413
diff
changeset
|
2932 a = linkcl.get(a, sort_on) |
|
6689
994893cf3e1a
Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6658
diff
changeset
|
2933 # In Python3 we may not compare strings and None |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
2934 if a is None: |
|
6689
994893cf3e1a
Fix traceback if an order attribute is None
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6658
diff
changeset
|
2935 return '' |
|
5414
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
2936 return a |
|
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5404
diff
changeset
|
2937 return keyfunc |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2938 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
2939 |
|
1202
01a143f9382e
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
1201
diff
changeset
|
2940 def handleListCGIValue(value): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2941 """ Value is either a single item or a list of items. Each item has a |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2942 .value that we're actually interested in. |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2943 """ |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2944 if isinstance(value, type([])): |
|
1202
01a143f9382e
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
1201
diff
changeset
|
2945 return [value.value for value in value] |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2946 else: |
|
1104
d759c3cb1f06
Remeber values in edit/new submission error pages.
Richard Jones <richard@users.sourceforge.net>
parents:
1103
diff
changeset
|
2947 value = value.value.strip() |
|
d759c3cb1f06
Remeber values in edit/new submission error pages.
Richard Jones <richard@users.sourceforge.net>
parents:
1103
diff
changeset
|
2948 if not value: |
|
d759c3cb1f06
Remeber values in edit/new submission error pages.
Richard Jones <richard@users.sourceforge.net>
parents:
1103
diff
changeset
|
2949 return [] |
|
3972
eee76dd4a09f
'Make a Copy' failed with more than one person in nosy list [SF#1906147]
Richard Jones <richard@users.sourceforge.net>
parents:
3971
diff
changeset
|
2950 return [v.strip() for v in value.split(',')] |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2951 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
2952 |
|
1956
1e2cccf6b53b
give access to the input() method all over the place
Richard Jones <richard@users.sourceforge.net>
parents:
1952
diff
changeset
|
2953 class HTMLRequest(HTMLInputMixin): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2954 """The *request*, holding the CGI form and environment. |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2955 |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
2956 - "form" the CGI form as a cgi.FieldStorage |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
2957 - "env" the CGI environment variables |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
2958 - "base" the base URL for this instance |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
2959 - "user" a HTMLItem instance for this user |
|
3968
5857cd1a0db9
add language to the "request" template var
Richard Jones <richard@users.sourceforge.net>
parents:
3936
diff
changeset
|
2960 - "language" as determined by the browser or config |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
2961 - "classname" the current classname (possibly None) |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
2962 - "template" the current template (suffix, also possibly None) |
|
1004
5f12d3259f31
logout works better now
Richard Jones <richard@users.sourceforge.net>
parents:
1003
diff
changeset
|
2963 |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
2964 Index args: |
|
1004
5f12d3259f31
logout works better now
Richard Jones <richard@users.sourceforge.net>
parents:
1003
diff
changeset
|
2965 |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
2966 - "columns" dictionary of the columns to display in an index page |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
2967 - "show" a convenience access to columns - request/show/colname will |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
2968 be true if the columns should be displayed, false otherwise |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
2969 - "sort" index sort column (direction, column name) |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
2970 - "group" index grouping property (direction, column name) |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
2971 - "filter" properties to filter the index on |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
2972 - "filterspec" values to filter the index on |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
2002
diff
changeset
|
2973 - "search_text" text to perform a full-text search on for an index |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
2974 """ |
|
3505
b294cc477f2c
ZRoundup works again [SF#1263842]
Richard Jones <richard@users.sourceforge.net>
parents:
3479
diff
changeset
|
2975 def __repr__(self): |
|
3736
a2d22d0de0bc
WSGI support via roundup.cgi.wsgi_handler
Richard Jones <richard@users.sourceforge.net>
parents:
3710
diff
changeset
|
2976 return '<HTMLRequest %r>'%self.__dict__ |
|
3505
b294cc477f2c
ZRoundup works again [SF#1263842]
Richard Jones <richard@users.sourceforge.net>
parents:
3479
diff
changeset
|
2977 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2978 def __init__(self, client): |
|
1956
1e2cccf6b53b
give access to the input() method all over the place
Richard Jones <richard@users.sourceforge.net>
parents:
1952
diff
changeset
|
2979 # _client is needed by HTMLInputMixin |
|
1e2cccf6b53b
give access to the input() method all over the place
Richard Jones <richard@users.sourceforge.net>
parents:
1952
diff
changeset
|
2980 self._client = self.client = client |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2981 |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2982 # easier access vars |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2983 self.form = client.form |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2984 self.env = client.env |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2985 self.base = client.base |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
2986 self.user = HTMLItem(client, 'user', client.userid) |
|
3968
5857cd1a0db9
add language to the "request" template var
Richard Jones <richard@users.sourceforge.net>
parents:
3936
diff
changeset
|
2987 self.language = client.language |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2988 |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2989 # store the current class name and action |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2990 self.classname = client.classname |
|
3584
35b35a152b40
fix "clear this message" [SF#1429367]
Richard Jones <richard@users.sourceforge.net>
parents:
3582
diff
changeset
|
2991 self.nodeid = client.nodeid |
|
1041
c28603c9f831
Class help and generic class editing done.
Richard Jones <richard@users.sourceforge.net>
parents:
1030
diff
changeset
|
2992 self.template = client.template |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2993 |
|
1421
90bb11eb40dc
oops, forgot the templating :)
Richard Jones <richard@users.sourceforge.net>
parents:
1417
diff
changeset
|
2994 # the special char to use for special vars |
|
90bb11eb40dc
oops, forgot the templating :)
Richard Jones <richard@users.sourceforge.net>
parents:
1417
diff
changeset
|
2995 self.special_char = '@' |
|
90bb11eb40dc
oops, forgot the templating :)
Richard Jones <richard@users.sourceforge.net>
parents:
1417
diff
changeset
|
2996 |
|
1956
1e2cccf6b53b
give access to the input() method all over the place
Richard Jones <richard@users.sourceforge.net>
parents:
1952
diff
changeset
|
2997 HTMLInputMixin.__init__(self) |
|
1952
c40ed9113285
Applied Stefan Seefeld's html4/xhtml patch with some changes.
Richard Jones <richard@users.sourceforge.net>
parents:
1932
diff
changeset
|
2998 |
|
1097
98f3d41f41d9
query "editing" now working, minus filling the form in with the query params
Richard Jones <richard@users.sourceforge.net>
parents:
1096
diff
changeset
|
2999 self._post_init() |
|
98f3d41f41d9
query "editing" now working, minus filling the form in with the query params
Richard Jones <richard@users.sourceforge.net>
parents:
1096
diff
changeset
|
3000 |
|
3584
35b35a152b40
fix "clear this message" [SF#1429367]
Richard Jones <richard@users.sourceforge.net>
parents:
3582
diff
changeset
|
3001 def current_url(self): |
|
35b35a152b40
fix "clear this message" [SF#1429367]
Richard Jones <richard@users.sourceforge.net>
parents:
3582
diff
changeset
|
3002 url = self.base |
|
35b35a152b40
fix "clear this message" [SF#1429367]
Richard Jones <richard@users.sourceforge.net>
parents:
3582
diff
changeset
|
3003 if self.classname: |
|
35b35a152b40
fix "clear this message" [SF#1429367]
Richard Jones <richard@users.sourceforge.net>
parents:
3582
diff
changeset
|
3004 url += self.classname |
|
35b35a152b40
fix "clear this message" [SF#1429367]
Richard Jones <richard@users.sourceforge.net>
parents:
3582
diff
changeset
|
3005 if self.nodeid: |
|
35b35a152b40
fix "clear this message" [SF#1429367]
Richard Jones <richard@users.sourceforge.net>
parents:
3582
diff
changeset
|
3006 url += self.nodeid |
|
35b35a152b40
fix "clear this message" [SF#1429367]
Richard Jones <richard@users.sourceforge.net>
parents:
3582
diff
changeset
|
3007 args = {} |
|
35b35a152b40
fix "clear this message" [SF#1429367]
Richard Jones <richard@users.sourceforge.net>
parents:
3582
diff
changeset
|
3008 if self.template: |
|
35b35a152b40
fix "clear this message" [SF#1429367]
Richard Jones <richard@users.sourceforge.net>
parents:
3582
diff
changeset
|
3009 args['@template'] = self.template |
|
35b35a152b40
fix "clear this message" [SF#1429367]
Richard Jones <richard@users.sourceforge.net>
parents:
3582
diff
changeset
|
3010 return self.indexargs_url(url, args) |
|
35b35a152b40
fix "clear this message" [SF#1429367]
Richard Jones <richard@users.sourceforge.net>
parents:
3582
diff
changeset
|
3011 |
|
3696
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3012 def _parse_sort(self, var, name): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
3013 """ Parse sort/group options. Append to var |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
3014 """ |
|
3696
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3015 fields = [] |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3016 dirs = [] |
|
3698
c2d232b377d5
optimize parsing of sort/group options according to suggestion...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3696
diff
changeset
|
3017 for special in '@:': |
|
3696
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3018 idx = 0 |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3019 key = '%s%s%d'%(special, name, idx) |
|
4804
bc4144417861
More fixes for form TypeError
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4791
diff
changeset
|
3020 while self._form_has_key(key): |
|
3696
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3021 self.special_char = special |
|
4040
b6a2251394dd
Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents:
4032
diff
changeset
|
3022 fields.append(self.form.getfirst(key)) |
|
3696
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3023 dirkey = '%s%sdir%d'%(special, name, idx) |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3024 if dirkey in self.form: |
|
4040
b6a2251394dd
Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents:
4032
diff
changeset
|
3025 dirs.append(self.form.getfirst(dirkey)) |
|
3696
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3026 else: |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3027 dirs.append(None) |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3028 idx += 1 |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3029 key = '%s%s%d'%(special, name, idx) |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3030 # backward compatible (and query) URL format |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3031 key = special + name |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3032 dirkey = key + 'dir' |
|
4804
bc4144417861
More fixes for form TypeError
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4791
diff
changeset
|
3033 if self._form_has_key(key) and not fields: |
|
3696
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3034 fields = handleListCGIValue(self.form[key]) |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3035 if dirkey in self.form: |
|
4040
b6a2251394dd
Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents:
4032
diff
changeset
|
3036 dirs.append(self.form.getfirst(dirkey)) |
|
7022
f4bfc1af5d95
flake8 inline comment spacing; too many leading #
John Rouillard <rouilj@ieee.org>
parents:
7021
diff
changeset
|
3037 if fields: # only try other special char if nothing found |
|
3696
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3038 break |
| 5095 | 3039 |
| 3040 # sometimes requests come in without a class | |
| 3041 # chances are they won't have any filter params, | |
| 3042 # in that case anyway but... | |
| 3043 if self.classname: | |
| 3044 cls = self.client.db.getclass(self.classname) | |
|
5399
dccae35caa59
Python 3 preparation: update map() calls as needed.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5395
diff
changeset
|
3045 for f, d in zip_longest(fields, dirs): |
|
3696
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3046 if f.startswith('-'): |
|
5094
92d33d3125a0
Validate properties specified for sorting and grouping in index
John Rouillard <rouilj@ieee.org>
parents:
5087
diff
changeset
|
3047 dir, propname = '-', f[1:] |
|
3696
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3048 elif d: |
|
5094
92d33d3125a0
Validate properties specified for sorting and grouping in index
John Rouillard <rouilj@ieee.org>
parents:
5087
diff
changeset
|
3049 dir, propname = '-', f |
|
3696
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3050 else: |
|
5094
92d33d3125a0
Validate properties specified for sorting and grouping in index
John Rouillard <rouilj@ieee.org>
parents:
5087
diff
changeset
|
3051 dir, propname = '+', f |
| 5095 | 3052 # if no classname, just append the propname unchecked. |
| 3053 # this may be valid for some actions that bypass classes. | |
| 3054 if self.classname and cls.get_transitive_prop(propname) is None: | |
|
5094
92d33d3125a0
Validate properties specified for sorting and grouping in index
John Rouillard <rouilj@ieee.org>
parents:
5087
diff
changeset
|
3055 self.client.add_error_message("Unknown %s property %s"%(name, propname)) |
|
92d33d3125a0
Validate properties specified for sorting and grouping in index
John Rouillard <rouilj@ieee.org>
parents:
5087
diff
changeset
|
3056 else: |
|
92d33d3125a0
Validate properties specified for sorting and grouping in index
John Rouillard <rouilj@ieee.org>
parents:
5087
diff
changeset
|
3057 var.append((dir, propname)) |
|
3696
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3058 |
|
4804
bc4144417861
More fixes for form TypeError
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4791
diff
changeset
|
3059 def _form_has_key(self, name): |
|
bc4144417861
More fixes for form TypeError
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4791
diff
changeset
|
3060 try: |
|
5381
0942fe89e82e
Python 3 preparation: change "x.has_key(y)" to "y in x".
Joseph Myers <jsm@polyomino.org.uk>
parents:
5378
diff
changeset
|
3061 return name in self.form |
|
4804
bc4144417861
More fixes for form TypeError
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4791
diff
changeset
|
3062 except TypeError: |
|
bc4144417861
More fixes for form TypeError
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4791
diff
changeset
|
3063 pass |
|
bc4144417861
More fixes for form TypeError
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4791
diff
changeset
|
3064 return False |
|
bc4144417861
More fixes for form TypeError
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4791
diff
changeset
|
3065 |
|
1097
98f3d41f41d9
query "editing" now working, minus filling the form in with the query params
Richard Jones <richard@users.sourceforge.net>
parents:
1096
diff
changeset
|
3066 def _post_init(self): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
3067 """ Set attributes based on self.form |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
3068 """ |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3069 # extract the index display information from the form |
|
1016
d6c13142e7b9
Keep a cache of compiled PageTemplates.
Richard Jones <richard@users.sourceforge.net>
parents:
1008
diff
changeset
|
3070 self.columns = [] |
|
1436
2f6647cf5345
bugger, dropping support for "+" special char
Richard Jones <richard@users.sourceforge.net>
parents:
1421
diff
changeset
|
3071 for name in ':columns @columns'.split(): |
|
4804
bc4144417861
More fixes for form TypeError
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4791
diff
changeset
|
3072 if self._form_has_key(name): |
|
1421
90bb11eb40dc
oops, forgot the templating :)
Richard Jones <richard@users.sourceforge.net>
parents:
1417
diff
changeset
|
3073 self.special_char = name[0] |
|
90bb11eb40dc
oops, forgot the templating :)
Richard Jones <richard@users.sourceforge.net>
parents:
1417
diff
changeset
|
3074 self.columns = handleListCGIValue(self.form[name]) |
|
90bb11eb40dc
oops, forgot the templating :)
Richard Jones <richard@users.sourceforge.net>
parents:
1417
diff
changeset
|
3075 break |
|
2983
9614a101b68f
Stuff from the train ride this morning:
Richard Jones <richard@users.sourceforge.net>
parents:
2962
diff
changeset
|
3076 self.show = support.TruthDict(self.columns) |
|
4437
261c9f913ff7
- Add explicit "Search" permissions, see Security Fix below.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4417
diff
changeset
|
3077 security = self._client.db.security |
|
261c9f913ff7
- Add explicit "Search" permissions, see Security Fix below.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4417
diff
changeset
|
3078 userid = self._client.userid |
| 1002 | 3079 |
|
3696
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3080 # sorting and grouping |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3081 self.sort = [] |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3082 self.group = [] |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3083 self._parse_sort(self.sort, 'sort') |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3084 self._parse_sort(self.group, 'group') |
|
4437
261c9f913ff7
- Add explicit "Search" permissions, see Security Fix below.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4417
diff
changeset
|
3085 self.sort = security.filterSortspec(userid, self.classname, self.sort) |
|
261c9f913ff7
- Add explicit "Search" permissions, see Security Fix below.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4417
diff
changeset
|
3086 self.group = security.filterSortspec(userid, self.classname, self.group) |
| 1002 | 3087 |
| 3088 # filtering | |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3089 self.filter = [] |
|
1436
2f6647cf5345
bugger, dropping support for "+" special char
Richard Jones <richard@users.sourceforge.net>
parents:
1421
diff
changeset
|
3090 for name in ':filter @filter'.split(): |
|
4804
bc4144417861
More fixes for form TypeError
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4791
diff
changeset
|
3091 if self._form_has_key(name): |
|
1421
90bb11eb40dc
oops, forgot the templating :)
Richard Jones <richard@users.sourceforge.net>
parents:
1417
diff
changeset
|
3092 self.special_char = name[0] |
|
90bb11eb40dc
oops, forgot the templating :)
Richard Jones <richard@users.sourceforge.net>
parents:
1417
diff
changeset
|
3093 self.filter = handleListCGIValue(self.form[name]) |
|
90bb11eb40dc
oops, forgot the templating :)
Richard Jones <richard@users.sourceforge.net>
parents:
1417
diff
changeset
|
3094 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3095 self.filterspec = {} |
|
1200
0a7bd082b94a
usability improvements in API
Richard Jones <richard@users.sourceforge.net>
parents:
1183
diff
changeset
|
3096 db = self.client.db |
|
1003
f89b8d32291b
Hack hack hack...
Richard Jones <richard@users.sourceforge.net>
parents:
1002
diff
changeset
|
3097 if self.classname is not None: |
|
7020
86312ca47ad7
flake8 E211 remove space before ( in function calls
John Rouillard <rouilj@ieee.org>
parents:
7019
diff
changeset
|
3098 cls = db.getclass(self.classname) |
|
1003
f89b8d32291b
Hack hack hack...
Richard Jones <richard@users.sourceforge.net>
parents:
1002
diff
changeset
|
3099 for name in self.filter: |
|
4804
bc4144417861
More fixes for form TypeError
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4791
diff
changeset
|
3100 if not self._form_has_key(name): |
|
1631
8a908bbad1ef
A couple of form value handling changes:
Richard Jones <richard@users.sourceforge.net>
parents:
1591
diff
changeset
|
3101 continue |
|
7020
86312ca47ad7
flake8 E211 remove space before ( in function calls
John Rouillard <rouilj@ieee.org>
parents:
7019
diff
changeset
|
3102 prop = cls.get_transitive_prop(name) |
|
1631
8a908bbad1ef
A couple of form value handling changes:
Richard Jones <richard@users.sourceforge.net>
parents:
1591
diff
changeset
|
3103 fv = self.form[name] |
|
8a908bbad1ef
A couple of form value handling changes:
Richard Jones <richard@users.sourceforge.net>
parents:
1591
diff
changeset
|
3104 if (isinstance(prop, hyperdb.Link) or |
|
8a908bbad1ef
A couple of form value handling changes:
Richard Jones <richard@users.sourceforge.net>
parents:
1591
diff
changeset
|
3105 isinstance(prop, hyperdb.Multilink)): |
|
8a908bbad1ef
A couple of form value handling changes:
Richard Jones <richard@users.sourceforge.net>
parents:
1591
diff
changeset
|
3106 self.filterspec[name] = lookupIds(db, prop, |
|
8a908bbad1ef
A couple of form value handling changes:
Richard Jones <richard@users.sourceforge.net>
parents:
1591
diff
changeset
|
3107 handleListCGIValue(fv)) |
|
8a908bbad1ef
A couple of form value handling changes:
Richard Jones <richard@users.sourceforge.net>
parents:
1591
diff
changeset
|
3108 else: |
|
8a908bbad1ef
A couple of form value handling changes:
Richard Jones <richard@users.sourceforge.net>
parents:
1591
diff
changeset
|
3109 if isinstance(fv, type([])): |
|
8a908bbad1ef
A couple of form value handling changes:
Richard Jones <richard@users.sourceforge.net>
parents:
1591
diff
changeset
|
3110 self.filterspec[name] = [v.value for v in fv] |
|
3461
fb82ab9461b0
fix comma-separated ID filter spec in web requests [SF#1396278]
Richard Jones <richard@users.sourceforge.net>
parents:
3401
diff
changeset
|
3111 elif name == 'id': |
|
fb82ab9461b0
fix comma-separated ID filter spec in web requests [SF#1396278]
Richard Jones <richard@users.sourceforge.net>
parents:
3401
diff
changeset
|
3112 # special case "id" property |
|
fb82ab9461b0
fix comma-separated ID filter spec in web requests [SF#1396278]
Richard Jones <richard@users.sourceforge.net>
parents:
3401
diff
changeset
|
3113 self.filterspec[name] = handleListCGIValue(fv) |
|
1003
f89b8d32291b
Hack hack hack...
Richard Jones <richard@users.sourceforge.net>
parents:
1002
diff
changeset
|
3114 else: |
|
f89b8d32291b
Hack hack hack...
Richard Jones <richard@users.sourceforge.net>
parents:
1002
diff
changeset
|
3115 self.filterspec[name] = fv.value |
|
4437
261c9f913ff7
- Add explicit "Search" permissions, see Security Fix below.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4417
diff
changeset
|
3116 self.filterspec = security.filterFilterspec(userid, self.classname, |
|
261c9f913ff7
- Add explicit "Search" permissions, see Security Fix below.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4417
diff
changeset
|
3117 self.filterspec) |
| 1002 | 3118 |
| 3119 # full-text search argument | |
| 3120 self.search_text = None | |
|
1436
2f6647cf5345
bugger, dropping support for "+" special char
Richard Jones <richard@users.sourceforge.net>
parents:
1421
diff
changeset
|
3121 for name in ':search_text @search_text'.split(): |
|
4804
bc4144417861
More fixes for form TypeError
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4791
diff
changeset
|
3122 if self._form_has_key(name): |
|
1421
90bb11eb40dc
oops, forgot the templating :)
Richard Jones <richard@users.sourceforge.net>
parents:
1417
diff
changeset
|
3123 self.special_char = name[0] |
|
4040
b6a2251394dd
Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents:
4032
diff
changeset
|
3124 self.search_text = self.form.getfirst(name) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3125 |
|
1016
d6c13142e7b9
Keep a cache of compiled PageTemplates.
Richard Jones <richard@users.sourceforge.net>
parents:
1008
diff
changeset
|
3126 # pagination - size and start index |
|
d6c13142e7b9
Keep a cache of compiled PageTemplates.
Richard Jones <richard@users.sourceforge.net>
parents:
1008
diff
changeset
|
3127 # figure batch args |
|
3158
cf824afdb76b
*cough* nothing to see here
Richard Jones <richard@users.sourceforge.net>
parents:
3157
diff
changeset
|
3128 self.pagesize = 50 |
|
1436
2f6647cf5345
bugger, dropping support for "+" special char
Richard Jones <richard@users.sourceforge.net>
parents:
1421
diff
changeset
|
3129 for name in ':pagesize @pagesize'.split(): |
|
4804
bc4144417861
More fixes for form TypeError
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4791
diff
changeset
|
3130 if self._form_has_key(name): |
|
1421
90bb11eb40dc
oops, forgot the templating :)
Richard Jones <richard@users.sourceforge.net>
parents:
1417
diff
changeset
|
3131 self.special_char = name[0] |
|
4115
d61066deae67
handle bogus pagination values (issue 2550530)
Richard Jones <richard@users.sourceforge.net>
parents:
4112
diff
changeset
|
3132 try: |
|
d61066deae67
handle bogus pagination values (issue 2550530)
Richard Jones <richard@users.sourceforge.net>
parents:
4112
diff
changeset
|
3133 self.pagesize = int(self.form.getfirst(name)) |
|
d61066deae67
handle bogus pagination values (issue 2550530)
Richard Jones <richard@users.sourceforge.net>
parents:
4112
diff
changeset
|
3134 except ValueError: |
|
d61066deae67
handle bogus pagination values (issue 2550530)
Richard Jones <richard@users.sourceforge.net>
parents:
4112
diff
changeset
|
3135 # not an integer - ignore |
|
d61066deae67
handle bogus pagination values (issue 2550530)
Richard Jones <richard@users.sourceforge.net>
parents:
4112
diff
changeset
|
3136 pass |
|
1421
90bb11eb40dc
oops, forgot the templating :)
Richard Jones <richard@users.sourceforge.net>
parents:
1417
diff
changeset
|
3137 |
|
90bb11eb40dc
oops, forgot the templating :)
Richard Jones <richard@users.sourceforge.net>
parents:
1417
diff
changeset
|
3138 self.startwith = 0 |
|
1436
2f6647cf5345
bugger, dropping support for "+" special char
Richard Jones <richard@users.sourceforge.net>
parents:
1421
diff
changeset
|
3139 for name in ':startwith @startwith'.split(): |
|
4804
bc4144417861
More fixes for form TypeError
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4791
diff
changeset
|
3140 if self._form_has_key(name): |
|
1421
90bb11eb40dc
oops, forgot the templating :)
Richard Jones <richard@users.sourceforge.net>
parents:
1417
diff
changeset
|
3141 self.special_char = name[0] |
|
4115
d61066deae67
handle bogus pagination values (issue 2550530)
Richard Jones <richard@users.sourceforge.net>
parents:
4112
diff
changeset
|
3142 try: |
|
d61066deae67
handle bogus pagination values (issue 2550530)
Richard Jones <richard@users.sourceforge.net>
parents:
4112
diff
changeset
|
3143 self.startwith = int(self.form.getfirst(name)) |
|
d61066deae67
handle bogus pagination values (issue 2550530)
Richard Jones <richard@users.sourceforge.net>
parents:
4112
diff
changeset
|
3144 except ValueError: |
|
d61066deae67
handle bogus pagination values (issue 2550530)
Richard Jones <richard@users.sourceforge.net>
parents:
4112
diff
changeset
|
3145 # not an integer - ignore |
|
d61066deae67
handle bogus pagination values (issue 2550530)
Richard Jones <richard@users.sourceforge.net>
parents:
4112
diff
changeset
|
3146 pass |
|
1016
d6c13142e7b9
Keep a cache of compiled PageTemplates.
Richard Jones <richard@users.sourceforge.net>
parents:
1008
diff
changeset
|
3147 |
|
3549
f6719836e521
allow dispname to be passed to renderWith [SF#1424587]
Richard Jones <richard@users.sourceforge.net>
parents:
3535
diff
changeset
|
3148 # dispname |
|
4804
bc4144417861
More fixes for form TypeError
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4791
diff
changeset
|
3149 if self._form_has_key('@dispname'): |
|
4040
b6a2251394dd
Make cgi.templating more fault-tolerant towards invalid requests.
Stefan Seefeld <stefan@seefeld.name>
parents:
4032
diff
changeset
|
3150 self.dispname = self.form.getfirst('@dispname') |
|
3689
c28d94070403
fix: HTMLRequest.dispname must be string,
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3665
diff
changeset
|
3151 else: |
|
c28d94070403
fix: HTMLRequest.dispname must be string,
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3665
diff
changeset
|
3152 self.dispname = None |
|
3549
f6719836e521
allow dispname to be passed to renderWith [SF#1424587]
Richard Jones <richard@users.sourceforge.net>
parents:
3535
diff
changeset
|
3153 |
|
1097
98f3d41f41d9
query "editing" now working, minus filling the form in with the query params
Richard Jones <richard@users.sourceforge.net>
parents:
1096
diff
changeset
|
3154 def updateFromURL(self, url): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
3155 """ Parse the URL for query args, and update my attributes using the |
|
1097
98f3d41f41d9
query "editing" now working, minus filling the form in with the query params
Richard Jones <richard@users.sourceforge.net>
parents:
1096
diff
changeset
|
3156 values. |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
3157 """ |
|
1693
7218be26cf85
attempt to fix query editing
Richard Jones <richard@users.sourceforge.net>
parents:
1633
diff
changeset
|
3158 env = {'QUERY_STRING': url} |
|
7218be26cf85
attempt to fix query editing
Richard Jones <richard@users.sourceforge.net>
parents:
1633
diff
changeset
|
3159 self.form = cgi.FieldStorage(environ=env) |
|
7218be26cf85
attempt to fix query editing
Richard Jones <richard@users.sourceforge.net>
parents:
1633
diff
changeset
|
3160 |
|
1097
98f3d41f41d9
query "editing" now working, minus filling the form in with the query params
Richard Jones <richard@users.sourceforge.net>
parents:
1096
diff
changeset
|
3161 self._post_init() |
|
98f3d41f41d9
query "editing" now working, minus filling the form in with the query params
Richard Jones <richard@users.sourceforge.net>
parents:
1096
diff
changeset
|
3162 |
|
1016
d6c13142e7b9
Keep a cache of compiled PageTemplates.
Richard Jones <richard@users.sourceforge.net>
parents:
1008
diff
changeset
|
3163 def update(self, kwargs): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
3164 """ Update my attributes using the keyword args |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
3165 """ |
|
1016
d6c13142e7b9
Keep a cache of compiled PageTemplates.
Richard Jones <richard@users.sourceforge.net>
parents:
1008
diff
changeset
|
3166 self.__dict__.update(kwargs) |
|
5381
0942fe89e82e
Python 3 preparation: change "x.has_key(y)" to "y in x".
Joseph Myers <jsm@polyomino.org.uk>
parents:
5378
diff
changeset
|
3167 if 'columns' in kwargs: |
|
2983
9614a101b68f
Stuff from the train ride this morning:
Richard Jones <richard@users.sourceforge.net>
parents:
2962
diff
changeset
|
3168 self.show = support.TruthDict(self.columns) |
|
1016
d6c13142e7b9
Keep a cache of compiled PageTemplates.
Richard Jones <richard@users.sourceforge.net>
parents:
1008
diff
changeset
|
3169 |
|
1061
7f9b942128a3
nicer page title
Richard Jones <richard@users.sourceforge.net>
parents:
1051
diff
changeset
|
3170 def description(self): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
3171 """ Return a description of the request - handle for the page title. |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
3172 """ |
|
1096
fa7df238e2d4
More cleaning up of configuration, and the "instance" -> "tracker" renaming.
Richard Jones <richard@users.sourceforge.net>
parents:
1080
diff
changeset
|
3173 s = [self.client.db.config.TRACKER_NAME] |
|
1061
7f9b942128a3
nicer page title
Richard Jones <richard@users.sourceforge.net>
parents:
1051
diff
changeset
|
3174 if self.classname: |
|
7f9b942128a3
nicer page title
Richard Jones <richard@users.sourceforge.net>
parents:
1051
diff
changeset
|
3175 if self.client.nodeid: |
|
7f9b942128a3
nicer page title
Richard Jones <richard@users.sourceforge.net>
parents:
1051
diff
changeset
|
3176 s.append('- %s%s'%(self.classname, self.client.nodeid)) |
|
7f9b942128a3
nicer page title
Richard Jones <richard@users.sourceforge.net>
parents:
1051
diff
changeset
|
3177 else: |
|
1123
644d3075c2df
more documentation, fixed bug in request/description
Richard Jones <richard@users.sourceforge.net>
parents:
1122
diff
changeset
|
3178 if self.template == 'item': |
|
644d3075c2df
more documentation, fixed bug in request/description
Richard Jones <richard@users.sourceforge.net>
parents:
1122
diff
changeset
|
3179 s.append('- new %s'%self.classname) |
|
644d3075c2df
more documentation, fixed bug in request/description
Richard Jones <richard@users.sourceforge.net>
parents:
1122
diff
changeset
|
3180 elif self.template == 'index': |
|
644d3075c2df
more documentation, fixed bug in request/description
Richard Jones <richard@users.sourceforge.net>
parents:
1122
diff
changeset
|
3181 s.append('- %s index'%self.classname) |
|
644d3075c2df
more documentation, fixed bug in request/description
Richard Jones <richard@users.sourceforge.net>
parents:
1122
diff
changeset
|
3182 else: |
|
644d3075c2df
more documentation, fixed bug in request/description
Richard Jones <richard@users.sourceforge.net>
parents:
1122
diff
changeset
|
3183 s.append('- %s %s'%(self.classname, self.template)) |
|
1061
7f9b942128a3
nicer page title
Richard Jones <richard@users.sourceforge.net>
parents:
1051
diff
changeset
|
3184 else: |
|
7f9b942128a3
nicer page title
Richard Jones <richard@users.sourceforge.net>
parents:
1051
diff
changeset
|
3185 s.append('- home') |
|
7f9b942128a3
nicer page title
Richard Jones <richard@users.sourceforge.net>
parents:
1051
diff
changeset
|
3186 return ' '.join(s) |
|
7f9b942128a3
nicer page title
Richard Jones <richard@users.sourceforge.net>
parents:
1051
diff
changeset
|
3187 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3188 def __str__(self): |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3189 d = {} |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3190 d.update(self.__dict__) |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3191 f = '' |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3192 for k in self.form.keys(): |
|
1202
01a143f9382e
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
1201
diff
changeset
|
3193 f += '\n %r=%r'%(k,handleListCGIValue(self.form[k])) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3194 d['form'] = f |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3195 e = '' |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3196 for k,v in self.env.items(): |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3197 e += '\n %r=%r'%(k, v) |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3198 d['env'] = e |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
3199 return """ |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3200 form: %(form)s |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3201 base: %(base)r |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3202 classname: %(classname)r |
|
1041
c28603c9f831
Class help and generic class editing done.
Richard Jones <richard@users.sourceforge.net>
parents:
1030
diff
changeset
|
3203 template: %(template)r |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3204 columns: %(columns)r |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3205 sort: %(sort)r |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3206 group: %(group)r |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3207 filter: %(filter)r |
|
1016
d6c13142e7b9
Keep a cache of compiled PageTemplates.
Richard Jones <richard@users.sourceforge.net>
parents:
1008
diff
changeset
|
3208 search_text: %(search_text)r |
|
d6c13142e7b9
Keep a cache of compiled PageTemplates.
Richard Jones <richard@users.sourceforge.net>
parents:
1008
diff
changeset
|
3209 pagesize: %(pagesize)r |
|
d6c13142e7b9
Keep a cache of compiled PageTemplates.
Richard Jones <richard@users.sourceforge.net>
parents:
1008
diff
changeset
|
3210 startwith: %(startwith)r |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3211 env: %(env)s |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
3212 """%d |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3213 |
| 1002 | 3214 def indexargs_form(self, columns=1, sort=1, group=1, filter=1, |
|
5082
c1f1465d5303
issue2550683 Allow indexargs_form filter variable exclusion.
John Rouillard <rouilj@ieee.org>
parents:
5067
diff
changeset
|
3215 filterspec=1, search_text=1, exclude=[]): |
|
c1f1465d5303
issue2550683 Allow indexargs_form filter variable exclusion.
John Rouillard <rouilj@ieee.org>
parents:
5067
diff
changeset
|
3216 """ return the current index args as form elements |
|
c1f1465d5303
issue2550683 Allow indexargs_form filter variable exclusion.
John Rouillard <rouilj@ieee.org>
parents:
5067
diff
changeset
|
3217 |
|
c1f1465d5303
issue2550683 Allow indexargs_form filter variable exclusion.
John Rouillard <rouilj@ieee.org>
parents:
5067
diff
changeset
|
3218 This routine generates an html form with hidden elements. |
|
c1f1465d5303
issue2550683 Allow indexargs_form filter variable exclusion.
John Rouillard <rouilj@ieee.org>
parents:
5067
diff
changeset
|
3219 If you want to have visible form elements in your tal/jinja |
|
c1f1465d5303
issue2550683 Allow indexargs_form filter variable exclusion.
John Rouillard <rouilj@ieee.org>
parents:
5067
diff
changeset
|
3220 generated templates use the exclude aray to list the names for |
|
c1f1465d5303
issue2550683 Allow indexargs_form filter variable exclusion.
John Rouillard <rouilj@ieee.org>
parents:
5067
diff
changeset
|
3221 these elements. This wll prevent the function from creating |
|
c1f1465d5303
issue2550683 Allow indexargs_form filter variable exclusion.
John Rouillard <rouilj@ieee.org>
parents:
5067
diff
changeset
|
3222 these elements in its output. |
|
c1f1465d5303
issue2550683 Allow indexargs_form filter variable exclusion.
John Rouillard <rouilj@ieee.org>
parents:
5067
diff
changeset
|
3223 """ |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3224 l = [] |
|
1421
90bb11eb40dc
oops, forgot the templating :)
Richard Jones <richard@users.sourceforge.net>
parents:
1417
diff
changeset
|
3225 sc = self.special_char |
|
7021
4e25815961a7
flake8: remove trailing whitespace; blank lines for definitions
John Rouillard <rouilj@ieee.org>
parents:
7020
diff
changeset
|
3226 |
|
3782
51c07c04d258
clean up input field generation and quoting of values [SF#1615616]
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
3227 def add(k, v): |
|
51c07c04d258
clean up input field generation and quoting of values [SF#1615616]
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
3228 l.append(self.input(type="hidden", name=k, value=v)) |
| 1002 | 3229 if columns and self.columns: |
|
3782
51c07c04d258
clean up input field generation and quoting of values [SF#1615616]
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
3230 add(sc+'columns', ','.join(self.columns)) |
|
3696
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3231 if sort: |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3232 val = [] |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3233 for dir, attr in self.sort: |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3234 if dir == '-': |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3235 val.append('-'+attr) |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3236 else: |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3237 val.append(attr) |
|
7020
86312ca47ad7
flake8 E211 remove space before ( in function calls
John Rouillard <rouilj@ieee.org>
parents:
7019
diff
changeset
|
3238 add(sc+'sort', ','.join(val)) |
|
3696
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3239 if group: |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3240 val = [] |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3241 for dir, attr in self.group: |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3242 if dir == '-': |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3243 val.append('-'+attr) |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3244 else: |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3245 val.append(attr) |
|
7020
86312ca47ad7
flake8 E211 remove space before ( in function calls
John Rouillard <rouilj@ieee.org>
parents:
7019
diff
changeset
|
3246 add(sc+'group', ','.join(val)) |
| 1002 | 3247 if filter and self.filter: |
|
3782
51c07c04d258
clean up input field generation and quoting of values [SF#1615616]
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
3248 add(sc+'filter', ','.join(self.filter)) |
|
3068
c4e76c84f43d
another fix to indexargs
Richard Jones <richard@users.sourceforge.net>
parents:
3060
diff
changeset
|
3249 if self.classname and filterspec: |
|
4051
047402c4ec9b
Handle transitive properties.
Stefan Seefeld <stefan@seefeld.name>
parents:
4043
diff
changeset
|
3250 cls = self.client.db.getclass(self.classname) |
| 1002 | 3251 for k,v in self.filterspec.items(): |
|
5082
c1f1465d5303
issue2550683 Allow indexargs_form filter variable exclusion.
John Rouillard <rouilj@ieee.org>
parents:
5067
diff
changeset
|
3252 if k in exclude: |
|
c1f1465d5303
issue2550683 Allow indexargs_form filter variable exclusion.
John Rouillard <rouilj@ieee.org>
parents:
5067
diff
changeset
|
3253 continue |
|
7024
bac315283a55
flake8: E721 do not compare types, use 'isinstance()'
John Rouillard <rouilj@ieee.org>
parents:
7023
diff
changeset
|
3254 if isinstance(v, list): |
|
5184
a40ea636a2ad
Issue2550934 - templating.py-indexargs_form() returns id's as space separated list not comma separated
John Rouillard <rouilj@ieee.org>
parents:
5183
diff
changeset
|
3255 # id's are stored as strings but should be treated |
|
a40ea636a2ad
Issue2550934 - templating.py-indexargs_form() returns id's as space separated list not comma separated
John Rouillard <rouilj@ieee.org>
parents:
5183
diff
changeset
|
3256 # as integers in lists. |
|
a40ea636a2ad
Issue2550934 - templating.py-indexargs_form() returns id's as space separated list not comma separated
John Rouillard <rouilj@ieee.org>
parents:
5183
diff
changeset
|
3257 if (isinstance(cls.get_transitive_prop(k), hyperdb.String) |
|
a40ea636a2ad
Issue2550934 - templating.py-indexargs_form() returns id's as space separated list not comma separated
John Rouillard <rouilj@ieee.org>
parents:
5183
diff
changeset
|
3258 and k != 'id'): |
|
3782
51c07c04d258
clean up input field generation and quoting of values [SF#1615616]
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
3259 add(k, ' '.join(v)) |
|
3049
393f6ab17c07
handle spaces in String index params in batching [SF#1054224]
Richard Jones <richard@users.sourceforge.net>
parents:
3040
diff
changeset
|
3260 else: |
|
3782
51c07c04d258
clean up input field generation and quoting of values [SF#1615616]
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
3261 add(k, ','.join(v)) |
|
1353
013ae8c6c8b1
display of saved queries is now performed correctly
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1342
diff
changeset
|
3262 else: |
|
3782
51c07c04d258
clean up input field generation and quoting of values [SF#1615616]
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
3263 add(k, v) |
|
3159
b2fc512f145d
allow suppression of search_text in indexargs_form [SF#1101548]
Richard Jones <richard@users.sourceforge.net>
parents:
3158
diff
changeset
|
3264 if search_text and self.search_text: |
|
3782
51c07c04d258
clean up input field generation and quoting of values [SF#1615616]
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
3265 add(sc+'search_text', self.search_text) |
|
51c07c04d258
clean up input field generation and quoting of values [SF#1615616]
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
3266 add(sc+'pagesize', self.pagesize) |
|
51c07c04d258
clean up input field generation and quoting of values [SF#1615616]
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
3267 add(sc+'startwith', self.startwith) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3268 return '\n'.join(l) |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3269 |
|
1124
1fc1f92c5f31
more doc, bugfix in Batch
Richard Jones <richard@users.sourceforge.net>
parents:
1123
diff
changeset
|
3270 def indexargs_url(self, url, args): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
3271 """ Embed the current index args in a URL |
| 5192 | 3272 |
| 3273 If the value of an arg (in args dict) is None, | |
| 3274 the argument is excluded from the url. If you want | |
| 3275 an empty value use an empty string '' as the value. | |
| 3276 Use this in templates to conditionally | |
| 3277 include an arg if it is set to a value. E.G. | |
| 3278 {..., '@queryname': request.dispname or None, ...} | |
| 3279 will include @queryname in the url if there is a | |
| 3280 dispname otherwise the parameter will be omitted | |
| 3281 from the url. | |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
3282 """ |
|
5402
88dbacd11cd1
Python 3 preparation: update urllib / urllib2 / urlparse imports.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5399
diff
changeset
|
3283 q = urllib_.quote |
|
1421
90bb11eb40dc
oops, forgot the templating :)
Richard Jones <richard@users.sourceforge.net>
parents:
1417
diff
changeset
|
3284 sc = self.special_char |
|
5438
e2382945d302
Python 3 preparation: avoid basestring.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5423
diff
changeset
|
3285 l = ['%s=%s'%(k,is_us(v) and q(v) or v) |
|
7023
ae6fa7b32e2d
flake8: E711 comparison to None should be 'if cond is not None:'
John Rouillard <rouilj@ieee.org>
parents:
7022
diff
changeset
|
3286 for k,v in args.items() if v is not None] |
|
1467
378081f066cc
registration is now a two-step process with confirmation from the
Richard Jones <richard@users.sourceforge.net>
parents:
1463
diff
changeset
|
3287 # pull out the special values (prefixed by @ or :) |
|
378081f066cc
registration is now a two-step process with confirmation from the
Richard Jones <richard@users.sourceforge.net>
parents:
1463
diff
changeset
|
3288 specials = {} |
|
378081f066cc
registration is now a two-step process with confirmation from the
Richard Jones <richard@users.sourceforge.net>
parents:
1463
diff
changeset
|
3289 for key in args.keys(): |
|
378081f066cc
registration is now a two-step process with confirmation from the
Richard Jones <richard@users.sourceforge.net>
parents:
1463
diff
changeset
|
3290 if key[0] in '@:': |
|
378081f066cc
registration is now a two-step process with confirmation from the
Richard Jones <richard@users.sourceforge.net>
parents:
1463
diff
changeset
|
3291 specials[key[1:]] = args[key] |
|
378081f066cc
registration is now a two-step process with confirmation from the
Richard Jones <richard@users.sourceforge.net>
parents:
1463
diff
changeset
|
3292 |
|
378081f066cc
registration is now a two-step process with confirmation from the
Richard Jones <richard@users.sourceforge.net>
parents:
1463
diff
changeset
|
3293 # ok, now handle the specials we received in the request |
|
5381
0942fe89e82e
Python 3 preparation: change "x.has_key(y)" to "y in x".
Joseph Myers <jsm@polyomino.org.uk>
parents:
5378
diff
changeset
|
3294 if self.columns and 'columns' not in specials: |
|
1421
90bb11eb40dc
oops, forgot the templating :)
Richard Jones <richard@users.sourceforge.net>
parents:
1417
diff
changeset
|
3295 l.append(sc+'columns=%s'%(','.join(self.columns))) |
|
5381
0942fe89e82e
Python 3 preparation: change "x.has_key(y)" to "y in x".
Joseph Myers <jsm@polyomino.org.uk>
parents:
5378
diff
changeset
|
3296 if self.sort and 'sort' not in specials: |
|
3696
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3297 val = [] |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3298 for dir, attr in self.sort: |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3299 if dir == '-': |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3300 val.append('-'+attr) |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3301 else: |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3302 val.append(attr) |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3303 l.append(sc+'sort=%s'%(','.join(val))) |
|
5381
0942fe89e82e
Python 3 preparation: change "x.has_key(y)" to "y in x".
Joseph Myers <jsm@polyomino.org.uk>
parents:
5378
diff
changeset
|
3304 if self.group and 'group' not in specials: |
|
3696
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3305 val = [] |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3306 for dir, attr in self.group: |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3307 if dir == '-': |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3308 val.append('-'+attr) |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3309 else: |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3310 val.append(attr) |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3311 l.append(sc+'group=%s'%(','.join(val))) |
|
5381
0942fe89e82e
Python 3 preparation: change "x.has_key(y)" to "y in x".
Joseph Myers <jsm@polyomino.org.uk>
parents:
5378
diff
changeset
|
3312 if self.filter and 'filter' not in specials: |
|
1421
90bb11eb40dc
oops, forgot the templating :)
Richard Jones <richard@users.sourceforge.net>
parents:
1417
diff
changeset
|
3313 l.append(sc+'filter=%s'%(','.join(self.filter))) |
|
5381
0942fe89e82e
Python 3 preparation: change "x.has_key(y)" to "y in x".
Joseph Myers <jsm@polyomino.org.uk>
parents:
5378
diff
changeset
|
3314 if self.search_text and 'search_text' not in specials: |
|
3104
97aec6907e69
merge from 0.7
Richard Jones <richard@users.sourceforge.net>
parents:
3068
diff
changeset
|
3315 l.append(sc+'search_text=%s'%q(self.search_text)) |
|
5381
0942fe89e82e
Python 3 preparation: change "x.has_key(y)" to "y in x".
Joseph Myers <jsm@polyomino.org.uk>
parents:
5378
diff
changeset
|
3316 if 'pagesize' not in specials: |
|
1467
378081f066cc
registration is now a two-step process with confirmation from the
Richard Jones <richard@users.sourceforge.net>
parents:
1463
diff
changeset
|
3317 l.append(sc+'pagesize=%s'%self.pagesize) |
|
5381
0942fe89e82e
Python 3 preparation: change "x.has_key(y)" to "y in x".
Joseph Myers <jsm@polyomino.org.uk>
parents:
5378
diff
changeset
|
3318 if 'startwith' not in specials: |
|
1467
378081f066cc
registration is now a two-step process with confirmation from the
Richard Jones <richard@users.sourceforge.net>
parents:
1463
diff
changeset
|
3319 l.append(sc+'startwith=%s'%self.startwith) |
|
378081f066cc
registration is now a two-step process with confirmation from the
Richard Jones <richard@users.sourceforge.net>
parents:
1463
diff
changeset
|
3320 |
|
378081f066cc
registration is now a two-step process with confirmation from the
Richard Jones <richard@users.sourceforge.net>
parents:
1463
diff
changeset
|
3321 # finally, the remainder of the filter args in the request |
|
3068
c4e76c84f43d
another fix to indexargs
Richard Jones <richard@users.sourceforge.net>
parents:
3060
diff
changeset
|
3322 if self.classname and self.filterspec: |
|
3635
53987aa153d2
Transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3610
diff
changeset
|
3323 cls = self.client.db.getclass(self.classname) |
|
3068
c4e76c84f43d
another fix to indexargs
Richard Jones <richard@users.sourceforge.net>
parents:
3060
diff
changeset
|
3324 for k,v in self.filterspec.items(): |
|
5381
0942fe89e82e
Python 3 preparation: change "x.has_key(y)" to "y in x".
Joseph Myers <jsm@polyomino.org.uk>
parents:
5378
diff
changeset
|
3325 if k not in args: |
|
7024
bac315283a55
flake8: E721 do not compare types, use 'isinstance()'
John Rouillard <rouilj@ieee.org>
parents:
7023
diff
changeset
|
3326 if isinstance(v, list): |
|
3635
53987aa153d2
Transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3610
diff
changeset
|
3327 prop = cls.get_transitive_prop(k) |
|
3909
e89bcb28f683
indexargs_url force ids to int
Justus Pendleton <jpend@users.sourceforge.net>
parents:
3905
diff
changeset
|
3328 if k != 'id' and isinstance(prop, hyperdb.String): |
|
3068
c4e76c84f43d
another fix to indexargs
Richard Jones <richard@users.sourceforge.net>
parents:
3060
diff
changeset
|
3329 l.append('%s=%s'%(k, '%20'.join([q(i) for i in v]))) |
|
c4e76c84f43d
another fix to indexargs
Richard Jones <richard@users.sourceforge.net>
parents:
3060
diff
changeset
|
3330 else: |
|
c4e76c84f43d
another fix to indexargs
Richard Jones <richard@users.sourceforge.net>
parents:
3060
diff
changeset
|
3331 l.append('%s=%s'%(k, ','.join([q(i) for i in v]))) |
|
3049
393f6ab17c07
handle spaces in String index params in batching [SF#1054224]
Richard Jones <richard@users.sourceforge.net>
parents:
3040
diff
changeset
|
3332 else: |
|
3068
c4e76c84f43d
another fix to indexargs
Richard Jones <richard@users.sourceforge.net>
parents:
3060
diff
changeset
|
3333 l.append('%s=%s'%(k, q(v))) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3334 return '%s?%s'%(url, '&'.join(l)) |
|
1124
1fc1f92c5f31
more doc, bugfix in Batch
Richard Jones <richard@users.sourceforge.net>
parents:
1123
diff
changeset
|
3335 indexargs_href = indexargs_url |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3336 |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3337 def base_javascript(self): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
3338 return """ |
|
5217
17b213eab274
Add nonce to embedded script references.
John Rouillard <rouilj@ieee.org>
parents:
5211
diff
changeset
|
3339 <script nonce="%s" type="text/javascript"> |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3340 submitted = false; |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3341 function submit_once() { |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3342 if (submitted) { |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3343 alert("Your request is being processed.\\nPlease be patient."); |
|
5172
fac171f0f27b
Fix submit_once Javascript function
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5166
diff
changeset
|
3344 return false; |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3345 } |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3346 submitted = true; |
|
5172
fac171f0f27b
Fix submit_once Javascript function
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5166
diff
changeset
|
3347 return true; |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3348 } |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3349 |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3350 function help_window(helpurl, width, height) { |
|
1204
b862bbf2067a
Replaced the content() callback ickiness with Page Template macro usage
Richard Jones <richard@users.sourceforge.net>
parents:
1202
diff
changeset
|
3351 HelpWin = window.open('%s' + helpurl, 'RoundupHelpWindow', 'scrollbars=yes,resizable=yes,toolbar=no,height='+height+',width='+width); |
|
5006
bb97f61e1b73
Help-Window now gets focus
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4959
diff
changeset
|
3352 HelpWin.focus () |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3353 } |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3354 </script> |
|
5217
17b213eab274
Add nonce to embedded script references.
John Rouillard <rouilj@ieee.org>
parents:
5211
diff
changeset
|
3355 """%(self._client.client_nonce,self.base) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3356 |
|
4524
68bbefb72825
Allow HTMLRequest.batch to filter on other permissions than "View"...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4483
diff
changeset
|
3357 def batch(self, permission='View'): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
3358 """ Return a batch object for results from the "current search" |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
3359 """ |
|
4328
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
3360 check = self._client.db.security.hasPermission |
|
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
3361 userid = self._client.userid |
|
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
3362 if not check('Web Access', userid): |
|
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
3363 return Batch(self.client, [], self.pagesize, self.startwith, |
|
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
3364 classname=self.classname) |
|
3d224f7fb364
add web access check all over templating
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
3365 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3366 filterspec = self.filterspec |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3367 sort = self.sort |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3368 group = self.group |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3369 |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3370 # get the list of ids we're batching over |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3371 klass = self.client.db.getclass(self.classname) |
| 1002 | 3372 if self.search_text: |
|
6593
e70e2789bc2c
issue2551189 - increase text search maxlength
John Rouillard <rouilj@ieee.org>
parents:
6588
diff
changeset
|
3373 indexer = self.client.db.indexer |
|
e70e2789bc2c
issue2551189 - increase text search maxlength
John Rouillard <rouilj@ieee.org>
parents:
6588
diff
changeset
|
3374 if indexer.query_language: |
|
6588
91ab3e0ffcd0
Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents:
6564
diff
changeset
|
3375 try: |
|
6593
e70e2789bc2c
issue2551189 - increase text search maxlength
John Rouillard <rouilj@ieee.org>
parents:
6588
diff
changeset
|
3376 matches = indexer.search( |
|
6588
91ab3e0ffcd0
Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents:
6564
diff
changeset
|
3377 [self.search_text], klass) |
|
91ab3e0ffcd0
Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents:
6564
diff
changeset
|
3378 except Exception as e: |
|
91ab3e0ffcd0
Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents:
6564
diff
changeset
|
3379 self.client.add_error_message(" ".join(e.args)) |
|
91ab3e0ffcd0
Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents:
6564
diff
changeset
|
3380 raise |
|
91ab3e0ffcd0
Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents:
6564
diff
changeset
|
3381 else: |
|
6593
e70e2789bc2c
issue2551189 - increase text search maxlength
John Rouillard <rouilj@ieee.org>
parents:
6588
diff
changeset
|
3382 matches = indexer.search( |
|
6588
91ab3e0ffcd0
Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents:
6564
diff
changeset
|
3383 [u2s(w.upper()) for w in re.findall( |
|
6593
e70e2789bc2c
issue2551189 - increase text search maxlength
John Rouillard <rouilj@ieee.org>
parents:
6588
diff
changeset
|
3384 r'(?u)\b\w{%s,%s}\b' % (indexer.minlength, |
|
e70e2789bc2c
issue2551189 - increase text search maxlength
John Rouillard <rouilj@ieee.org>
parents:
6588
diff
changeset
|
3385 indexer.maxlength), |
|
6588
91ab3e0ffcd0
Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents:
6564
diff
changeset
|
3386 s2u(self.search_text, "replace") |
|
91ab3e0ffcd0
Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents:
6564
diff
changeset
|
3387 )], klass) |
| 1002 | 3388 else: |
| 3389 matches = None | |
|
3126
a2889d22db4a
the cgi templating code now checks item-level
Richard Jones <richard@users.sourceforge.net>
parents:
3117
diff
changeset
|
3390 |
|
a2889d22db4a
the cgi templating code now checks item-level
Richard Jones <richard@users.sourceforge.net>
parents:
3117
diff
changeset
|
3391 # filter for visibility |
|
a2889d22db4a
the cgi templating code now checks item-level
Richard Jones <richard@users.sourceforge.net>
parents:
3117
diff
changeset
|
3392 l = [id for id in klass.filter(matches, filterspec, sort, group) |
|
4524
68bbefb72825
Allow HTMLRequest.batch to filter on other permissions than "View"...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4483
diff
changeset
|
3393 if check(permission, userid, self.classname, itemid=id)] |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3394 |
|
1182
cb35cf3db0e0
don't create instances that aren't used
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
3395 # return the batch object, using IDs only |
|
cb35cf3db0e0
don't create instances that aren't used
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
3396 return Batch(self.client, l, self.pagesize, self.startwith, |
|
cb35cf3db0e0
don't create instances that aren't used
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
3397 classname=self.classname) |
|
1004
5f12d3259f31
logout works better now
Richard Jones <richard@users.sourceforge.net>
parents:
1003
diff
changeset
|
3398 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
3399 |
|
1004
5f12d3259f31
logout works better now
Richard Jones <richard@users.sourceforge.net>
parents:
1003
diff
changeset
|
3400 # extend the standard ZTUtils Batch object to remove dependency on |
|
5f12d3259f31
logout works better now
Richard Jones <richard@users.sourceforge.net>
parents:
1003
diff
changeset
|
3401 # Acquisition and add a couple of useful methods |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3402 class Batch(ZTUtils.Batch): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
3403 """ Use me to turn a list of items, or item ids of a given class, into a |
|
1122
ddbc5d1ad94f
more batching cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1120
diff
changeset
|
3404 series of batches. |
|
ddbc5d1ad94f
more batching cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1120
diff
changeset
|
3405 |
|
ddbc5d1ad94f
more batching cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1120
diff
changeset
|
3406 ========= ======================================================== |
|
ddbc5d1ad94f
more batching cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1120
diff
changeset
|
3407 Parameter Usage |
|
ddbc5d1ad94f
more batching cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1120
diff
changeset
|
3408 ========= ======================================================== |
|
1182
cb35cf3db0e0
don't create instances that aren't used
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
3409 sequence a list of HTMLItems or item ids |
|
cb35cf3db0e0
don't create instances that aren't used
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
3410 classname if sequence is a list of ids, this is the class of item |
|
1122
ddbc5d1ad94f
more batching cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1120
diff
changeset
|
3411 size how big to make the sequence. |
|
ddbc5d1ad94f
more batching cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1120
diff
changeset
|
3412 start where to start (0-indexed) in the sequence. |
|
ddbc5d1ad94f
more batching cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1120
diff
changeset
|
3413 end where to end (0-indexed) in the sequence. |
|
ddbc5d1ad94f
more batching cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1120
diff
changeset
|
3414 orphan if the next batch would contain less items than this |
|
ddbc5d1ad94f
more batching cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1120
diff
changeset
|
3415 value, then it is combined with this batch |
|
ddbc5d1ad94f
more batching cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1120
diff
changeset
|
3416 overlap the number of items shared between adjacent batches |
|
ddbc5d1ad94f
more batching cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1120
diff
changeset
|
3417 ========= ======================================================== |
|
ddbc5d1ad94f
more batching cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1120
diff
changeset
|
3418 |
|
ddbc5d1ad94f
more batching cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1120
diff
changeset
|
3419 Attributes: Note that the "start" attribute, unlike the |
|
ddbc5d1ad94f
more batching cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1120
diff
changeset
|
3420 argument, is a 1-based index (I know, lame). "first" is the |
|
ddbc5d1ad94f
more batching cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1120
diff
changeset
|
3421 0-based index. "length" is the actual number of elements in |
|
ddbc5d1ad94f
more batching cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1120
diff
changeset
|
3422 the batch. |
|
ddbc5d1ad94f
more batching cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1120
diff
changeset
|
3423 |
|
ddbc5d1ad94f
more batching cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1120
diff
changeset
|
3424 "sequence_length" is the length of the original, unbatched, sequence. |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
3425 """ |
|
1122
ddbc5d1ad94f
more batching cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1120
diff
changeset
|
3426 def __init__(self, client, sequence, size, start, end=0, orphan=0, |
|
1182
cb35cf3db0e0
don't create instances that aren't used
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
3427 overlap=0, classname=None): |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3428 self.client = client |
| 1002 | 3429 self.last_index = self.last_item = None |
| 3430 self.current_item = None | |
|
1182
cb35cf3db0e0
don't create instances that aren't used
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
3431 self.classname = classname |
|
1124
1fc1f92c5f31
more doc, bugfix in Batch
Richard Jones <richard@users.sourceforge.net>
parents:
1123
diff
changeset
|
3432 self.sequence_length = len(sequence) |
|
1122
ddbc5d1ad94f
more batching cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1120
diff
changeset
|
3433 ZTUtils.Batch.__init__(self, sequence, size, start, end, orphan, |
|
ddbc5d1ad94f
more batching cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1120
diff
changeset
|
3434 overlap) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3435 |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3436 # overwrite so we can late-instantiate the HTMLItem instance |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3437 def __getitem__(self, index): |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3438 if index < 0: |
|
5378
35ea9b1efc14
Python 3 preparation: "raise" syntax.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5356
diff
changeset
|
3439 if index + self.end < self.first: raise IndexError(index) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3440 return self._sequence[index + self.end] |
|
2327
36ae1b14aaab
remove excessive spaces in the translatable strings;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2324
diff
changeset
|
3441 |
|
1120
c26471971d18
Exposed the Batch mechanism through the top-level "utils" variable.
Richard Jones <richard@users.sourceforge.net>
parents:
1113
diff
changeset
|
3442 if index >= self.length: |
|
5378
35ea9b1efc14
Python 3 preparation: "raise" syntax.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5356
diff
changeset
|
3443 raise IndexError(index) |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3444 |
| 1002 | 3445 # move the last_item along - but only if the fetched index changes |
| 3446 # (for some reason, index 0 is fetched twice) | |
| 3447 if index != self.last_index: | |
| 3448 self.last_item = self.current_item | |
| 3449 self.last_index = index | |
| 3450 | |
|
1182
cb35cf3db0e0
don't create instances that aren't used
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
3451 item = self._sequence[index + self.first] |
|
cb35cf3db0e0
don't create instances that aren't used
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
3452 if self.classname: |
|
cb35cf3db0e0
don't create instances that aren't used
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
3453 # map the item ids to instances |
|
2649
1df7d4a41da4
Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents:
2640
diff
changeset
|
3454 item = HTMLItem(self.client, self.classname, item) |
|
1182
cb35cf3db0e0
don't create instances that aren't used
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
3455 self.current_item = item |
|
cb35cf3db0e0
don't create instances that aren't used
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
3456 return item |
| 1002 | 3457 |
|
3696
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3458 def propchanged(self, *properties): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
3459 """ Detect if one of the properties marked as being a group |
|
3696
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3460 property changed in the last iteration fetch |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
3461 """ |
|
3369
18f1631c9b85
sort/group by missing values correctly [SF#1198623]
Richard Jones <richard@users.sourceforge.net>
parents:
3363
diff
changeset
|
3462 # we poke directly at the _value here since MissingValue can screw |
|
18f1631c9b85
sort/group by missing values correctly [SF#1198623]
Richard Jones <richard@users.sourceforge.net>
parents:
3363
diff
changeset
|
3463 # us up and cause Nones to compare strangely |
|
3696
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3464 if self.last_item is None: |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3465 return 1 |
|
790363e96852
Sorting/grouping by multiple properties.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3689
diff
changeset
|
3466 for property in properties: |
|
7020
86312ca47ad7
flake8 E211 remove space before ( in function calls
John Rouillard <rouilj@ieee.org>
parents:
7019
diff
changeset
|
3467 if property == 'id' or property.endswith('.id')\ |
|
86312ca47ad7
flake8 E211 remove space before ( in function calls
John Rouillard <rouilj@ieee.org>
parents:
7019
diff
changeset
|
3468 or isinstance(self.last_item[property], list): |
|
3700
9cc2566cc7d9
This isn't really nice, but now grouping by transitive multilinks works.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3699
diff
changeset
|
3469 if (str(self.last_item[property]) != |
|
9cc2566cc7d9
This isn't really nice, but now grouping by transitive multilinks works.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3699
diff
changeset
|
3470 str(self.current_item[property])): |
|
3699
976191d749fb
grouping by ID and grouping by transitive multilinks didn't work correctly.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3698
diff
changeset
|
3471 return 1 |
|
976191d749fb
grouping by ID and grouping by transitive multilinks didn't work correctly.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3698
diff
changeset
|
3472 else: |
|
976191d749fb
grouping by ID and grouping by transitive multilinks didn't work correctly.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3698
diff
changeset
|
3473 if (self.last_item[property]._value != |
|
976191d749fb
grouping by ID and grouping by transitive multilinks didn't work correctly.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3698
diff
changeset
|
3474 self.current_item[property]._value): |
|
976191d749fb
grouping by ID and grouping by transitive multilinks didn't work correctly.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3698
diff
changeset
|
3475 return 1 |
| 1002 | 3476 return 0 |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3477 |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3478 # override these 'cos we don't have access to acquisition |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3479 def previous(self): |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3480 if self.start == 1: |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3481 return None |
|
5087
39af8a0f3446
Applied patch attached to issue2550723. Problem in index page
John Rouillard <rouilj@ieee.org>
parents:
5082
diff
changeset
|
3482 return Batch(self.client, self._sequence, self.size, |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3483 self.first - self._size + self.overlap, 0, self.orphan, |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3484 self.overlap) |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3485 |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3486 def next(self): |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3487 try: |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3488 self._sequence[self.end] |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3489 except IndexError: |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3490 return None |
|
5087
39af8a0f3446
Applied patch attached to issue2550723. Problem in index page
John Rouillard <rouilj@ieee.org>
parents:
5082
diff
changeset
|
3491 return Batch(self.client, self._sequence, self.size, |
|
985
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3492 self.end - self.overlap, 0, self.orphan, self.overlap) |
|
55ab0c5b49f9
New CGI interface support
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3493 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
3494 |
|
1120
c26471971d18
Exposed the Batch mechanism through the top-level "utils" variable.
Richard Jones <richard@users.sourceforge.net>
parents:
1113
diff
changeset
|
3495 class TemplatingUtils: |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
3496 """ Utilities for templating |
|
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
3497 """ |
|
1120
c26471971d18
Exposed the Batch mechanism through the top-level "utils" variable.
Richard Jones <richard@users.sourceforge.net>
parents:
1113
diff
changeset
|
3498 def __init__(self, client): |
|
c26471971d18
Exposed the Batch mechanism through the top-level "utils" variable.
Richard Jones <richard@users.sourceforge.net>
parents:
1113
diff
changeset
|
3499 self.client = client |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
3500 |
|
1122
ddbc5d1ad94f
more batching cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1120
diff
changeset
|
3501 def Batch(self, sequence, size, start, end=0, orphan=0, overlap=0): |
|
ddbc5d1ad94f
more batching cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1120
diff
changeset
|
3502 return Batch(self.client, sequence, size, start, end, orphan, |
|
1120
c26471971d18
Exposed the Batch mechanism through the top-level "utils" variable.
Richard Jones <richard@users.sourceforge.net>
parents:
1113
diff
changeset
|
3503 overlap) |
|
c26471971d18
Exposed the Batch mechanism through the top-level "utils" variable.
Richard Jones <richard@users.sourceforge.net>
parents:
1113
diff
changeset
|
3504 |
|
5201
a9ace22e0a2f
issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents:
5193
diff
changeset
|
3505 def anti_csrf_nonce(self, lifetime=None): |
|
5488
52cb53eedf77
reworked random number use
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5485
diff
changeset
|
3506 return anti_csrf_nonce(self.client, lifetime=lifetime) |
|
5201
a9ace22e0a2f
issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents:
5193
diff
changeset
|
3507 |
|
5973
fe334430ca07
issue2550919 - Anti-bot signup using 4 second delay
John Rouillard <rouilj@ieee.org>
parents:
5947
diff
changeset
|
3508 def timestamp(self): |
|
fe334430ca07
issue2550919 - Anti-bot signup using 4 second delay
John Rouillard <rouilj@ieee.org>
parents:
5947
diff
changeset
|
3509 return pack_timestamp() |
|
7019
e1528860e591
flake8 remove space from blank lines W293
John Rouillard <rouilj@ieee.org>
parents:
7018
diff
changeset
|
3510 |
|
2180
58b6d1747973
Web interface tweaks.
Richard Jones <richard@users.sourceforge.net>
parents:
2170
diff
changeset
|
3511 def url_quote(self, url): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
3512 """URL-quote the supplied text.""" |
|
5402
88dbacd11cd1
Python 3 preparation: update urllib / urllib2 / urlparse imports.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5399
diff
changeset
|
3513 return urllib_.quote(url) |
|
2180
58b6d1747973
Web interface tweaks.
Richard Jones <richard@users.sourceforge.net>
parents:
2170
diff
changeset
|
3514 |
|
58b6d1747973
Web interface tweaks.
Richard Jones <richard@users.sourceforge.net>
parents:
2170
diff
changeset
|
3515 def html_quote(self, html): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
3516 """HTML-quote the supplied text.""" |
|
5800
1a835db41674
Call cgi.escape only on python 2. Replace with html.escapeif it can be
John Rouillard <rouilj@ieee.org>
parents:
5684
diff
changeset
|
3517 return html_escape(html) |
|
2180
58b6d1747973
Web interface tweaks.
Richard Jones <richard@users.sourceforge.net>
parents:
2170
diff
changeset
|
3518 |
|
2640
b01eca163779
The "type" parameter is supposed to be optional
Richard Jones <richard@users.sourceforge.net>
parents:
2637
diff
changeset
|
3519 def __getattr__(self, name): |
|
3842
310e315624b1
Change ''' into """ to work around bug in Emacs' syntax highlighting code.
Erik Forsberg <forsberg@users.sourceforge.net>
parents:
3832
diff
changeset
|
3520 """Try the tracker's templating_utils.""" |
|
2640
b01eca163779
The "type" parameter is supposed to be optional
Richard Jones <richard@users.sourceforge.net>
parents:
2637
diff
changeset
|
3521 if not hasattr(self.client.instance, 'templating_utils'): |
|
b01eca163779
The "type" parameter is supposed to be optional
Richard Jones <richard@users.sourceforge.net>
parents:
2637
diff
changeset
|
3522 # backwards-compatibility |
|
5378
35ea9b1efc14
Python 3 preparation: "raise" syntax.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5356
diff
changeset
|
3523 raise AttributeError(name) |
|
5381
0942fe89e82e
Python 3 preparation: change "x.has_key(y)" to "y in x".
Joseph Myers <jsm@polyomino.org.uk>
parents:
5378
diff
changeset
|
3524 if name not in self.client.instance.templating_utils: |
|
5378
35ea9b1efc14
Python 3 preparation: "raise" syntax.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5356
diff
changeset
|
3525 raise AttributeError(name) |
|
3006
50b0f8e98247
fix API for templating utils extensions - remove "utils" arg
Richard Jones <richard@users.sourceforge.net>
parents:
2994
diff
changeset
|
3526 return self.client.instance.templating_utils[name] |
|
2640
b01eca163779
The "type" parameter is supposed to be optional
Richard Jones <richard@users.sourceforge.net>
parents:
2637
diff
changeset
|
3527 |
|
4466
f1fe6fd0aa61
Multilinks can be filtered by combining elements with AND, OR and NOT now.
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4463
diff
changeset
|
3528 def keywords_expressions(self, request): |
|
f1fe6fd0aa61
Multilinks can be filtered by combining elements with AND, OR and NOT now.
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4463
diff
changeset
|
3529 return render_keywords_expression_editor(request) |
|
f1fe6fd0aa61
Multilinks can be filtered by combining elements with AND, OR and NOT now.
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4463
diff
changeset
|
3530 |
|
3292
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3531 def html_calendar(self, request): |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3532 """Generate a HTML calendar. |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3533 |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3534 `request` the roundup.request object |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3535 - @template : name of the template |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3536 - form : name of the form to store back the date |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3537 - property : name of the property of the form to store |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3538 back the date |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3539 - date : current date |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3540 - display : when browsing, specifies year and month |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3541 |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3542 html will simply be a table. |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3543 """ |
| 4333 | 3544 tz = request.client.db.getUserTimezone() |
|
4331
7327b102920f
Display 'today' in the account user's timezone, thanks David Wolever
Richard Jones <richard@users.sourceforge.net>
parents:
4329
diff
changeset
|
3545 current_date = date.Date(".").local(tz) |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
3546 date_str = request.form.getfirst("date", current_date) |
|
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
3547 display = request.form.getfirst("display", date_str) |
|
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
3548 template = request.form.getfirst("@template", "calendar") |
|
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
3549 form = request.form.getfirst("form") |
|
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
3550 property = request.form.getfirst("property") |
|
5191
fe52cab8f5b5
issue2550932 - html_calendar produces templating errors for bad date strings
John Rouillard <rouilj@ieee.org>
parents:
5190
diff
changeset
|
3551 curr_date = "" |
|
fe52cab8f5b5
issue2550932 - html_calendar produces templating errors for bad date strings
John Rouillard <rouilj@ieee.org>
parents:
5190
diff
changeset
|
3552 try: |
|
fe52cab8f5b5
issue2550932 - html_calendar produces templating errors for bad date strings
John Rouillard <rouilj@ieee.org>
parents:
5190
diff
changeset
|
3553 # date_str and display can be set to an invalid value |
|
fe52cab8f5b5
issue2550932 - html_calendar produces templating errors for bad date strings
John Rouillard <rouilj@ieee.org>
parents:
5190
diff
changeset
|
3554 # if user submits a value like "d4" and gets an edit error. |
|
fe52cab8f5b5
issue2550932 - html_calendar produces templating errors for bad date strings
John Rouillard <rouilj@ieee.org>
parents:
5190
diff
changeset
|
3555 # If either or both invalid just ignore that we can't parse it |
|
fe52cab8f5b5
issue2550932 - html_calendar produces templating errors for bad date strings
John Rouillard <rouilj@ieee.org>
parents:
5190
diff
changeset
|
3556 # and assign them to today. |
|
7022
f4bfc1af5d95
flake8 inline comment spacing; too many leading #
John Rouillard <rouilj@ieee.org>
parents:
7021
diff
changeset
|
3557 curr_date = date.Date(date_str) # to highlight |
|
f4bfc1af5d95
flake8 inline comment spacing; too many leading #
John Rouillard <rouilj@ieee.org>
parents:
7021
diff
changeset
|
3558 display = date.Date(display) # to show |
|
5191
fe52cab8f5b5
issue2550932 - html_calendar produces templating errors for bad date strings
John Rouillard <rouilj@ieee.org>
parents:
5190
diff
changeset
|
3559 except ValueError: |
|
fe52cab8f5b5
issue2550932 - html_calendar produces templating errors for bad date strings
John Rouillard <rouilj@ieee.org>
parents:
5190
diff
changeset
|
3560 # we couldn't parse the date |
|
fe52cab8f5b5
issue2550932 - html_calendar produces templating errors for bad date strings
John Rouillard <rouilj@ieee.org>
parents:
5190
diff
changeset
|
3561 # just let the calendar display |
|
fe52cab8f5b5
issue2550932 - html_calendar produces templating errors for bad date strings
John Rouillard <rouilj@ieee.org>
parents:
5190
diff
changeset
|
3562 curr_date = current_date |
|
fe52cab8f5b5
issue2550932 - html_calendar produces templating errors for bad date strings
John Rouillard <rouilj@ieee.org>
parents:
5190
diff
changeset
|
3563 display = current_date |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
3564 day = display.day |
|
3292
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3565 |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3566 # for navigation |
|
4651
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3567 try: |
|
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3568 date_prev_month = display + date.Interval("-1m") |
|
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3569 except ValueError: |
|
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3570 date_prev_month = None |
|
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3571 try: |
|
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3572 date_next_month = display + date.Interval("+1m") |
|
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3573 except ValueError: |
|
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3574 date_next_month = None |
|
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3575 try: |
|
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3576 date_prev_year = display + date.Interval("-1y") |
|
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3577 except ValueError: |
|
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3578 date_prev_year = None |
|
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3579 try: |
|
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3580 date_next_year = display + date.Interval("+1y") |
|
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3581 except ValueError: |
|
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3582 date_next_year = None |
|
3292
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3583 |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3584 res = [] |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3585 |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3586 base_link = "%s?@template=%s&property=%s&form=%s&date=%s" % \ |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3587 (request.classname, template, property, form, curr_date) |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3588 |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3589 # navigation |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3590 # month |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3591 res.append('<table class="calendar"><tr><td>') |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3592 res.append(' <table width="100%" class="calendar_nav"><tr>') |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3593 link = "&display=%s"%date_prev_month |
|
4651
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3594 if date_prev_month: |
|
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3595 res.append(' <td><a href="%s&display=%s"><</a></td>' |
|
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3596 % (base_link, date_prev_month)) |
|
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3597 else: |
|
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3598 res.append(' <td></td>') |
|
3292
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3599 res.append(' <td>%s</td>'%calendar.month_name[display.month]) |
|
4651
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3600 if date_next_month: |
|
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3601 res.append(' <td><a href="%s&display=%s">></a></td>' |
|
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3602 % (base_link, date_next_month)) |
|
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3603 else: |
|
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3604 res.append(' <td></td>') |
|
3292
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3605 # spacer |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3606 res.append(' <td width="100%"></td>') |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3607 # year |
|
4651
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3608 if date_prev_year: |
|
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3609 res.append(' <td><a href="%s&display=%s"><</a></td>' |
|
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3610 % (base_link, date_prev_year)) |
|
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3611 else: |
|
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3612 res.append(' <td></td>') |
|
3292
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3613 res.append(' <td>%s</td>'%display.year) |
|
4651
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3614 if date_next_year: |
|
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3615 res.append(' <td><a href="%s&display=%s">></a></td>' |
|
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3616 % (base_link, date_next_year)) |
|
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3617 else: |
|
beb8d43f4d9d
issue2550765: Don't show links in calendar that will fail. Found and fixed by Cédric Krier.
Bernhard Reiter <bernhard@intevation.de>
parents:
4647
diff
changeset
|
3618 res.append(' <td></td>') |
|
3292
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3619 res.append(' </tr></table>') |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3620 res.append(' </td></tr>') |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3621 |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3622 # the calendar |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3623 res.append(' <tr><td><table class="calendar_display">') |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3624 res.append(' <tr class="weekdays">') |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3625 for day in calendar.weekheader(3).split(): |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3626 res.append(' <td>%s</td>'%day) |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3627 res.append(' </tr>') |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3628 for week in calendar.monthcalendar(display.year, display.month): |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3629 res.append(' <tr>') |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3630 for day in week: |
|
5180
f95650727b1c
got the indent wrong in the last change for templating.py
John Rouillard <rouilj@ieee.org>
parents:
5179
diff
changeset
|
3631 link = "javascript:form[field].value = '%d-%02d-%02d'; " \ |
|
f95650727b1c
got the indent wrong in the last change for templating.py
John Rouillard <rouilj@ieee.org>
parents:
5179
diff
changeset
|
3632 "if ('createEvent' in document) { var evt = document.createEvent('HTMLEvents'); evt.initEvent('change', true, true); form[field].dispatchEvent(evt); } else { form[field].fireEvent('onchange'); }" \ |
|
f95650727b1c
got the indent wrong in the last change for templating.py
John Rouillard <rouilj@ieee.org>
parents:
5179
diff
changeset
|
3633 "window.close ();"%(display.year, display.month, day) |
|
3292
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3634 if (day == curr_date.day and display.month == curr_date.month |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3635 and display.year == curr_date.year): |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3636 # highlight |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3637 style = "today" |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
3638 else: |
|
3292
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3639 style = "" |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3640 if day: |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3641 res.append(' <td class="%s"><a href="%s">%s</a></td>'%( |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3642 style, link, day)) |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
3643 else: |
|
3292
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3644 res.append(' <td></td>') |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3645 res.append(' </tr>') |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3646 res.append('</table></td></tr></table>') |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3647 return "\n".join(res) |
|
8c7b522dc934
added date selection popup windows (thanks Marcus Priesch)
Richard Jones <richard@users.sourceforge.net>
parents:
3280
diff
changeset
|
3648 |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
3649 |
|
4878
f6e76a03b502
HTML* classes for cgi are now all new-style
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4875
diff
changeset
|
3650 class MissingValue(object): |
|
3164
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
3651 def __init__(self, description, **kwargs): |
|
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
3652 self.__description = description |
|
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
3653 for key, value in kwargs.items(): |
|
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
3654 self.__dict__[key] = value |
|
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
3655 |
|
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
3656 def __call__(self, *args, **kwargs): return MissingValue(self.__description) |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
3657 |
|
3164
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
3658 def __getattr__(self, name): |
|
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
3659 # This allows assignments which assume all intermediate steps are Null |
|
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
3660 # objects if they don't exist yet. |
|
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
3661 # |
|
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
3662 # For example (with just 'client' defined): |
|
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
3663 # |
|
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
3664 # client.db.config.TRACKER_WEB = 'BASE/' |
|
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
3665 self.__dict__[name] = MissingValue(self.__description) |
|
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
3666 return getattr(self, name) |
|
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
3667 |
|
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
3668 def __getitem__(self, key): return self |
|
5457
a35d4cc8cd1a
fix MissingValue / MockNull to return False on __bool__ and add a
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5448
diff
changeset
|
3669 def __bool__(self): return False |
|
5404
3757449e00c4
Python 3 preparation: use __bool__ instead of __nonzero__.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5402
diff
changeset
|
3670 # Python 2 compatibility: |
|
3757449e00c4
Python 3 preparation: use __bool__ instead of __nonzero__.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5402
diff
changeset
|
3671 __nonzero__ = __bool__ |
|
5457
a35d4cc8cd1a
fix MissingValue / MockNull to return False on __bool__ and add a
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5448
diff
changeset
|
3672 def __contains__(self, key): return False |
|
5461
ad8031290639
Python 3 compatibility for missing / mock value
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5457
diff
changeset
|
3673 def __eq__(self, rhs): return False |
|
ad8031290639
Python 3 compatibility for missing / mock value
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5457
diff
changeset
|
3674 def __ne__(self, rhs): return False |
|
3164
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
3675 def __str__(self): return '[%s]'%self.__description |
|
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
3676 def __repr__(self): return '<MissingValue 0x%x "%s">'%(id(self), |
|
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
3677 self.__description) |
|
7018
379a5e501dab
flake8: fix whitespace around : and operator and add blank lines
John Rouillard <rouilj@ieee.org>
parents:
7017
diff
changeset
|
3678 |
|
3164
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
3679 def gettext(self, str): return str |
|
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
3680 _ = gettext |
|
24476db8872f
nicer error looking up values of None (response to [SF#1108697])
Richard Jones <richard@users.sourceforge.net>
parents:
3159
diff
changeset
|
3681 |
|
2561
0dd3dca6bd01
always use translation service set in the tracker client instance;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2558
diff
changeset
|
3682 # vim: set et sts=4 sw=4 : |
