~launchpad-pqm/launchpad/devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

# pylint: disable-msg=E0211,E0213

"""Interfaces for groups of translators."""

__metaclass__ = type

__all__ = [
    'ITranslationGroup',
    'ITranslationGroupSet',
    'TranslationPermission',
    ]

from lazr.restful.declarations import (
    collection_default_content,
    exported,
    export_as_webservice_entry,
    export_as_webservice_collection,
    export_read_operation,
    export_operation_as,
    operation_for_version,
    operation_parameters,
    operation_returns_entry,
    )
from zope.interface import (
    Attribute,
    Interface,
    )
from zope.schema import (
    Datetime,
    Int,
    TextLine,
    )

from canonical.launchpad import _
from lp.app.validators.name import name_validator
from lp.registry.interfaces.role import IHasOwner
from lp.services.fields import (
    PublicPersonChoice,
    Summary,
    Title,
    URIField,
    )
from lp.translations.enums import TranslationPermission


class ITranslationGroup(IHasOwner):
    """A TranslationGroup."""

    export_as_webservice_entry(
        singular_name='translation_group', plural_name='translation_groups')

    id = Int(
            title=_('Translation Group ID'), required=True, readonly=True,
            )
    name = exported(
        TextLine(
            title=_('Name'), required=True,
            description=_("""Keep this name very short, unique, and
            descriptive, because it will be used in URLs. Examples:
            gnome-translation-project, ubuntu-translators."""),
            constraint=name_validator),
        as_of="devel"
        )
    title = exported(
        Title(
            title=_('Title'), required=True,
            description=_("""Title of this Translation Group.
            This title is displayed at the top of the Translation Group
            page and in lists or reports of translation groups.  Do not
            add "translation group" to this title, or it will be shown
            double.
            """),),
        as_of="devel"
        )
    summary = Summary(
            title=_('Summary'), required=True,
            description=_("""A single-paragraph description of the
            group. This will also be displayed in most
            translation group listings."""),
            )
    datecreated = Datetime(
            title=_('Date Created'), required=True, readonly=True,
            )
    owner = PublicPersonChoice(
            title=_('Owner'), required=True, vocabulary='ValidOwner',
            description=_("The owner's IPerson"))
    # joins
    translators = Attribute('The set of translators for this group.')
    projects = Attribute('The projects for which this group translates.')
    products = Attribute('The projects to which this group is directly '
        'appointed as a translator. There may be other projects that are '
        'part of project groups for which the group also translates.')
    distributions = Attribute('The distros for which this group translates.')

    translation_guide_url = URIField(
        title=_('Translation instructions'), required=False,
        allowed_schemes=['http', 'https', 'ftp'],
        allow_userinfo=False,
        description=_("The URL of the generic translation instructions "
                      "followed by this particular translation group. "
                      "This should include team policies and "
                      "recommendations, specific instructions for "
                      "any non-standard behaviour and other documentation."
                      "Can be any of http://, https://, or ftp://."))

    # accessing the translator list
    def query_translator(language):
        """Retrieve a translator, or None, based on a Language"""

    # adding and removing translators
    def remove_translator(language):
        """Remove the translator for this language from the group."""

    # used for the form machinery
    def add(content):
        """Add a new object."""

    top_projects = Attribute(
        "Most relevant projects using this translation group.")

    number_of_remaining_projects = Attribute(
        "Count of remaining projects not listed in the `top_projects`.")

    def __getitem__(language_code):
        """Retrieve the translator for the given language in this group.

        This is used for navigation through the group.
        """

    def fetchTranslatorData():
        """Fetch translators and related data.

        Prefetches display-related properties.

        :return: A result set of (`Translator`, `Language`, `Person`),
            ordered by language name in English.
        """

    def fetchProjectsForDisplay():
        """Fetch `Product`s using this group, for display purposes.

        Prefetches display-related properties.

        :return: A result set of `Product`, ordered by display name.
        """

    def fetchProjectGroupsForDisplay():
        """Fetch `Project`s using this group, for display purposes.

        Prefetches display-related properties.

        :return: A result set of `Project`, ordered by display name.
        """

    def fetchDistrosForDisplay():
        """Fetch `Distribution`s using this group, for display purposes.

        Prefetches display-related properties.

        :return: A result set of `Distribution`, ordered by display name.
        """


class ITranslationGroupSet(Interface):
    """A container for translation groups."""

    export_as_webservice_collection(ITranslationGroup)

    title = Attribute('Title')

    @operation_parameters(
        name=TextLine(title=_("Name of the translation group"),))
    @operation_returns_entry(ITranslationGroup)
    @export_read_operation()
    @operation_for_version('devel')
    def getByName(name):
        """Get a translation group by name."""

    def __getitem__(name):
        """Get a translation group by name."""

    @collection_default_content()
    def _get():
        """Return a collection of all entries."""

    def __iter__():
        """Iterate through the translation groups in this set."""

    def new(name, title, summary, translation_guide_url, owner):
        """Create a new translation group."""

    def getByPerson(person):
        """Return the translation groups which that person is a member of."""

    def getGroupsCount():
        """Return the amount of translation groups available."""