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

# pylint: disable-msg=E0211,E0213

from zope.interface import (
    Attribute,
    Interface,
    )
from zope.interface.common.sequence import IFiniteSequence
from zope.schema import (
    Datetime,
    Object,
    )

from canonical.launchpad import _
from lp.registry.interfaces.person import IPerson
from lp.services.worlddata.interfaces.language import ILanguage
from lp.translations.interfaces.hastranslationtemplates import (
    IHasTranslationTemplates,
    )


__metaclass__ = type

__all__ = [
    'IPOFilesByPOTemplates',
    'ITranslatedLanguage',
    ]


class ITranslatedLanguage(Interface):
    """Interface for providing translations for context by language.

    It expects `parent` to provide `IHasTranslationTemplates`.
    """

    language = Object(
        title=_('Language to gather statistics and POFiles for.'),
        schema=ILanguage)

    parent = Object(
        title=_('A parent with translation templates.'),
        schema=IHasTranslationTemplates)

    pofiles = Attribute(
        _('Iterator over all POFiles for this context and language.'))

    translation_statistics = Attribute(
        _('A dict containing relevant aggregated statistics counts.'))

    def setCounts(total, translated, new, changed, unreviewed):
        """Set aggregated message counts for ITranslatedLanguage."""

    def recalculateCounts():
        """Recalculate message counts for this ITranslatedLanguage."""

    last_changed_date = Datetime(
        title=_('When was this translation last changed.'),
        readonly=False, required=True)

    last_translator = Object(
        title=_('Last person that translated something in this context.'),
        schema=IPerson)


class IPOFilesByPOTemplates(IFiniteSequence):
    """Iterate `IPOFile`s for (`ILanguage`, `ITranslationTemplateCollection`).

    This is a wrapper for Storm ResultSet that enables optimized slicing
    by doing it lazily on the query, thus allowing DummyPOFile objects
    to be returned while still not doing more than one database query.

    It subclasses `IFiniteSequence` so it can easily be used with the
    BatchNavigator.
    """

    def __getitem__(selector):
        """Get an element or slice of `IPOFile`s for given templates."""

    def __getslice__(start, end):
        """Deprecated, and implemented through __getitem__."""

    def __iter__():
        """Iterates over all `IPOFile`s for given templates."""

    def __len__():
        """Provides count of `IPOTemplate`s in a template collection."""