~launchpad-pqm/launchpad/devel

14134.2.2 by Danilo Segan
Update copyright notice.
1
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
8687.15.34 by Karl Fogel
Add license header blocks to .py, .zcml, and .pt files that don't have it
2
# GNU Affero General Public License version 3 (see the file LICENSE).
8919.1.1 by Danilo Šegan
Move Distribution translations views out of registry and into translations, and clean up unfinished bits of product move.
3
4
"""Translations browser views for distributions."""
5
6
__metaclass__ = type
7
8
__all__ = [
9
    'DistributionLanguagePackAdminView',
10089.2.13 by Adi Roiban
Fix some formats and rename to +settings.
10
    'DistributionSettingsView',
8919.1.1 by Danilo Šegan
Move Distribution translations views out of registry and into translations, and clean up unfinished bits of product move.
11
    'DistributionView',
12
    ]
13
14
import operator
15
14612.2.1 by William Grant
format-imports on lib/. So many imports.
16
from lp.app.enums import service_uses_launchpad
17
from lp.registry.browser import RegistryEditFormView
18
from lp.registry.interfaces.distribution import IDistribution
19
from lp.registry.interfaces.series import SeriesStatus
20
from lp.services.propertycache import cachedproperty
14600.2.2 by Curtis Hovey
Moved webapp to lp.services.
21
from lp.services.webapp import (
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
22
    action,
23
    canonical_url,
24
    enabled_with_permission,
25
    LaunchpadEditFormView,
26
    LaunchpadView,
27
    Link,
28
    )
14600.2.2 by Curtis Hovey
Moved webapp to lp.services.
29
from lp.services.webapp.authorization import check_permission
30
from lp.services.webapp.menu import NavigationMenu
9269.2.2 by Danilo Šegan
Replace distribution-translation-settings.pt with set-translators.pt.
31
from lp.translations.browser.translations import TranslationsMixin
8919.1.1 by Danilo Šegan
Move Distribution translations views out of registry and into translations, and clean up unfinished bits of product move.
32
33
34
class DistributionTranslationsMenu(NavigationMenu):
35
36
    usedfor = IDistribution
37
    facet = 'translations'
10089.2.13 by Adi Roiban
Fix some formats and rename to +settings.
38
    links = ['overview', 'settings', 'language_pack_admin', 'imports']
8919.1.1 by Danilo Šegan
Move Distribution translations views out of registry and into translations, and clean up unfinished bits of product move.
39
40
    def overview(self):
41
        text = 'Overview'
42
        link = canonical_url(self.context, rootsite='translations')
43
        return Link(link, text)
44
10089.2.13 by Adi Roiban
Fix some formats and rename to +settings.
45
    @enabled_with_permission('launchpad.TranslationsAdmin')
46
    def settings(self):
12140.2.5 by Danilo Segan
Fix up tests.
47
        text = 'Configure translations'
11388.1.9 by Tim Penhey
Explicitly setting the translations rootsite.
48
        return Link('+settings', text, icon='edit', site='translations')
8919.1.1 by Danilo Šegan
Move Distribution translations views out of registry and into translations, and clean up unfinished bits of product move.
49
50
    @enabled_with_permission('launchpad.TranslationsAdmin')
51
    def language_pack_admin(self):
52
        text = 'Language pack admin'
11388.1.9 by Tim Penhey
Explicitly setting the translations rootsite.
53
        return Link(
54
            '+select-language-pack-admin', text, icon='edit',
55
            site='translations')
8919.1.1 by Danilo Šegan
Move Distribution translations views out of registry and into translations, and clean up unfinished bits of product move.
56
57
    def imports(self):
58
        text = 'Import queue'
11388.1.9 by Tim Penhey
Explicitly setting the translations rootsite.
59
        return Link('+imports', text, site='translations')
8919.1.1 by Danilo Šegan
Move Distribution translations views out of registry and into translations, and clean up unfinished bits of product move.
60
61
62
class DistributionLanguagePackAdminView(LaunchpadEditFormView):
63
    """Browser view to change the language pack administrator."""
64
65
    schema = IDistribution
9481.1.1 by Danilo Šegan
Fix up headings and titles on distribution pages.
66
    label = "Select the language pack administrator"
8919.1.1 by Danilo Šegan
Move Distribution translations views out of registry and into translations, and clean up unfinished bits of product move.
67
    field_names = ['language_pack_admin']
68
9264.3.5 by Danilo Šegan
Replace distribution-language-pack-admin.pt with generic-edit.pt.
69
    @property
70
    def cancel_url(self):
11388.1.9 by Tim Penhey
Explicitly setting the translations rootsite.
71
        return canonical_url(self.context, rootsite="translations")
9264.3.5 by Danilo Šegan
Replace distribution-language-pack-admin.pt with generic-edit.pt.
72
11388.1.9 by Tim Penhey
Explicitly setting the translations rootsite.
73
    next_url = cancel_url
9264.3.5 by Danilo Šegan
Replace distribution-language-pack-admin.pt with generic-edit.pt.
74
75
    @property
76
    def page_title(self):
9264.3.6 by Danilo Šegan
Fix the page title for langpack admin.
77
        return 'Change the %s language pack administrator' % (
9264.3.5 by Danilo Šegan
Replace distribution-language-pack-admin.pt with generic-edit.pt.
78
            self.context.displayname)
79
8919.1.1 by Danilo Šegan
Move Distribution translations views out of registry and into translations, and clean up unfinished bits of product move.
80
    @action("Change", name='change')
81
    def change_action(self, action, data):
82
        self.updateContextFromData(data)
83
84
85
class DistributionView(LaunchpadView):
86
    """Default Distribution view class."""
87
9481.1.1 by Danilo Šegan
Fix up headings and titles on distribution pages.
88
    label = "Translations overview"
89
8919.1.1 by Danilo Šegan
Move Distribution translations views out of registry and into translations, and clean up unfinished bits of product move.
90
    @cachedproperty
91
    def translation_focus(self):
92
        """Return the IDistroSeries where the translators should work.
93
94
        If ther isn't a defined focus, we return latest series.
95
        """
96
        if self.context.translation_focus is None:
97
            return self.context.currentseries
98
        else:
99
            return self.context.translation_focus
100
11551.8.2 by j.c.sackett
Updated distribution to use portlet when not showing content.
101
    @cachedproperty
102
    def show_page_content(self):
103
        """Whether the main content of the page should be shown."""
104
        return (service_uses_launchpad(self.context.translations_usage) or
11551.8.25 by j.c.sackett
Lint fixes.
105
               self.is_translations_admin)
11551.8.21 by j.c.sackett
Finished up the distribution template for unknown translations.
106
107
    def can_configure_translations(self):
108
        """Whether or not the user can configure translations."""
12143.2.5 by Danilo Segan
Fix up failing tests.
109
        return check_permission("launchpad.TranslationsAdmin", self.context)
11551.8.21 by j.c.sackett
Finished up the distribution template for unknown translations.
110
111
    def is_translations_admin(self):
112
        """Whether or not the user is a translations admin."""
113
        return check_permission("launchpad.TranslationsAdmin", self.context)
11551.8.2 by j.c.sackett
Updated distribution to use portlet when not showing content.
114
9760.8.1 by Brad Crittenden
Change the non-English 'serieses' to 'series' throughout our codebase.
115
    def secondary_translatable_series(self):
8919.1.1 by Danilo Šegan
Move Distribution translations views out of registry and into translations, and clean up unfinished bits of product move.
116
        """Return a list of IDistroSeries that aren't the translation_focus.
117
118
        It only includes the ones that are still supported.
119
        """
9760.8.1 by Brad Crittenden
Change the non-English 'serieses' to 'series' throughout our codebase.
120
        series = [
8919.1.1 by Danilo Šegan
Move Distribution translations views out of registry and into translations, and clean up unfinished bits of product move.
121
            series
9760.8.1 by Brad Crittenden
Change the non-English 'serieses' to 'series' throughout our codebase.
122
            for series in self.context.series
10054.26.1 by Adi Roiban
Refactor DistroSeriesStatus to SeriesStatus; Don't prompt for setting up translations for obsolete product series.
123
            if (series.status != SeriesStatus.OBSOLETE
8919.1.1 by Danilo Šegan
Move Distribution translations views out of registry and into translations, and clean up unfinished bits of product move.
124
                and (self.translation_focus is None or
11551.8.2 by j.c.sackett
Updated distribution to use portlet when not showing content.
125
                     self.translation_focus.id != series.id))]
8919.1.1 by Danilo Šegan
Move Distribution translations views out of registry and into translations, and clean up unfinished bits of product move.
126
9760.8.1 by Brad Crittenden
Change the non-English 'serieses' to 'series' throughout our codebase.
127
        return sorted(series, key=operator.attrgetter('version'),
8919.1.1 by Danilo Šegan
Move Distribution translations views out of registry and into translations, and clean up unfinished bits of product move.
128
                      reverse=True)
129
9269.2.2 by Danilo Šegan
Replace distribution-translation-settings.pt with set-translators.pt.
130
14134.2.1 by Danilo Segan
Show only relevant fields for distribution translation settings and fix privileges for them.
131
class DistributionSettingsView(TranslationsMixin, RegistryEditFormView):
12140.2.1 by Danilo Segan
Clean-up a few UI-elements regarding the settings page.
132
    label = "Translations settings"
133
    page_title = "Settings"
14134.2.1 by Danilo Segan
Show only relevant fields for distribution translation settings and fix privileges for them.
134
    schema = IDistribution
135
12140.2.1 by Danilo Segan
Clean-up a few UI-elements regarding the settings page.
136
    field_names = [
14120.2.2 by Danilo Segan
Remove most of the official_rosetta use from the code and fix all the tests.
137
        "translations_usage",
12140.2.1 by Danilo Segan
Clean-up a few UI-elements regarding the settings page.
138
        "translation_focus",
139
        "translationgroup",
140
        "translationpermission",
141
        ]
9269.2.2 by Danilo Šegan
Replace distribution-translation-settings.pt with set-translators.pt.
142
143
    @property
144
    def cancel_url(self):
11388.1.9 by Tim Penhey
Explicitly setting the translations rootsite.
145
        return canonical_url(self.context, rootsite="translations")
9269.2.2 by Danilo Šegan
Replace distribution-translation-settings.pt with set-translators.pt.
146
11388.1.9 by Tim Penhey
Explicitly setting the translations rootsite.
147
    next_url = cancel_url
9269.2.2 by Danilo Šegan
Replace distribution-translation-settings.pt with set-translators.pt.
148
149
    @action('Change', name='change')
150
    def edit(self, action, data):
151
        self.updateContextFromData(data)