Mercurial > p > roundup > code
annotate roundup/dist/command/build.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 | f2fade4552c5 |
| children | 42bf0a707763 |
| rev | line source |
|---|---|
| 4068 | 1 # |
| 2 # Copyright (C) 2009 Stefan Seefeld | |
| 3 # All rights reserved. | |
| 4 # For license terms see the file COPYING.txt. | |
| 5 # | |
|
5376
64b05e24dbd8
Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4516
diff
changeset
|
6 from __future__ import print_function |
| 4068 | 7 from roundup import msgfmt |
| 8 from distutils.command.build import build as base | |
| 9 import os | |
| 10 from glob import glob | |
| 11 | |
| 12 def list_message_files(suffix=".po"): | |
| 13 """Return list of all found message files and their intallation paths""" | |
| 14 _files = glob("locale/*" + suffix) | |
| 15 _list = [] | |
| 16 for _file in _files: | |
| 17 # basename (without extension) is a locale name | |
| 18 _locale = os.path.splitext(os.path.basename(_file))[0] | |
| 19 _list.append((_file, os.path.join( | |
| 20 "share", "locale", _locale, "LC_MESSAGES", "roundup.mo"))) | |
| 21 return _list | |
| 22 | |
| 23 def check_manifest(): | |
| 24 """Check that the files listed in the MANIFEST are present when the | |
| 25 source is unpacked. | |
| 26 """ | |
| 27 try: | |
| 28 f = open('MANIFEST') | |
| 29 except: | |
|
5376
64b05e24dbd8
Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4516
diff
changeset
|
30 print('\n*** SOURCE WARNING: The MANIFEST file is missing!') |
| 4068 | 31 return |
| 32 try: | |
| 33 manifest = [l.strip() for l in f.readlines()] | |
| 34 finally: | |
| 35 f.close() | |
|
4394
d4cd0a264098
fixed reporting of source missing warnings
Richard Jones <richard@users.sourceforge.net>
parents:
4068
diff
changeset
|
36 err = set([line for line in manifest if not os.path.exists(line)]) |
| 4068 | 37 # ignore auto-generated files |
|
4394
d4cd0a264098
fixed reporting of source missing warnings
Richard Jones <richard@users.sourceforge.net>
parents:
4068
diff
changeset
|
38 err = err - set(['roundup-admin', 'roundup-demo', 'roundup-gettext', |
|
d4cd0a264098
fixed reporting of source missing warnings
Richard Jones <richard@users.sourceforge.net>
parents:
4068
diff
changeset
|
39 'roundup-mailgw', 'roundup-server', 'roundup-xmlrpc-server']) |
| 4068 | 40 if err: |
| 41 n = len(manifest) | |
|
5376
64b05e24dbd8
Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4516
diff
changeset
|
42 print('\n*** SOURCE WARNING: There are files missing (%d/%d found)!'%( |
|
64b05e24dbd8
Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4516
diff
changeset
|
43 n-len(err), n)) |
|
64b05e24dbd8
Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4516
diff
changeset
|
44 print('Missing:', '\nMissing: '.join(err)) |
| 4068 | 45 |
|
4516
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
46 def build_message_files(command): |
|
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
47 """For each locale/*.po, build .mo file in target locale directory""" |
|
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
48 for (_src, _dst) in list_message_files(): |
|
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
49 _build_dst = os.path.join("build", _dst) |
|
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
50 command.mkpath(os.path.dirname(_build_dst)) |
|
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
51 command.announce("Compiling %s -> %s" % (_src, _build_dst)) |
|
5450
f2fade4552c5
replaced msgfmt.py with latest version supporting Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5376
diff
changeset
|
52 mo = msgfmt.Msgfmt(_src).get() |
|
f2fade4552c5
replaced msgfmt.py with latest version supporting Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5376
diff
changeset
|
53 open(_build_dst, 'wb').write(mo) |
|
4516
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
54 |
| 4068 | 55 |
| 56 class build(base): | |
| 57 | |
| 58 def run(self): | |
| 59 check_manifest() | |
|
4516
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
60 build_message_files(self) |
| 4068 | 61 base.run(self) |
| 62 |
