def pdf_proxy(request): mapper = { 'mutation': VPlanMut } if 'code' in request.params: code = request.params['code'] else: return HTTPNotFound() if code and code != request.registry.settings['intranet_code']: return HTTPNotFound() type = request.matchdict['type'] id_folio = int(request.matchdict['id']) db_filepath = DBSession.query(mapper[type]).get(id_folio) db_filepath = db_filepath.chemin_desi log.info("Get pdf mutation with id = %s." % id_folio) file = os.path.join(request.registry.settings['image_server_mutation'], db_filepath) fileName, fileExtension = os.path.splitext(file) return FileResponse( file, request = request, content_type = 'application/pdf' )
def get_user_from_request(request): """ Return the User object for the request. Return ``None`` if: * user is anonymous * it does not exist in the database * the referer is invalid """ from historic_cadastre.models import DBSession, AuthenticationUser if not hasattr(request, "_user"): request._user = None username = request.authenticated_userid if username is not None: username = username.lower() # We know we will need the role object of the # user so we use joined loading user = DBSession.query(AuthenticationUser) \ .filter_by(username=username) \ .first() if user is not None: headers = remember(request, user.username) request.response.headerlist.extend(headers) request._user = user return request._user
def pdf_proxy(request): mapper = { 'mutation': VPlanMut, 'histoparcel': HistoricParcelDoc } type = request.matchdict['type'] id_folio = int(request.matchdict['id']) db_filepath = DBSession.query(mapper[type]).get(id_folio) db_filepath = db_filepath.chemin_desi log.info("Get pdf mutation with id = %s." % id_folio) file = os.path.join(request.registry.settings['image_server_mutation'], db_filepath) fileName, fileExtension = os.path.splitext(file) return FileResponse( file, request = request, content_type = 'application/pdf' )
def image_proxy(request): mapper = { 'graphique': VPlanGraphique, 'servitude': Servitude, 'cadastre_graphique': CadastreGraphique, 'distribution': VPlanDistr, 'mutation': VPlanMut } type = request.matchdict['type'] if type == 'graphique': id_img = int(request.matchdict['id']) else: id_img = request.matchdict['id'] code = None if 'code' in request.params: code = request.params['code'] is_intranet = False if code and code == request.registry.settings['intranet_code']: is_intranet = True db_filepath = DBSession.query(mapper[type]).get(id_img) if db_filepath.is_internet is False and is_intranet is False: return HTTPNotFound() db_filepath = db_filepath.chemin_cad if type == 'graphique' or type == 'distribution': registry_string = 'image_server_graphique' elif type == 'mutation': registry_string = 'image_server_mutation' elif type == 'servitude': registry_string = 'image_server_servitudes' elif type == 'cadastre_graphique': registry_string = 'image_server_cadastre_graphique' log.info("Get image with id = %s." % id_img) file = os.path.join(request.registry.settings[registry_string], db_filepath) fileName, fileExtension = os.path.splitext(file) extension = { '.jpg': 'image/jpg', '.jpeg': 'image/jpg', '.png': 'image/png', '.tif': 'image/tif', '.tiff': 'image/tif', } return FileResponse(file, request=request, content_type=extension[fileExtension.lower()])
def image_proxy(request): mapping_conf = request.registry.settings['type_configuration'] type = request.matchdict['type'] mapper = mapping_conf[type] pass_through = True if mapper['public'] is False: pass_through = check_rights(request, type) if pass_through is False: return HTTPForbidden() mapped_class = mapped_classes_registry[mapper['table']] img_base_path = mapper['image_server'] if type == 'graphique': id_img = int(request.matchdict['id']) else: id_img = request.matchdict['id'] db_filepath = DBSession.query(mapped_class).get(id_img) db_filepath = db_filepath.chemin_cad log.info("Get image with id = %s." % id_img) file = os.path.join(img_base_path, db_filepath) fileName, fileExtension = os.path.splitext(file) extension = { '.jpg': 'image/jpg', '.jpeg': 'image/jpg', '.png': 'image/png', '.tif': 'image/tif', '.tiff': 'image/tif', } return FileResponse( file, request=request, content_type=extension[fileExtension.lower()] )
def image_proxy(request): mapper = { 'graphique': VPlanGraphique, 'servitude': Servitude, 'cadastre_graphique': CadastreGraphique, 'distribution': VPlanDistr, 'mutation': VPlanMut } type = request.matchdict['type'] if type == 'graphique': id_img = int(request.matchdict['id']) else: id_img = request.matchdict['id'] code = None if 'code' in request.params: code = request.params['code'] is_intranet = False if code and code == request.registry.settings['intranet_code']: is_intranet = True db_filepath = DBSession.query(mapper[type]).get(id_img) if db_filepath.is_internet is False and is_intranet is False: return HTTPNotFound() db_filepath = db_filepath.chemin_cad if type == 'graphique' or type == 'distribution': registry_string = 'image_server_graphique' elif type == 'mutation': registry_string = 'image_server_mutation' elif type == 'servitude': registry_string = 'image_server_servitudes' elif type == 'cadastre_graphique': registry_string = 'image_server_cadastre_graphique' log.info("Get image with id = %s." % id_img) file = os.path.join(request.registry.settings[registry_string], db_filepath) fileName, fileExtension = os.path.splitext(file) extension = { '.jpg': 'image/jpg', '.jpeg': 'image/jpg', '.png': 'image/png', '.tif': 'image/tif', '.tiff': 'image/tif', } return FileResponse( file, request = request, content_type = extension[fileExtension.lower()] )
def viewer(self): mapper = { 'graphique': VPlanGraphique, 'servitude': Servitude, 'cadastre_graphique': CadastreGraphique, 'distribution': VPlanDistr, 'mutation': VPlanMut } type_plan = { 'o': u'original', 'm': u'muté', 'r': u'remanié', 'c': u'copié' } id_plan = self.request.params['id_plan'] code = None if 'code' in self.request.params: code = self.request.params['code'] type_ = self.request.params['type'] mapped_class = mapper[type_] params = DBSession.query(mapped_class).get(id_plan) plan_url = self.request.route_url('image_proxy', type=type_, id=id_plan) if code: plan_url += '?code=' + code self.request.response.content_type = 'application/javascript' type_plan_ = None if 'type_plan' in params.__table__.c.keys(): if params.type_plan[0:1] in type_plan.keys(): type_plan_ = type_plan[params.type_plan[0:1]] else: type_plan_ = params.type_plan if params.echelle: echelle = params.echelle else: echelle = None if type_ == 'servitude' or type_ == 'cadastre_graphique': list_folio = params.id_plan.split('_') nom_folio = list_folio[2] else: if params.nom_plan: list_folio = params.nom_plan.split('_') nom_folio = list_folio[1] return { 'debug': self.debug, 'id_plan': id_plan, 'nom_folio':nom_folio, 'plan_largeur': params.larg, 'plan_hauteur': params.haut, 'plan_resolution': params.resol, 'plan_url': plan_url, 'nomcad': params.cadastre, 'no_plan': params.plan, 'type_plan': type_plan_, 'echelle': echelle, 'type_': type_ }
def mutation_list(request): if 'id' in request.params: id = request.params['id'] else: return HTTPNotFound() debug = False if 'debug' in request.params: debug = True list = [] qq = DBSession.query(VPlanMut).filter(VPlanMut.id_cad_geom==int(id)).order_by(VPlanMut.plan) results = qq.all() for result in results: date_plan = result.date_plan if date_plan: date_plan = dateToString(date_plan) else: date_plan = '' date_acte = result.date_acte if date_acte: date_acte = dateToString(date_acte) else: date_acte = '' date_depot = result.date_depot if date_depot: date_depot = dateToString(date_depot) else: date_depot = '' req_bidon = result.req_bidon if req_bidon: req_bidon = 'oui' else: req_bidon = 'non' cut_plan = result.nom_plan list_cut = cut_plan.split('_') nom_plan = list_cut[1] list.append({ 'id': result.id_folio, 'cadastre': result.cadastre, 'nom_plan': nom_plan, 'plan': result.plan, 'indice': result.indice, 'folio': result.folio, 'req_tot': result.req_tot, 'req_bidon': req_bidon, 'date_plan': date_plan, 'date_acte': date_acte, 'date_depot': date_depot, 'chemin_desi': result.chemin_desi }) return {'list': list, 'debug':debug}
def viewer(self): mapping_conf = self.request.registry.settings['type_configuration'] type_plan = { 'o': u'original', 'm': u'muté', 'rp': u'remanié', 'c': u'copié', 't': u'minute', 'p': u'plaque alu', 'n': u'minute remaniée', 'b': u'minute copiée' } id_plan = self.request.params['id_plan'] type_ = self.request.params['type'] mapper = mapping_conf[type_] pass_through = True if mapper['public'] is False: pass_through = check_rights(self.request, type_) if pass_through is False: return HTTPForbidden() mapped_class = mapped_classes_registry[mapper['table']] params = DBSession.query(mapped_class).get(id_plan) plan_url = self.request.route_url('image_proxy', type=type_, id=id_plan) self.request.response.content_type = 'application/javascript' type_plan_ = None if 'type_plan' in params.__table__.c.keys(): if params.type_plan[0:1] in type_plan.keys(): type_plan_ = type_plan[params.type_plan[0:1]] else: type_plan_ = params.type_plan if hasattr(params, 'echelle') and params.echelle is not None: echelle = params.echelle else: echelle = None list_folio = None nom_folio = None cadastre = None plan = None num_dossier = None nom_liste_tech = None district = None if type_ == 'servitude' or type_ == 'cadastre_graphique': list_folio = params.id_plan.split('_') nom_folio = list_folio[2] else: if hasattr(params, 'nom_plan') is True and hasattr(params, 'folio') is True: list_folio = params.nom_plan.split('_') nom_folio = list_folio[1] if nom_folio == '0': nom_folio = params.folio if hasattr(params, 'cadastre') is True: cadastre = params.cadastre if hasattr(params, 'plan') is True: plan = params.plan if hasattr(params, 'num_dossier') is True: num_dossier = params.num_dossier if hasattr(params, 'nom_liste_tech') is True: nom_liste_tech = params.nom_liste_tech if hasattr(params, 'district') is True: district = params.district return { 'debug': self.debug, 'id_plan': id_plan, 'nom_folio': nom_folio, 'plan_largeur': params.larg, 'plan_hauteur': params.haut, 'plan_resolution': params.resol, 'plan_url': plan_url, 'nomcad': cadastre, 'no_plan': plan, 'type_plan': type_plan_, 'echelle': echelle, 'type_': type_, 'district': district, 'nom_liste_tech': nom_liste_tech, 'num_dossier': num_dossier, }
def historic_parcel_get(request): id_ = request.matchdict['id'] results = DBSession.query(HistoricParcelTree).filter(HistoricParcelTree.imm_dest == id_) results = results.all() base_route = request.route_url('historic_parcel') base_route_doc = request.route_url('historic_parcel_doc') if results: root = id_ origine = '' doc = base_route_doc + '?id=' + root value = '' else: results2 = DBSession.query(HistoricParcelTree).filter(HistoricParcelTree.imm_source == id_) results2 = results2.first() root = id_ doc = base_route_doc + '?id=' + id_ value = None if results2.origine == 'origine': origine = 'origine' elif results2.origine == 'continue': origine = 'rompu' elif results2.origine == 'rp': origine = 'rp' children = [] children0 = [] children1 = [] children2 = [] children3 = [] children4 = [] children5 = [] children6 = [] children7 = [] # LEVEL INITIAL children0 = list_append(children, { "name": root, "lien": doc, "value": value, "origine": origine, "children": [] }) # LEVEL 0 for row in results: id_s = row.imm_source orig = row.origine level1_data = [] url = base_route + "?id=" + id_s doc = base_route_doc + '?id=' + id_s if 'DP' in id_s or 'RP' in id_s: origdp = 'origine' children1 = list_append(children0, { "name": id_s, "origine": origdp, }) elif len(row.children) > 0: level1_data = row.children children1 = list_append(children0, { "name": id_s, "lien": doc, "value": url, "origine": orig, "children": [] }) elif len(row.children) == 0 and orig == 'continue': orig = 'rompu' children1 = list_append(children0, { "name": id_s, "lien": doc, "origine": orig, }) else: children1 = list_append(children0, { "name": id_s, "lien": doc, "origine": orig, }) # LEVEL1 for row1 in level1_data: id_s1 = row1.imm_source orig1 = row1.origine level2_data = [] url = base_route + "?id=" + id_s1 doc = base_route_doc + '?id=' + id_s1 if 'DP' in id_s1 or 'RP' in id_s1: origdp1 = 'origine' children1 = list_append(children0, { "name": id_s1, "origine": origdp1, }) elif len(row1.children) > 0: level2_data = row1.children children2 = list_append(children1, { "name": id_s1, "lien": doc, "value": url, "origine": orig1, "children": [] }) elif len(row.children) == 0 and orig1 == '': orig1 = 'rompu' children2 = list_append(children1, { "name": id_s1, "lien": doc, "origine": orig1, }) else: children2 = list_append(children1, { "name": id_s1, "lien": doc, "origine": orig1, }) # LEVEL2 for row2 in level2_data: id_s2 = row2.imm_source orig2 = row2.origine level3_data = [] url = base_route + "?id=" + id_s2 doc = base_route_doc + '?id=' + id_s2 if 'DP' in id_s2 or 'RP' in id_s2: origdp2 = 'origine' children1 = list_append(children0, { "name": id_s2, "origine": origdp2, }) elif len(row2.children) > 0: level3_data = row2.children children3 = list_append(children2, { "name": id_s2, "lien": doc, "value": url, "origine": orig2, "children": [] }) elif len(row.children) == 0 and orig2 == '': orig2 = 'rompu' children3 = list_append(children2, { "name": id_s2, "lien": doc, "origine": orig2, }) else: children3 = list_append(children2, { "name": id_s2, "lien": doc, "origine": orig2, }) # LEVEL3 for row3 in level3_data: id_s3 = row3.imm_source orig3 = row3.origine level4_data = [] url = base_route + "?id=" + id_s3 doc = base_route_doc + '?id=' + id_s3 if 'DP' in id_s3 or 'RP' in id_s3: children1 = list_append(children0, { "name": id_s3, "origine": orig, }) elif len(row3.children) > 0: level4_data = row3.children children4 = list_append(children3, { "name": id_s3, "lien": doc, "value": url, "origine": orig3, "children": [] }) elif len(row.children) == 0 and orig3 == '': orig3 = 'rompu' children4 = list_append(children3, { "name": id_s3, "lien": doc, "origine": orig3, }) else: children4 = list_append(children3, { "name": id_s3, "lien": doc, "origine": orig3, }) # LEVEL4 for row4 in level4_data: id_s4 = row4.imm_source orig4 = row4.origine level5_data = [] url = base_route + "?id=" + id_s4 doc = base_route_doc + '?id=' + id_s4 if 'DP' in id_s4 or 'RP' in id_s4: children1 = list_append(children0, { "name": id_s4, "origine": orig, }) elif len(row4.children) > 0: level5_data = row4.children children5 = list_append(children4, { "name": id_s4, "lien": doc, "value": url, "origine": orig4, "children": [] }) elif len(row.children) == 0 and orig4 == '': orig4 = 'rompu' children5 = list_append(children4, { "name": id_s4, "lien": doc, "origine": orig4, }) else: children5 = list_append(children4, { "name": id_s4, "lien": doc, "origine": orig4, }) # LEVEL5 for row5 in level5_data: id_s5 = row5.imm_source orig5 = row.origine level6_data = [] url = base_route + "?id=" + id_s5 doc = base_route_doc + '?id=' + id_s5 if 'DP' in id_s5 or 'RP' in id_s5: children1 = list_append(children0, { "name": id_s5, "origine": orig, }) elif len(row5.children) > 0: level6_data = row5.children children6 = list_append(children5, { "name": id_s5, "lien": doc, "value": url, "origine": orig5, "children": [] }) elif len(row.children) == 0 and orig5 == '': orig5 = 'rompu' children6 = list_append(children5, { "name": id_s5, "lien": doc, "origine": orig5, }) else: children6 = list_append(children5, { "name": id_s5, "lien": doc, "origine": orig5, }) # LEVEL6 for row6 in level6_data: id_s6 = row6.imm_source orig6 = row6.origine level7_data = [] url = base_route + "?id=" + id_s6 doc = base_route_doc + '?id=' + id_s6 if 'DP' in id_s6 or 'RP' in id_s6: children1 = list_append(children0, { "name": id_s6, "origine": orig, }) elif len(row6.children) > 0: level7_data = row6.children children7 = list_append(children6, { "name": id_s6, "lien": doc, "value": url, "origine": orig6, "children": [] }) elif len(row.children) == 0 and orig6 == '': orig6 = 'rompu' children7 = list_append(children6, { "name": id_s6, "lien": doc, "origine": orig6, }) else: children7 = list_append(children6, { "name": id_s6, "lien": doc, "origine": orig6, }) # LEVEL7 for row7 in level7_data: id_s7 = row7.imm_source orig7 = row.origine url = base_route + "?id=" + id_s7 doc = base_route_doc + '?id=' + id_s7 if 'DP' in id_s7 or 'RP' in id_s7: children1 = list_append(children0, { "name": id_s7, "origine": orig, }) elif len(row7.children) > 0: children8 = list_append(children7, { "name": id_s7, "lien": doc, "value": url, "origine": orig7, "children": [] }) elif len(row7.children) == 0 and orig7 == '': orig7 = 'chaîne brisée' children8 = list_append(children7, { "name": id_s7, "lien": doc, "origine": orig7, }) else: children8 = list_append(children7, { # NOQA "name": id_s7, "lien": doc, "origine": orig7, }) data = copy.copy(children) # Added to make it work in IE11, but do not ask why... request.response.headers['Access-Control-Allow-Origin'] = '*' return data[0]
def mutation_list(request): code = None if 'code' in request.params: code = request.params['code'] else: return HTTPNotFound() if 'id' in request.params: id = request.params['id'] else: return HTTPNotFound() debug = False if 'debug' in request.params: debug = True list = [] qq = DBSession.query(VPlanMut).filter( VPlanMut.id_cad_geom == int(id)).order_by(VPlanMut.plan) results = qq.all() for result in results: date_plan = result.date_plan if date_plan: date_plan = dateToString(date_plan) else: date_plan = '' date_acte = result.date_acte if date_acte: date_acte = dateToString(date_acte) else: date_acte = '' date_depot = result.date_depot if date_depot: date_depot = dateToString(date_depot) else: date_depot = '' req_bidon = result.req_bidon if req_bidon: req_bidon = 'oui' else: req_bidon = 'non' cut_plan = result.nom_plan list_cut = cut_plan.split('_') nom_plan = list_cut[1] list.append({ 'id': result.id_folio, 'cadastre': result.cadastre, 'nom_plan': nom_plan, 'plan': result.plan, 'indice': result.indice, 'req_tot': result.req_tot, 'req_bidon': req_bidon, 'date_plan': date_plan, 'date_acte': date_acte, 'date_depot': date_depot, 'chemin_desi': result.chemin_desi }) return {'list': list, 'code': code, 'debug': debug}
def viewer(self): mapper = { 'graphique': VPlanGraphique, 'servitude': Servitude, 'cadastre_graphique': CadastreGraphique, 'distribution': VPlanDistr, 'mutation': VPlanMut } type_plan = { 'o': u'original', 'm': u'muté', 'r': u'remanié', 'c': u'copié' } id_plan = self.request.params['id_plan'] code = None if 'code' in self.request.params: code = self.request.params['code'] type_ = self.request.params['type'] mapped_class = mapper[type_] params = DBSession.query(mapped_class).get(id_plan) plan_url = self.request.route_url('image_proxy', type=type_, id=id_plan) if code: plan_url += '?code=' + code self.request.response.content_type = 'application/javascript' type_plan_ = None if 'type_plan' in params.__table__.c.keys(): if params.type_plan[0:1] in type_plan.keys(): type_plan_ = type_plan[params.type_plan[0:1]] else: type_plan_ = params.type_plan if params.echelle: echelle = params.echelle else: echelle = None return { 'debug': self.debug, 'id_plan': id_plan, 'plan_largeur': params.larg, 'plan_hauteur': params.haut, 'plan_resolution': params.resol, 'plan_url': plan_url, 'nomcad': params.cadastre, 'no_plan': params.plan, 'type_plan': type_plan_, 'echelle': echelle }