~launchpad-pqm/launchpad/devel

11128.6.5 by Michael Hudson
translations
1
# Copyright 2010 Canonical Ltd.  This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
4
"""Translations's custom publication."""
5
6
__metaclass__ = type
7
__all__ = [
8
    'TranslationsBrowserRequest',
9
    'TranslationsLayer',
10
    'translations_request_publication_factory',
11
    ]
12
13
14
from zope.interface import implements
15
from zope.publisher.interfaces.browser import (
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
16
    IBrowserRequest,
17
    IDefaultBrowserLayer,
18
    )
11128.6.5 by Michael Hudson
translations
19
20
from canonical.launchpad.webapp.publication import LaunchpadBrowserPublication
21
from canonical.launchpad.webapp.servers import (
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
22
    LaunchpadBrowserRequest,
23
    VHostWebServiceRequestPublicationFactory,
24
    )
11128.6.5 by Michael Hudson
translations
25
26
27
class TranslationsLayer(IBrowserRequest, IDefaultBrowserLayer):
28
    """The Translations layer."""
29
30
11128.6.9 by Michael Hudson
add tests for translations publishing
31
class TranslationsBrowserRequest(LaunchpadBrowserRequest):
32
    """Instances of TranslationsBrowserRequest provide `TranslationsLayer`."""
11128.6.5 by Michael Hudson
translations
33
    implements(TranslationsLayer)
34
35
    def __init__(self, body_instream, environ, response=None):
36
        super(TranslationsBrowserRequest, self).__init__(
37
            body_instream, environ, response)
38
        # Many of the responses from Translations vary based on language.
39
        self.response.setHeader(
40
            'Vary', 'Cookie, Authorization, Accept-Language')
41
42
43
def translations_request_publication_factory():
11128.6.9 by Michael Hudson
add tests for translations publishing
44
    return VHostWebServiceRequestPublicationFactory(
11128.6.18 by Michael Hudson
fix lots of lint
45
        'translations', TranslationsBrowserRequest,
46
        LaunchpadBrowserPublication)