def lux_report_get(self): ref = self.request.matchdict.get("ref") resp, content = self._proxy("%s/report/%s" % (self.config["print_url"], ref)) job = DBSession.query(LuxPrintJob).get( self.request.matchdict.get("ref")) attributes = json.loads(job.spec)["attributes"] if "legend" in attributes and attributes["legend"] is not None: merger = PdfFileMerger() merger.append(StringIO(content)) lang = attributes.get("lang") for item in attributes["legend"]: merger.append(self._get_legend(item["name"], lang)) content = StringIO() merger.write(content) content = content.getvalue() DBSession.delete(job) resp["content-disposition"] =\ "attachment; filename=map_geoportal_lu.pdf" return self._build_response(resp, content, NO_CACHE, "print")
def lux_report_get(self): ref = self.request.matchdict.get("ref") resp, content = self._proxy("%s/report/%s" % ( self.config["print_url"], ref )) job = DBSession.query(LuxPrintJob).get( self.request.matchdict.get("ref") ) attributes = json.loads(job.spec)["attributes"] if "legend" in attributes and attributes["legend"] is not None: merger = PdfFileMerger() merger.append(StringIO(content)) lang = attributes.get("lang") for item in attributes["legend"]: merger.append(self._get_legend(item["name"], lang)) content = StringIO() merger.write(content) content = content.getvalue() DBSession.delete(job) return self._build_response( resp, content, NO_CACHE, "print" )
def lux_report_get(self): ref = self.request.matchdict.get("ref") job = DBSession.query(LuxPrintJob).get(ref) if job is None: return HTTPNotFound() try: resp, content = self._proxy("%s/report/%s" % (job.print_url, ref)) attributes = json.loads(job.spec)["attributes"] is_pdf = json.loads(job.spec)["format"] == "pdf" print_title = attributes.get("name") if print_title is None or len(print_title) == 0: print_title = "map_geoportal_lu" print_title = re.sub(r" ", "_", print_title) print_title = re.sub(r"[^a-zA-Z0-9\-\_]", "", print_title) if is_pdf and "firstPagesUrls" in attributes and\ attributes["firstPagesUrls"] is not None and\ len(attributes["firstPagesUrls"]) > 0: attributes["firstPagesUrls"].reverse() for pageUrl in attributes["firstPagesUrls"]: try: merger = PdfFileMerger(strict=False) if pageUrl['type'].lower() == 'pdf': opener = urllib2.build_opener( urllib2.HTTPHandler()) pdf_content = opener.open(pageUrl['url']).read() merger.append(StringIO(pdf_content)) else: first_page = StringIO() weasyprint.HTML( pageUrl['url']).write_pdf(first_page) merger.append(first_page) merger.append(StringIO(content)) content = StringIO() merger.write(content) content = content.getvalue() except Exception as e: log.exception(e) if is_pdf and "legend" in attributes and\ attributes["legend"] is not None: merger = PdfFileMerger(strict=False) merger.append(StringIO(content)) lang = attributes.get("lang") for item in attributes["legend"]: if "legendUrl" in item and item["legendUrl"] is not None: legend_title = "" if "legendTitle" in item and\ item["legendTitle"] is not None: legend_title = item["legendTitle"] access_constraints = "" if "accessConstraints" in item and\ item["accessConstraints"] is not None: access_constraints = item["accessConstraints"] merger.append( self._create_legend_from_image( item["legendUrl"], legend_title, access_constraints)) elif "name" in item and item["name"] is not None: merger.append(self._get_legend(item["name"], lang)) content = StringIO() merger.write(content) content = content.getvalue() if is_pdf and "queryResults" in attributes and\ attributes["queryResults"] is not None: css = weasyprint.CSS( string=".ng-hide {display: none !important;} " + ".no-print {display: none !important;} " + "body {font-size: 60%;} " + ".route-details-step { font-family: " + "Arial,sans-serif; font-size: 14px; " + "line-height: 20px; border-bottom: 1px " + "solid #8394A0; padding: 10px 10px 10px 30px; " + "margin: 0 -12px 0 0; position: relative;} " + ".route-info-title {font-size: 18px; " + "line-height: 19px; font-weight: 700;} " + ".route-general-info-container {display: " + "table; width: 100%;} " + ".route-single-info {display: table-cell; " + "width: auto;} " + ".route-info-general-data {font-size: 18px; " + "font-weight: 700; line-height: 22px; " + "padding-top: 10px;} " + ".route-info-data {color: #8394A0;} " + ".route-instruction-data {font-size: 16px; " + "line-height: 19px; display: inline-block; " + "margin: 0 10px 0 0;} " + ".route-instruction {margin-bottom: 10px;" + "position: relative;} " + ".icon-Direction {position: absolute; top: 0;" + "right: 100%; margin-right: 6px;} " + ".icon-Direction:before {font-family: " + "apart-geoportail!important;content: '\e903';" + "font-size: 6px;color:'#000';} " + ".south {transform: rotate(90deg);} " + ".north {transform: rotate(270deg);} " + ".west {transform: rotate(180deg);} " + ".east {transform: rotate(0deg);} " + ".n-e {transform: rotate(315deg);} " + ".n-w {transform: rotate(225deg);} " + ".s-w {transform: rotate(135deg);} " + ".s-e {transform: rotate(45deg);} ") merger = PdfFileMerger(strict=False) merger.append(StringIO(content)) query_results = StringIO() weasyprint.HTML(string=attributes["queryResults"]).write_pdf( query_results, stylesheets=[css]) merger.append(query_results) content = StringIO() merger.write(content) content = content.getvalue() DBSession.delete(job) if is_pdf: resp["content-disposition"] =\ "attachment; filename=%s.pdf" % (str(print_title)) else: resp["content-disposition"] =\ "attachment; filename=%s.png" % (str(print_title)) return self._build_response(resp, content, NO_CACHE, "print") except Exception as e: log.exception(e) log.error("reference is : " + ref) if job is not None: job.is_error = True return HTTPInternalServerError()
def lux_report_get(self): ref = self.request.matchdict.get("ref") job = DBSession.query(LuxPrintJob).get(ref) if job is None: return HTTPNotFound() try: resp, content = self._proxy("%s/report/%s" % ( job.print_url, ref )) attributes = json.loads(job.spec)["attributes"] is_pdf = json.loads(job.spec)["format"] == "pdf" print_title = attributes.get("name") if print_title is None or len(print_title) == 0: print_title = "map_geoportal_lu" print_title = re.sub(r" ", "_", print_title) print_title = re.sub(r"[^a-zA-Z0-9\-\_]", "", print_title) if is_pdf and "firstPagesUrls" in attributes and\ attributes["firstPagesUrls"] is not None and\ len(attributes["firstPagesUrls"]) > 0: attributes["firstPagesUrls"].reverse() for page_url in attributes["firstPagesUrls"]: try: merger = PdfFileMerger(strict=False) if page_url['type'].lower() == 'pdf': opener = urllib2.build_opener( urllib2.HTTPHandler()) pdf_content = opener.open(page_url['url']).read() merger.append(StringIO(pdf_content)) else: first_page = StringIO() weasyprint.HTML(page_url['url']).write_pdf( first_page ) merger.append(first_page) merger.append(StringIO(content)) content = StringIO() merger.write(content) content = content.getvalue() except Exception as e: log.exception(e) if is_pdf and "legend" in attributes and\ attributes["legend"] is not None: merger = PdfFileMerger(strict=False) merger.append(StringIO(content)) lang = attributes.get("lang") for item in attributes["legend"]: if "legendUrl" in item and item["legendUrl"] is not None: legend_title = "" if "legendTitle" in item and\ item["legendTitle"] is not None: legend_title = item["legendTitle"] access_constraints = "" if "accessConstraints" in item and\ item["accessConstraints"] is not None: access_constraints = item["accessConstraints"] merger.append( self._create_legend_from_image( item["legendUrl"], legend_title, access_constraints)) elif "name" in item and item["name"] is not None: merger.append(self._get_legend(item["name"], lang)) content = StringIO() merger.write(content) content = content.getvalue() if is_pdf and "queryResults" in attributes and\ attributes["queryResults"] is not None: css = weasyprint.CSS( string=".ng-hide {display: none !important;} " + ".no-print {display: none !important;} " + "body {font-size: 60%;} " + ".route-details-step { font-family: " + "Arial,sans-serif; font-size: 14px; " + "line-height: 20px; border-bottom: 1px " + "solid #8394A0; padding: 10px 10px 10px 30px; " + "margin: 0 -12px 0 0; position: relative;} " + ".route-info-title {font-size: 18px; " + "line-height: 19px; font-weight: 700;} " + ".route-general-info-container {display: " + "table; width: 100%;} " + ".route-single-info {display: table-cell; " + "width: auto;} " + ".route-info-general-data {font-size: 18px; " + "font-weight: 700; line-height: 22px; " + "padding-top: 10px;} " + ".route-info-data {color: #8394A0;} " + ".route-instruction-data {font-size: 16px; " + "line-height: 19px; display: inline-block; " + "margin: 0 10px 0 0;} " + ".route-instruction {margin-bottom: 10px;" + "position: relative;} " + ".icon-Direction {position: absolute; top: 0;" + "right: 100%; margin-right: 6px;} " + ".icon-Direction:before {font-family: " + "apart-geoportail!important;content: '\e903';" + "font-size: 6px;color:'#000';} " + ".south {transform: rotate(90deg);} " + ".north {transform: rotate(270deg);} " + ".west {transform: rotate(180deg);} " + ".east {transform: rotate(0deg);} " + ".n-e {transform: rotate(315deg);} " + ".n-w {transform: rotate(225deg);} " + ".s-w {transform: rotate(135deg);} " + ".s-e {transform: rotate(45deg);} " ) merger = PdfFileMerger(strict=False) merger.append(StringIO(content)) query_results = StringIO() weasyprint.HTML(string=attributes["queryResults"]).write_pdf( query_results, stylesheets=[css] ) merger.append(query_results) content = StringIO() merger.write(content) content = content.getvalue() DBSession.delete(job) if is_pdf: resp["content-disposition"] =\ "attachment; filename=%s.pdf" % (str(print_title)) else: resp["content-disposition"] =\ "attachment; filename=%s.png" % (str(print_title)) return self._build_response( resp, content, NO_CACHE, "print" ) except Exception as e: log.exception(e) log.error("reference is : " + ref) if job is not None: job.is_error = True return HTTPInternalServerError()