Ejemplo n.º 1
0
    def __call__(self, request, elements, kw):
        if self.subdomain and "subdomain" in kw:
            if "subdomain_url_template" in request.registry.settings:
                subdomain_url_template = \
                    request.registry.settings["subdomain_url_template"]
            else:
                subdomain_url_template = "http://%(sub)s.%(host)s"

            kw["_app_url"] = subdomain_url_template % {
                "sub": kw["subdomain"],
                "host": request.host,
            } + request.script_name

        query = kw.get("_query", {})

        if self.version:
            from c2cgeoportal.lib.cacheversion import get_cache_version
            query["cache_version"] = get_cache_version()

        if self.role and request.user:
            # The templates change if the user is logged in or not. Usually it is
            # the role that is making a difference, but the username is put in
            # some JS files. So we add the username to hit different cache entries.
            query["username"] = request.user.username

        kw["_query"] = query
        return elements, kw
Ejemplo n.º 2
0
    def __call__(self, request, elements, kw):
        if self.subdomain and "subdomain" in kw:
            if "subdomain_url_template" in request.registry.settings:
                subdomain_url_template = \
                    request.registry.settings["subdomain_url_template"]
            else:
                subdomain_url_template = "http://%(sub)s.%(host)s"

            kw["_app_url"] = subdomain_url_template % {
                "sub": kw["subdomain"],
                "host": request.host,
            } + request.script_name

        query = kw.get("_query", {})

        if self.version:
            from c2cgeoportal.lib.cacheversion import get_cache_version
            query["cache_version"] = get_cache_version()

        if self.role and request.user:
            # The templates change if the user is logged in or not. Usually it is
            # the role that is making a difference, but the username is put in
            # some JS files. So we add the username to hit different cache entries.
            query["username"] = request.user.username

        kw["_query"] = query
        return elements, kw
Ejemplo n.º 3
0
    def get_cgxp_viewer_vars(self):
        role_id = None if self.request.user is None or self.request.user.role is None else \
            self.request.user.role.id

        interface = self.request.interface_name

        themes, errors = self._themes(role_id, interface)
        wfs_types, add_errors = self._internal_wfs_types(role_id)
        errors |= add_errors
        external_wfs_types, add_errors = self._external_wfs_types(role_id)
        errors |= add_errors
        external_themes, add_errors = self._external_themes(interface)
        errors |= add_errors

        cache_version = get_cache_version()
        url_params = {
            'version': cache_version
        }
        url_role_params = {
            'version': cache_version
        }
        if self.request.user is not None and self.request.user.role is not None:
            url_role_params['role'] = self.request.user.role.name

        d = {
            'themes': json.dumps(themes),
            'user': self.request.user,
            'WFSTypes': json.dumps(wfs_types),
            'externalWFSTypes': json.dumps(external_wfs_types),
            'external_themes': external_themes,
            'tiles_url': json.dumps(self.settings.get("tiles_url")),
            'functionality': self._functionality(),
            'queryer_attribute_urls': json.dumps(self._get_layers_enum()),
            'url_params': url_params,
            'url_role_params': url_role_params,
            'serverError': json.dumps(list(errors)),
        }

        # handle permalink_themes
        permalink_themes = self.request.params.get('permalink_themes')
        if permalink_themes:
            d['permalink_themes'] = json.dumps(permalink_themes.split(','))

        d['lang'] = self.lang
        d['debug'] = self.debug

        self.request.response.content_type = 'application/javascript'
        self.request.response.headers["Vary"] = "Accept-Language"
        return d
Ejemplo n.º 4
0
    def get_cgxp_viewer_vars(self):
        role_id = None if self.request.user is None or self.request.user.role is None else \
            self.request.user.role.id

        interface = self.request.interface_name

        themes, errors = self._themes(role_id, interface)
        wfs_types, add_errors = self._internal_wfs_types(role_id)
        errors |= add_errors
        external_wfs_types, add_errors = self._external_wfs_types(role_id)
        errors |= add_errors
        external_themes, add_errors = self._external_themes(interface)
        errors |= add_errors

        version_role_params = {
            "cache_version": get_cache_version()
        }

        d = {
            "lang": self.lang,
            "debug": self.debug,
            "themes": json.dumps(themes),
            "user": self.request.user,
            "WFSTypes": json.dumps(wfs_types),
            "externalWFSTypes": json.dumps(external_wfs_types),
            "external_themes": external_themes,
            "tiles_url": json.dumps(self.settings.get("tiles_url")),
            "functionality": self._functionality(),
            "queryer_attribute_urls": json.dumps(self._get_layers_enum()),
            "serverError": json.dumps(list(errors)),
            "version_role_params": version_role_params
        }

        # handle permalink_themes
        permalink_themes = self.request.params.get("permalink_themes")
        if permalink_themes:
            d["permalink_themes"] = json.dumps(permalink_themes.split(","))

        set_common_headers(
            self.request, "cgxp_viewer", PRIVATE_CACHE,
            vary=True, content_type="application/javascript",
        )

        return d
Ejemplo n.º 5
0
    def get_ngeo_index_vars(self, vars={}):
        self.request.response.headers['Cache-Control'] = 'no-cache'

        url_params = {
            'version': get_cache_version()
        }

        if self.request.user is not None:  # pragma: nocover
            # For the cache
            url_params['role'] = self.request.user.role.name

        vars.update({
            'debug': self.debug,
            'url_params': url_params,
            'user': self.request.user,
            'functionality': self._functionality(),
            'queryer_attribute_urls': self._get_layers_enum(),
        })
        return vars
Ejemplo n.º 6
0
    def get_cgxp_index_vars(self, templates_params=None):
        cache_version = get_cache_version()
        extra_params = {
            'version': cache_version
        }
        url_params = {
            'version': cache_version
        }
        if self.lang:
            extra_params['lang'] = self.lang

        d = {
            'lang': self.lang,
            'debug': self.debug,
            'url_params': url_params,
            'extra_params': extra_params
        }

        if self.request.user is not None:
            d['extra_params']['user'] = self.request.user.username.encode('utf-8')

        # general templates_params handling
        if templates_params is not None:
            d.update(templates_params)

        # specific permalink_themes handling
        if 'permalink_themes' in d:
            extra_params['permalink_themes'] = d['permalink_themes']

        # check if route to mobile app exists
        try:
            d['mobile_url'] = self.request.route_url('mobile_index_prod')
        except:  # pragma: no cover
            d['mobile_url'] = None

        d['no_redirect'] = self.request.params.get('no_redirect') is not None
        self.request.response.headers["Cache-Control"] = "no-cache"
        self.request.response.headers["Vary"] = "Accept-Language"

        return d
Ejemplo n.º 7
0
    def mobile(self):
        """
        View callable for the mobile application's index.html file.
        """
        self.request.response.headers['Cache-Control'] = 'no-cache'

        extra_params = dict(self.request.params)
        came_from = self.request.current_route_url(_query=extra_params)
        cache_version = get_cache_version()
        url_params = {
            'cache_version': cache_version
        }
        extra_params['cache_version'] = cache_version

        def enc(vals):
            return (vals[0], vals[1].encode('utf8'))
        self.request.response.headers["Vary"] = "Accept-Language"
        return {
            'lang': self.lang,
            'came_from': came_from,
            'url_params': urllib.urlencode(dict(map(enc, url_params.items()))),
            'extra_params': urllib.urlencode(dict(map(enc, extra_params.items()))),
        }
Ejemplo n.º 8
0
    def __call__(self, request, elements, kw):
        if self.subdomain and "subdomain" in kw:
            if "subdomain_url_template" in request.registry.settings:
                subdomain_url_template = \
                    request.registry.settings["subdomain_url_template"]
            else:
                subdomain_url_template = "http://%(sub)s.%(host)s"

            kw["_app_url"] = subdomain_url_template % {
                "sub": kw["subdomain"],
                "host": request.host,
            } + request.script_name

        query = kw.get("_query", {})

        if self.version:
            from c2cgeoportal.lib.cacheversion import get_cache_version
            query["cache_version"] = get_cache_version()

        if self.role and request.user and request.user.role:
            query["role"] = request.user.role.id

        kw["_query"] = query
        return elements, kw
Ejemplo n.º 9
0
    def __call__(self, request, elements, kw):
        if self.subdomain and "subdomain" in kw:
            if "subdomain_url_template" in request.registry.settings:
                subdomain_url_template = \
                    request.registry.settings["subdomain_url_template"]
            else:
                subdomain_url_template = "http://%(sub)s.%(host)s"

            kw["_app_url"] = subdomain_url_template % {
                "sub": kw["subdomain"],
                "host": request.host,
            } + request.script_name

        query = kw.get("_query", {})

        if self.version:
            from c2cgeoportal.lib.cacheversion import get_cache_version
            query["cache_version"] = get_cache_version()

        if self.role and request.user and request.user.role:
            query["role"] = request.user.role.id

        kw["_query"] = query
        return elements, kw
Ejemplo n.º 10
0
    def mobile(self):
        """
        View callable for the mobile application's index.html file.
        """
        set_common_headers(self.request, "sencha_index", NO_CACHE)

        extra_params = dict(self.request.params)
        came_from = self.request.current_route_url(_query=extra_params)
        cache_version = get_cache_version()
        url_params = {
            "cache_version": cache_version
        }
        extra_params["cache_version"] = cache_version
        if self.request.user is not None:
            extra_params["role"] = self.request.user.role.name

        def enc(vals):
            return (vals[0], vals[1].encode("utf8"))
        return {
            "lang": self.lang,
            "came_from": came_from,
            "url_params": urllib.urlencode(dict(map(enc, url_params.items()))),
            "extra_params": urllib.urlencode(dict(map(enc, extra_params.items()))),
        }