Mercurial > p > roundup > code
annotate roundup/cgi/engine_zopetal.py @ 6593:e70e2789bc2c
issue2551189 - increase text search maxlength
This removes I think all the magic references to 25 and 30 (varchar
size) and replaces them with references to maxlength or maxlength+5.
I am not sure why the db column is 5 characters larger than the size
of what should be the max size of a word, but I'll keep the buffer
of 5 as making it 1/5 the size of maxlength makes less sense.
Also added tests for fts search in templating which were missing.
Added postgres, mysql and sqlite native indexing backends in which to
test fts. Added fts test to native-fts as well to make sure it's
working.
I want to commit this now for CI.
Todo:
add test cases for the use of FTS in the csv output in
actions.py. There is no test coverage of the match case there.
change maxlength to a higher value (50) as requested in the ticket.
Modify existing extremewords test cases to allow words > 25 and < 51
write code to migrate column sizes for mysql and postgresql to match
maxlength I will roll this into the version 7 schema update that
supports use of database fts support.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Tue, 25 Jan 2022 13:22:00 -0500 |
| parents | 808f7a8ed2b6 |
| children | 408fd477761f |
| rev | line source |
|---|---|
|
4587
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
1 """Templating engine adapter for the legacy TAL implementation ported from |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
2 Zope. |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
3 """ |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
4 __docformat__ = 'restructuredtext' |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
5 |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
6 import errno |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
7 import mimetypes |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
8 import os |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
9 import os.path |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
10 |
|
4749
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4740
diff
changeset
|
11 from roundup.cgi.templating import StringIO, context, translationService, TALLoaderBase |
|
4587
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
12 from roundup.cgi.PageTemplates import PageTemplate, GlobalTranslationService |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
13 from roundup.cgi.PageTemplates.Expressions import getEngine |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
14 from roundup.cgi.TAL import TALInterpreter |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
15 |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
16 GlobalTranslationService.setGlobalTranslationService(translationService) |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
17 |
| 6192 | 18 |
|
4749
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4740
diff
changeset
|
19 class Loader(TALLoaderBase): |
|
4587
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
20 templates = {} |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
21 |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
22 def __init__(self, dir): |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
23 self.dir = dir |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
24 |
|
4740
fe9568a6cbd6
Untangle template selection logic from template loading functionality.
anatoly techtonik <techtonik@gmail.com>
parents:
4739
diff
changeset
|
25 def load(self, tplname): |
|
4587
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
26 # find the source |
|
4749
0421390b3094
templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents:
4740
diff
changeset
|
27 src, filename = self._find(tplname) |
|
4587
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
28 |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
29 # has it changed? |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
30 try: |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
31 stime = os.stat(src)[os.path.stat.ST_MTIME] |
|
5248
198b6e810c67
Use Python-3-compatible 'as' syntax for except statements
Eric S. Raymond <esr@thyrsus.com>
parents:
4749
diff
changeset
|
32 except os.error as error: |
|
4587
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
33 if error.errno != errno.ENOENT: |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
34 raise |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
35 |
|
5381
0942fe89e82e
Python 3 preparation: change "x.has_key(y)" to "y in x".
Joseph Myers <jsm@polyomino.org.uk>
parents:
5378
diff
changeset
|
36 if src in self.templates and \ |
|
4587
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
37 stime <= self.templates[src].mtime: |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
38 # compiled template is up to date |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
39 return self.templates[src] |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
40 |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
41 # compile the template |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
42 pt = RoundupPageTemplate() |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
43 # use pt_edit so we can pass the content_type guess too |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
44 content_type = mimetypes.guess_type(filename)[0] or 'text/html' |
|
6479
808f7a8ed2b6
Clean leaking file descriptors. Eliminates ResourceWarnings.
John Rouillard <rouilj@ieee.org>
parents:
6192
diff
changeset
|
45 with open(src) as srcd: |
|
808f7a8ed2b6
Clean leaking file descriptors. Eliminates ResourceWarnings.
John Rouillard <rouilj@ieee.org>
parents:
6192
diff
changeset
|
46 pt.pt_edit(srcd.read(), content_type) |
|
4587
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
47 pt.id = filename |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
48 pt.mtime = stime |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
49 # Add it to the cache. We cannot do this until the template |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
50 # is fully initialized, as we could otherwise have a race |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
51 # condition when running with multiple threads: |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
52 # |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
53 # 1. Thread A notices the template is not in the cache, |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
54 # adds it, but has not yet set "mtime". |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
55 # |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
56 # 2. Thread B notices the template is in the cache, checks |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
57 # "mtime" (above) and crashes. |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
58 # |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
59 # Since Python dictionary access is atomic, as long as we |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
60 # insert "pt" only after it is fully initialized, we avoid |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
61 # this race condition. It's possible that two separate |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
62 # threads will both do the work of initializing the template, |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
63 # but the risk of wasted work is offset by avoiding a lock. |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
64 self.templates[src] = pt |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
65 return pt |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
66 |
| 6192 | 67 |
|
4587
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
68 class RoundupPageTemplate(PageTemplate.PageTemplate): |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
69 """A Roundup-specific PageTemplate. |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
70 |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
71 Interrogate the client to set up Roundup-specific template variables |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
72 to be available. See 'context' function for the list of variables. |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
73 |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
74 """ |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
75 |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
76 def render(self, client, classname, request, **options): |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
77 """Render this Page Template""" |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
78 |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
79 if not self._v_cooked: |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
80 self._cook() |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
81 |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
82 __traceback_supplement__ = (PageTemplate.PageTemplateTracebackSupplement, self) |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
83 |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
84 if self._v_errors: |
| 6192 | 85 raise PageTemplate.PTRuntimeError('Page Template %s has errors.' % |
| 86 self.id) | |
|
4587
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
87 |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
88 # figure the context |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
89 c = context(client, self, classname, request) |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
90 c.update({'options': options}) |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
91 |
|
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
92 # and go |
|
5418
55f09ca366c4
Python 3 preparation: StringIO.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5381
diff
changeset
|
93 output = StringIO() |
|
4587
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
94 TALInterpreter.TALInterpreter(self._v_program, self.macros, |
| 6192 | 95 getEngine().getContext(c), output, |
| 96 tal=1, strictinsert=0)() | |
|
4587
a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
97 return output.getvalue() |
