コード例 #1
0
    def lux_report_create(self):
        resp, content = self._proxy("%s/report.%s" % (
            self.config["print_url"],
            self.request.matchdict.get("format")
        ))

        job = LuxPrintJob()
        job.id = json.loads(content)["ref"]
        job.spec = self.request.body
        job.creation = datetime.now()
        DBSession.add(job)

        return self._build_response(
            resp, content, False, "print"
        )
コード例 #2
0
    def lux_report_create(self):
        resp, content = self._proxy(
            "%s/report.%s" %
            (self.config["print_url"], self.request.matchdict.get("format")))

        spec = json.loads(self.request.body)
        for map_layer in spec["attributes"]["map"]["layers"]:
            if "baseURL" in map_layer and\
               "ogcproxywms" in map_layer["baseURL"]:
                for layer in map_layer["layers"]:
                    internal_wms = DBSession.query(LuxLayerInternalWMS).filter(
                        LuxLayerInternalWMS.layer == layer).first()
                    if internal_wms is not None and\
                       not self._is_authorized(internal_wms):
                        return HTTPUnauthorized()
        job = LuxPrintJob()
        job.id = json.loads(content)["ref"]
        job.spec = self.request.body
        job.creation = datetime.now()
        DBSession.add(job)
        return self._build_response(resp, content, False, "print")
コード例 #3
0
    def lux_report_create(self):
        token = self.config["authtkt_secret"]
        print_servers = DBSession.query(LuxPrintServers).all()
        print_urls = [print_server.url for print_server in print_servers]
        urllib2.getproxies = lambda: {}
        valid_print_urls = []
        if print_urls is not None and len(print_urls) > 0:
            for url in print_urls:
                try:
                    test_url = url.replace("/print/geoportailv3", "")
                    urllib2.urlopen(test_url)
                    valid_print_urls.append(url)
                except Exception as e:
                    log.exception(e)
                    log.error("Print server not available : " + url)
            print_url = valid_print_urls[random.randint(
                0,
                len(valid_print_urls) - 1)]
        else:
            print_url = self.config["print_url"]

        spec = json.loads(self.request.body)
        for map_layer in spec["attributes"]["map"]["layers"]:
            if "baseURL" in map_layer and\
               "ogcproxywms" in map_layer["baseURL"]:
                if "customParams" in map_layer:
                    map_layer["customParams"]["GP_TOKEN"] = token
                else:
                    map_layer["customParams"] = {"GP_TOKEN": token}
                if self.request.user and\
                   self.request.user.ogc_role is not None and\
                   self.request.user.ogc_role != -1:
                    if "customParams" in map_layer:
                        map_layer["customParams"]["roleOGC"] =\
                            str(self.request.user.ogc_role)
                    else:
                        map_layer["customParams"] =\
                            {"roleOGC": str(self.request.user.ogc_role)}

                for layer in map_layer["layers"]:
                    internal_wms = DBSession.query(LuxLayerInternalWMS).filter(
                        LuxLayerInternalWMS.layer == layer).first()
                    if internal_wms is not None and\
                       not self._is_authorized(internal_wms):
                        return HTTPUnauthorized()
        if "longUrl" in spec["attributes"]:
            opener = urllib2.build_opener(urllib2.HTTPHandler())
            data = urllib.urlencode({"url": spec["attributes"]["longUrl"]})
            content = opener.open(
                "https://map.geoportail.lu/wsgi/short/create",
                data=data).read()
            shortner = json.loads(content)
            spec["attributes"]["url"] = shortner["short_url"]
            spec["attributes"]["qrimage"] =\
                "https://map.geoportail.lu/main/wsgi/qr?url=" + \
                spec["attributes"]["url"]

        job = LuxPrintJob()
        job.spec = json.dumps(spec)
        self.request.body = job.spec

        resp, content = self._proxy(
            "%s/report.%s" % (print_url, self.request.matchdict.get("format")))
        job.id = json.loads(content)["ref"]
        job.print_url = print_url
        job.creation = datetime.now()
        DBSession.add(job)
        return self._build_response(resp, content, False, "print")
コード例 #4
0
    def lux_report_create(self):
        token = self.config["authtkt_secret"]
        print_servers = DBSession.query(LuxPrintServers).all()
        print_urls = [print_server.url for print_server in print_servers]
        urllib2.getproxies = lambda: {}
        valid_print_urls = []
        if print_urls is not None and len(print_urls) > 0:
            for url in print_urls:
                try:
                    test_url = url.replace("/print/geoportailv3", "")
                    urllib2.urlopen(test_url)
                    valid_print_urls.append(url)
                except Exception as e:
                    log.exception(e)
                    log.error("Print server not available : " + url)
            print_url = valid_print_urls[random.randint(0,
                                         len(valid_print_urls) - 1)]
        else:
            print_url = self.config["print_url"]

        spec = json.loads(self.request.body)
        for map_layer in spec["attributes"]["map"]["layers"]:
            if "baseURL" in map_layer and\
               "ogcproxywms" in map_layer["baseURL"]:
                if "customParams" in map_layer:
                    map_layer["customParams"]["GP_TOKEN"] = token
                else:
                    map_layer["customParams"] = {"GP_TOKEN": token}
                if self.request.user and\
                   self.request.user.ogc_role is not None and\
                   self.request.user.ogc_role != -1:
                    if "customParams" in map_layer:
                        map_layer["customParams"]["roleOGC"] =\
                            str(self.request.user.ogc_role)
                    else:
                        map_layer["customParams"] =\
                            {"roleOGC": str(self.request.user.ogc_role)}

                for layer in map_layer["layers"]:
                    internal_wms = DBSession.query(LuxLayerInternalWMS).filter(
                        LuxLayerInternalWMS.layer == layer).first()
                    if internal_wms is not None and\
                       not self._is_authorized(internal_wms):
                            return HTTPUnauthorized()
        if "longUrl" in spec["attributes"]:
            opener = urllib2.build_opener(urllib2.HTTPHandler())
            data = urllib.urlencode({"url": spec["attributes"]["longUrl"]})
            content = opener.open(
                "https://map.geoportail.lu/wsgi/short/create",
                data=data).read()
            shortner = json.loads(content)
            spec["attributes"]["url"] = shortner["short_url"]
            spec["attributes"]["qrimage"] =\
                "https://map.geoportail.lu/main/wsgi/qr?url=" + \
                spec["attributes"]["url"]

        job = LuxPrintJob()
        job.spec = json.dumps(spec)
        self.request.body = job.spec

        resp, content = self._proxy("%s/report.%s" % (
            print_url,
            self.request.matchdict.get("format")
        ))
        job.id = json.loads(content)["ref"]
        job.print_url = print_url
        job.creation = datetime.now()
        DBSession.add(job)
        return self._build_response(
            resp, content, False, "print"
        )