Merge lp:~jtv/launchpad/recife-pre-sharing-permissions into lp:~launchpad/launchpad/recife
| Status: | Merged |
|---|---|
| Approved by: | Gavin Panella on 2010-10-14 |
| Approved revision: | no longer in the source branch. |
| Merged at revision: | 9173 |
| Proposed branch: | lp:~jtv/launchpad/recife-pre-sharing-permissions |
| Merge into: | lp:~launchpad/launchpad/recife |
| Diff against target: |
801 lines (+239/-168) 15 files modified
lib/lp/testing/factory.py (+8/-2) lib/lp/testing/tests/test_factory.py (+8/-0) lib/lp/translations/browser/pofile.py (+0/-9) lib/lp/translations/browser/tests/pofile-base-views.txt (+0/-2) lib/lp/translations/browser/tests/test_translationmessage_view.py (+63/-4) lib/lp/translations/browser/tests/translationmessage-views.txt (+2/-28) lib/lp/translations/browser/translationmessage.py (+74/-56) lib/lp/translations/interfaces/pofile.py (+3/-0) lib/lp/translations/model/pofile.py (+35/-11) lib/lp/translations/stories/standalone/xx-licensing.txt (+0/-11) lib/lp/translations/stories/standalone/xx-pofile-translate.txt (+0/-12) lib/lp/translations/stories/standalone/xx-translationmessage-translate.txt (+0/-12) lib/lp/translations/tests/test_pofile.py (+43/-18) lib/lp/translations/utilities/tests/test_file_importer.py (+2/-2) lib/lp/translations/utilities/translation_import.py (+1/-1) |
| To merge this branch: | bzr merge lp:~jtv/launchpad/recife-pre-sharing-permissions |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Gavin Panella (community) | code | Approve on 2010-10-14 | |
| Launchpad code reviewers | code | 2010-10-14 | Pending |
|
Review via email:
|
|||
Commit Message
Cleanups in preparation for Recife sharing permissions check.
Description of the Change
= Cleanups prior to Recife sharing permissions checks =
This is a cleanup to be merged into the Recife feature branch.
I'm working on the part of the Recife model change where we check if a particular translation submission for Ubuntu should be shared with upstream, or vice versa. In my preparations I came across some things that needed cleaning up:
* The basic translation view checked far too many separate things in one big method.
* View failures generated some truly horrible error messages.
* Existing permissions checks needed breaking down into smaller chunks to be comprehensible.
* Some inefficient "do we know how plural forms work for this POFile" logic was also redundant.
* Reading of "lock_timestamp" was tested in a doctest instead of a view unit test.
* Lots and lots of trailing whitespace.
I sped up the inefficient logic by doing the cheapest (and often sufficient) test first, centralized it into a single method, and replaced the view properties that duplicated it with a single attribute.
To test, best run all Translations tests really:
{{{
./bin/test -vvc lp.translations
}}}
There's a bit of lint left, most related to comment blocks that aren't directly attached to their respective next lines. I think that style is valid where the comment applies to a section of a class, as these do, so I didn't touch these cases. The other source of lint is Moin-style headings in doctests, which I didn't touch in order to stay under the review limit.
Jeroen
| Jeroen T. Vermeulen (jtv) wrote : | # |
> Nice branch, r=me, with a few very minor comments.
Thanks! Good stuff. My replies:
> [1]
>
> +from __future__ import with_statement
>
> I don't think we need to do this anymore.
So did I, but there have been nasty surprises lately where we _thought_ we were all the way there (just a few days ago there was another "we're on 2.6!—er, almost" thread) so I decided to be conservative. I suppose at some point we'll clean these up collectively.
> [2]
>
> + if blank_timestamp:
> + view.lock_timestamp = None
> + else:
> + view.lock_timestamp = datetime.
>
> The blank_timestamp argument is only used once. If you did the
> following in that one place, could this argument be removed and the
> code above simplified?
>
> view = self._makeView()
> view.lock_timestamp = None
Yup. Much better!
> [3]
>
> +All the tests will be submitted as comming from Kurem, an editor for the
>
> s/comming/coming/
Thanks for spotting that. Normally I'm the big pedant.
> [4]
>
> + if method == 'POST' and self.request.
>
> What should submit_translations look like? The style guide would say
> that this needs to be explicit.
You're right. AFAICS the ideal spelling is "if 'submit_
> [5]
>
> + if is_read_only():
> + raise UnexpectedFormData(
> + "Launchpad is currently in read-only mode for maintenance. "
> + "Please try again later.")
>
> Is this not taken care of earlier in the request by, say, the
> publication machinery? I haven't done anything to make views cope with
> read-only mode, so I'd like to know if I can continue to be oblivious
> to this or if I need to do something about it.
In theory, yes, this is taken care of. But read-only mode ignores transaction boundaries and isolation levels: it is signaled by the presence of a particular file. That file can appear while processing a request. This check is here because we had one or two oopses while switching to read-only mode.
> [6]
>
> + if self.user is None:
> + raise UnexpectedFormD
>
> Is this needed? Similar question to [5] really.
It's needed for, arguably, a stupid reason. (Don't think I knew this; I checked up just now). Yes, the permissions machinery takes care of it but at a later stage. We're checking it here because the rest of the initialize code makes use of self.user, and bailing out here is easier than guarding all those cases just so we can arrive at another similar error at the end.
Jeroen

Nice branch, r=me, with a few very minor comments.
[1]
+from __future__ import with_statement
+
I don't think we need to do this anymore.
[2]
+ if blank_timestamp: now(pytz. utc)
+ view.lock_timestamp = None
+ else:
+ view.lock_timestamp = datetime.
The blank_timestamp argument is only used once. If you did the
following in that one place, could this argument be removed and the
code above simplified?
view = self._makeView() lock_timestamp = None
view.
[3]
+All the tests will be submitted as comming from Kurem, an editor for the
s/comming/coming/
[4]
+ if method == 'POST' and self.request. form.get( 'submit_ translations' ):
What should submit_translations look like? The style guide would say
that this needs to be explicit.
[5]
+ if is_read_only():
+ raise UnexpectedFormData(
+ "Launchpad is currently in read-only mode for maintenance. "
+ "Please try again later.")
Is this not taken care of earlier in the request by, say, the
publication machinery? I haven't done anything to make views cope with
read-only mode, so I'd like to know if I can continue to be oblivious
to this or if I need to do something about it.
[6]
+ if self.user is None: ata("You are not logged in.")
+ raise UnexpectedFormD
Is this needed? Similar question to [5] really.