annotate roundup/scripts/roundup_gettext.py @ 5548:fea11d05110e

Avoid errors from selecting "no selection" on multilink (issue2550722). As discussed in issue 2550722 there are various cases where selecting "no selection" on a multilink can result in inappropriate errors from Roundup: * If selecting "no selection" produces a null edit (a value was set in the multilink in an edit with an error, then removed again, along with all other changes, in the next form submission), so the page is rendered from the form contents including the "-<id>" value for "no selection" for the multilink. * If creating an item with a nonempty value for a multilink has an error, and the resubmission changes that multilink to "no selection" (and this in turn has subcases, according to whether the creation then succeeds or fails on the resubmission, which need fixes in different places in the Roundup code). All of these cases have in common that it is expected and OK to have a "-<id>" value for a submission for a multilink when <id> is not set in that multilink in the database (because the original attempt to set <id> in that multilink had an error), so the hyperdb.py logic to give an error in that case is thus removed. In the subcase of the second case where the resubmission with "no selection" has an error, the templating code tries to produce a menu entry for the "-<id>" multilink value, which also results in an error, hence the templating.py change to ignore such values in the list for a multilink.
author Joseph Myers <jsm@polyomino.org.uk>
date Thu, 27 Sep 2018 11:33:01 +0000
parents 64b05e24dbd8
children 32a5a54536b5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2803
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1 #! /usr/bin/env python
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2 #
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
3 # Copyright 2004 Richard Jones (richard@mechanicalcat.net)
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
4
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
5 """Extract translatable strings from tracker templates"""
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
6
5376
64b05e24dbd8 Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents: 4766
diff changeset
7 from __future__ import print_function
2803
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
8 import os
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
9 import sys
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
10
4766
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
11
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
12 # --- patch sys.path to make sure 'import roundup' finds correct version
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
13 import os.path as osp
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
14
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
15 thisdir = osp.dirname(osp.abspath(__file__))
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
16 rootdir = osp.dirname(osp.dirname(thisdir))
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
17 if (osp.exists(thisdir + '/__init__.py') and
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
18 osp.exists(rootdir + '/roundup/__init__.py')):
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
19 # the script is located inside roundup source code
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
20 sys.path.insert(0, rootdir)
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
21 # --/
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
22
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
23
2803
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
24 from roundup.i18n import _
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
25 from roundup.cgi.TAL import talgettext
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
26
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
27 # name of message template file.
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
28 # i don't think this will ever need to be changed, but still...
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
29 TEMPLATE_FILE = "messages.pot"
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
30
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
31 def run():
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
32 # return unless command line arguments contain single directory path
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
33 if (len(sys.argv) != 2) or (sys.argv[1] in ("-h", "--help")):
5376
64b05e24dbd8 Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents: 4766
diff changeset
34 print(_("Usage: %(program)s <tracker home>") % {"program": sys.argv[0]})
2803
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
35 return
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
36 # collect file paths of html templates
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
37 home = os.path.abspath(sys.argv[1])
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
38 htmldir = os.path.join(home, "html")
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
39 if os.path.isdir(htmldir):
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
40 # glob is not used because i want to match file names
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
41 # without case sensitivity, and that is easier done this way.
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
42 htmlfiles = [filename for filename in os.listdir(htmldir)
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
43 if os.path.isfile(os.path.join(htmldir, filename))
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
44 and filename.lower().endswith(".html")]
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
45 else:
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
46 htmlfiles = []
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
47 # return if no html files found
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
48 if not htmlfiles:
5376
64b05e24dbd8 Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents: 4766
diff changeset
49 print(_("No tracker templates found in directory %s") % home)
2803
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
50 return
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
51 # change to locale dir to have relative source references
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
52 locale = os.path.join(home, "locale")
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
53 if not os.path.isdir(locale):
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
54 os.mkdir(locale)
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
55 os.chdir(locale)
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
56 # tweak sys.argv as this is the only way to tell talgettext what to do
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
57 # Note: unix-style paths used instead of os.path.join deliberately
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
58 sys.argv[1:] = ["-o", TEMPLATE_FILE] \
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
59 + ["../html/" + filename for filename in htmlfiles]
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
60 # run
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
61 talgettext.main()
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
62
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
63 if __name__ == "__main__":
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
64 run()
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
65
a7b755646ffd Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
66 # vim: set et sts=4 sw=4 :

Roundup Issue Tracker: http://roundup-tracker.org/