Beispiel #1
0
    def __init__(self, site, request):
        """Setup the current language stuff."""
        tool = getUtility(ILanguageUtility)
        langs = []
        useContent = tool.settings.use_content_negotiation
        useCcTLD = tool.settings.use_cctld_negotiation
        useSubdomain = tool.settings.use_subdomain_negotiation
        usePath = tool.settings.use_path_negotiation
        useCookie = tool.settings.use_cookie_negotiation
        setCookieEverywhere = tool.settings.set_cookie_always
        authOnly = tool.settings.authenticated_users_only
        useRequest = tool.settings.use_request_negotiation
        useDefault = 1  # This should never be disabled
        langsCookie = None
        if usePath:
            # This one is set if there is an allowed language in the current path
            langs.append(tool.getPathLanguage(request))

        if useContent:
            langs.append(tool.getContentLanguage(request))

        if useCookie and not (authOnly and tool.isAnonymousUser()):
            # If we are using the cookie stuff we provide the setter here
            set_language = request.get('set_language', None)
            if set_language:
                langsCookie = tool.setLanguageCookie(set_language,
                                                     request=request)
            else:
                # Get from cookie
                langsCookie = tool.getLanguageCookie(request)
            langs.append(langsCookie)

        if useSubdomain:
            langs.extend(tool.getSubdomainLanguages(request))

        if useCcTLD:
            langs.extend(tool.getCcTLDLanguages(request))

        # Get langs from request
        if useRequest:
            langs.extend(tool.getRequestLanguages(request))

        # Get default
        if useDefault:
            langs.append(tool.getDefaultLanguage())

        # Filter None languages
        langs = [lang for lang in langs if lang is not None]

        # Set cookie language to language
        if setCookieEverywhere and langs[0] != langsCookie:
            # We need to make sure its not a subrequest otherwise we are going
            # To change the language of the main request
            from plone.subrequest import ISubRequest
            if not ISubRequest.providedBy(request):
                tool.setLanguageCookie(langs[0], noredir=True, request=request)

        self.default_language = langs[-1]
        self.language = langs[0]
        self.language_list = langs[1:-1]
Beispiel #2
0
    def __init__(self, site, request):
        """Setup the current language stuff."""
        tool = getUtility(ILanguageUtility)
        langs = []
        useContent = tool.settings.use_content_negotiation
        useCcTLD = tool.settings.use_cctld_negotiation
        useSubdomain = tool.settings.use_subdomain_negotiation
        usePath = tool.settings.use_path_negotiation
        useCookie = tool.settings.use_cookie_negotiation
        setCookieEverywhere = tool.settings.set_cookie_always
        authOnly = tool.settings.authenticated_users_only
        useRequest = tool.settings.use_request_negotiation
        useDefault = 1 # This should never be disabled
        langsCookie = None
        if usePath:
            # This one is set if there is an allowed language in the current path
            langs.append(tool.getPathLanguage(request))

        if useContent:
            langs.append(tool.getContentLanguage(request))

        if useCookie and not (authOnly and tool.isAnonymousUser()):
            # If we are using the cookie stuff we provide the setter here
            set_language = request.get('set_language', None)
            if set_language:
                langsCookie = tool.setLanguageCookie(set_language, request=request)
            else:
                # Get from cookie
                langsCookie = tool.getLanguageCookie(request)
            langs.append(langsCookie)

        if useSubdomain:
            langs.extend(tool.getSubdomainLanguages(request))

        if useCcTLD:
            langs.extend(tool.getCcTLDLanguages(request))

        # Get langs from request
        if useRequest:
            langs.extend(tool.getRequestLanguages(request))

        # Get default
        if useDefault:
            langs.append(tool.getDefaultLanguage())

        # Filter None languages
        langs = [lang for lang in langs if lang is not None]

        # Set cookie language to language
        if setCookieEverywhere  and langs[0] != langsCookie:
            # We need to make sure its not a subrequest otherwise we are going
            # To change the language of the main request
            from plone.subrequest import ISubRequest
            if not ISubRequest.providedBy(request):
                tool.setLanguageCookie(langs[0], noredir=True, request=request)

        self.default_language = langs[-1]
        self.language = langs[0]
        self.language_list = langs[1:-1]
Beispiel #3
0
 def __call__(self):
     try:
         return self.index()
     except NotFound:
         pass
     request = self.request
     if ISubRequest.providedBy(request):
         request = request.PARENT_REQUEST
     return SiteLayoutView(self.context, request)()
 def __call__(self):
     try:
         return self.index()
     except NotFound:
         if ISubRequest.providedBy(self.request):
             return SiteLayoutView(
                 self.context, self.request.PARENT_REQUEST)()
         else:
             return SiteLayoutView(self.context, self.request)()
Beispiel #5
0
 def __call__(self):
     try:
         return self.index()
     except NotFound:
         if ISubRequest.providedBy(self.request):
             return SiteLayoutView(self.context,
                                   self.request.PARENT_REQUEST)()
         else:
             return SiteLayoutView(self.context, self.request)()
Beispiel #6
0
 def __call__(self):
     content = self.data.get('content')
     if content:
         # only transform is not rendering for layout editor
         if (not self.request.get('_layouteditor') or
                 ISubRequest.providedBy(self.request)):
             transforms = getToolByName(self.context, 'portal_transforms')
             data = transforms.convertTo('text/x-html-safe', content, mimetype='text/html',
                                         context=self.context)
             content = data.getData()
     else:
         content = u'<p></p>'
     return u"<html><body>%s</body></html>" % safe_unicode(content)
Beispiel #7
0
 def __call__(self):
     content = self.data.get('content')
     if content:
         # only transform is not rendering for layout editor
         if (not self.request.get('_layouteditor') or
                 ISubRequest.providedBy(self.request)):
             transforms = getToolByName(self.context, 'portal_transforms')
             data = transforms.convertTo('text/x-html-safe', content, mimetype='text/html',
                                         context=self.context)
             content = data.getData()
     else:
         content = u'<p></p>'
     return u"<html><body>%s</body></html>" % content
Beispiel #8
0
    def get_default_request_data(self):
        """
        from request form
        """
        # try to use a '_tiledata' parameter in the request
        if '_tiledata' in self.tile.request.form:
            data = json.loads(self.tile.request.form['_tiledata'])
        elif self.tileType is None or self.tileType.schema is None:
            data = self.tile.request.form.copy()
        else:
            # Try to decode the form data properly if we can
            try:
                data = decode(self.tile.request.form,
                              self.tileType.schema,
                              missing=True)
            except (
                    ValueError,
                    UnicodeDecodeError,
            ):
                LOGGER.exception(u'Could not convert form data to schema')
                return self.data.copy()
        # we're assuming this data is potentially unsafe so we need to check
        # the ignore querystring field setting

        # before we start, we allow it for sub-requests since in this case,
        # the input is safe and we can trust it
        if ISubRequest.providedBy(self.tile.request):
            return data

        # first off, we only care to filter if it is a GET request
        if getattr(self.tile.request, 'REQUEST_METHOD', 'GET') != 'GET':
            return data

        # now, pay attention to schema hints for form data
        if self.tileType is not None and self.tileType.schema is not None:
            for name in self.tileType.schema.queryTaggedValue(
                    IGNORE_QUERYSTRING_KEY) or []:
                if name in data:
                    del data[name]

        return data
Beispiel #9
0
    def get_default_request_data(self):
        """
        from request form
        """
        # try to use a '_tiledata' parameter in the request
        if '_tiledata' in self.tile.request.form:
            data = json.loads(self.tile.request.form['_tiledata'])
        elif self.tileType is None or self.tileType.schema is None:
            data = self.tile.request.form.copy()
        else:
            # Try to decode the form data properly if we can
            try:
                data = decode(self.tile.request.form,
                              self.tileType.schema,
                              missing=True, primary=True)
            except (ValueError, UnicodeDecodeError,):
                LOGGER.exception(u'Could not convert form data to schema')
                return self.data.copy()
        # we're assuming this data is potentially unsafe so we need to check
        # the ignore querystring field setting

        # before we start, we allow it for sub-requests since in this case,
        # the input is safe and we can trust it
        if ISubRequest.providedBy(self.tile.request):
            return data

        # first off, we only care to filter if it is a GET request
        if getattr(self.tile.request, 'REQUEST_METHOD', 'GET') != 'GET':
            return data

        # now, pay attention to schema hints for form data
        if self.tileType is not None and self.tileType.schema is not None:
            for name in self.tileType.schema.queryTaggedValue(
                    IGNORE_QUERYSTRING_KEY) or []:
                if name in data:
                    del data[name]

        return data