~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
# Copyright 2009 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

# pylint: disable-msg=E0213

__metaclass__ = type

__all__ = [
    'IPOFileTranslator',
    'IPOFileTranslatorSet',
    ]


from zope.interface import Interface
from zope.schema import (
    Datetime,
    Int,
    Object,
    )

from lp import _
from lp.registry.interfaces.person import IPerson
from lp.translations.interfaces.pofile import IPOFile
from lp.translations.interfaces.translationmessage import ITranslationMessage


class IPOFileTranslator(Interface):
    """Represents contributions from people to `POFile`s."""

    id = Int(title=_("ID"), readonly=True, required=True)

    person = Object(
        title=_(u"The `Person` whose contribution this record represents."),
        required=True, readonly=True, schema=IPerson)

    pofile = Object(
        title=_(u"The `POFile` modified by the translator."), required=True,
        readonly=True, schema=IPOFile)

    latest_message = Object(
        title=_(u"Latest `TranslationMessage` for this person and file."),
        required=True, readonly=True, schema=ITranslationMessage)

    date_last_touched = Datetime(
        title=_(u"When the latest translation message was added."),
        required=True, readonly=True)


class IPOFileTranslatorSet(Interface):
    """Interface representing the set of `IPOFileTranslator`records.

    You won't find a "new" method here.  POFileTranslator records are
    created directly in the database by a trigger that watches for
    translation updates.
    """

    def prefetchPOFileTranslatorRelations(pofiletranslators):
        """Batch-prefetch objects attached to given `POFileTranslator`s.

        Fetches a large amount of data relevant to rendering the given
        `POFileTranslator` objects in the user interface, to reduce the
        number of queries needed while rendering the page.
        """

    def getForPersonPOFile(person, pofile):
        """Retrieve `POFileTranslator` for given `Person` and `POFile`.

        :return: one `POFileTranslator` object matching the requested
            person and pofile, or None.
        """

    def getForPOTMsgSet(potmsgset):
        """Retrieve `POFileTranslator`s for translations of `potmsgset`.

        :return: a query result of `POFileTranslator`s whose
            `latest_message` are translations of `potmsgset`.
        """