def numeros_view(request): """ Return all numeros """ # Check connected if not Utils.check_connected(request): raise exc.HTTPForbidden() numero = int(request.params['numero']) if 'numero' in request.params else None cadastre_id = [int(a) for a in request.params['cadastre_id'].split(",")] if 'cadastre_id' in request.params else None type_id = [int(a) for a in request.params['type_id'].split(",")] if 'type_id' in request.params else None etat_id = [int(a) for a in request.params['etat_id'].split(",")] if 'etat_id' in request.params else None query = request.dbsession.query(VNumeros) if numero: query = query.filter(VNumeros.numero == numero) if cadastre_id: query = query.filter(VNumeros.cadastre_id.in_(cadastre_id)) if type_id: query = query.filter(VNumeros.type_numero_id.in_(type_id)) if etat_id: query = query.filter(VNumeros.etat_id.in_(etat_id)) query = query.order_by(VNumeros.numero.asc()).all() return Utils.serialize_many(query)
def reservation_numeros_mo_by_affaire_id_view(request): """ Return all reservations_numeros_mo by affaire_id """ # Check connected if not Utils.check_connected(request): raise exc.HTTPForbidden() searchLimit = request.registry.settings['search_limit'] affaire_id = request.matchdict['id'] cadastre_id = request.params[ "cadastre_id"] if "cadastre_id" in request.params else None startDate = request.params[ "startDate"] if "startDate" in request.params else None endDate = request.params["endDate"] if "endDate" in request.params else None query = request.dbsession.query(VReservationNumerosMO).filter( VReservationNumerosMO.affaire_id == affaire_id).order_by( VReservationNumerosMO.id.desc()) if not cadastre_id is None: query = query.filter(VReservationNumerosMO.cadastre_id == cadastre_id) if not startDate is None: query = query.filter(VReservationNumerosMO.date >= startDate) if not endDate is None: query = query.filter(VReservationNumerosMO.date <= endDate) if request.params == {} or (cadastre_id is None and startDate is None): query = query.limit(searchLimit) query = query.all() return Utils.serialize_many(query)
def operateur_notes_maj_update_view(request): """ Update last seen notes_maj in operateur """ # Check authorization if not Utils.check_connected(request): raise exc.HTTPForbidden() # Get operateur_id operateur_id = request.params[ 'operateur_id'] if 'operateur_id' in request.params else None last_notes_maj_id = request.params[ 'last_notes_maj_id'] if 'last_notes_maj_id' in request.params else None model = request.dbsession.query(Operateur).filter( Operateur.id == operateur_id).first() # If result is empty if not model: raise CustomError( CustomError.RECORD_WITH_ID_NOT_FOUND.format( Operateur.__tablename__, operateur_id)) # Read params operateur model.last_notemaj_id = last_notes_maj_id return Utils.get_data_save_response( Constant.SUCCESS_SAVE.format(Operateur.__tablename__))
def download_affaire_document_view(request): """ Download document """ # Check connected if not Utils.check_connected(request): raise exc.HTTPForbidden() affaires_directory = request.registry.settings['affaires_directory'] affaire_id = request.params['affaire_id'] relpath = request.params['relpath'] filename = request.params['filename'] affaire_chemin = request.dbsession.query(Affaire).filter( Affaire.id == affaire_id).first().chemin file_path = os.path.normcase( os.path.join(affaires_directory, affaire_chemin, relpath, filename)) folder_path = os.path.exists(os.path.dirname(file_path)) if not folder_path: Utils.create_affaire_folder(request, folder_path) import urllib response = FileResponse(file_path, request=request, cache_max_age=86400) headers = response.headers headers['Content-Type'] = 'application/download' headers['Accept-Ranges'] = 'bite' headers[ 'Content-Disposition'] = 'attachment;filename=' + urllib.parse.quote( filename) return response
def affaire_numeros_view(request): """ Add new numero_etat_histo """ # Check connected if not Utils.check_connected(request): raise exc.HTTPForbidden() conditions = list() affaire_id = request.matchdict["id"] # Récupérer les id des numéros de la MO settings = request.registry.settings numeros_immeubles_type_id = [ settings['numero_bf_id'], settings['numero_ddp_id'], settings['numero_ppe_id'], settings['numero_pcop_id'] ] conditions.append(VNumerosAffaires.affaire_id == affaire_id) conditions.append(VNumerosAffaires.numero_type_id.in_(numeros_immeubles_type_id)) if 'affaire_numero_actif' in request.params: affaire_numero_actif = request.params['affaire_numero_actif'] affaire_numero_actif = True if affaire_numero_actif.upper() == 'TRUE' else False conditions.append(VNumerosAffaires.affaire_numero_actif == affaire_numero_actif) records = request.dbsession.query(VNumerosAffaires).filter( *conditions).order_by(VNumerosAffaires.numero.desc()).all() return Utils.serialize_many(records)
def affaire_documents_view(request): """ GET documents affaire """ # Check connected if not Utils.check_connected(request): raise exc.HTTPForbidden() affaire_id = request.matchdict['id'] affaire_chemin = request.dbsession.query(Affaire).filter( Affaire.id == affaire_id).first().chemin documents = [] if not affaire_chemin: return documents affaire_path = os.path.join( request.registry.settings['affaires_directory'], affaire_chemin).replace('\\', '/') for root, dirs, files in os.walk(affaire_path, topdown=False): for name in files: if name.startswith(".") or name.startswith("~"): continue file_i = {} file_i['relpath'] = os.path.relpath(root, affaire_path).replace( '\\', '/') file_i['filename'] = name file_i['creation'] = datetime.fromtimestamp( os.path.getctime(os.path.join(affaire_path, root))).strftime("%d.%m.%Y") documents.append(file_i) return documents
def numero_mo_next_view(request): """ Return all next available numero MO par cadastre, type et plan """ # Check connected if not Utils.check_connected(request): raise exc.HTTPForbidden() cadastre_id = request.params[ 'cadastre_id'] if 'cadastre_id' in request.params else None type_id = request.params['type_id'] if 'type_id' in request.params else None plan = request.params['plan'] if 'plan' in request.params else None query = request.dbsession.query(VProchainNumeroDisponible) if cadastre_id: query = query.filter( VProchainNumeroDisponible.cadastre_id == cadastre_id) if type_id: query = query.filter( VProchainNumeroDisponible.numero_type_id == type_id) if plan: query = query.filter(VProchainNumeroDisponible.plan == plan) query = query.all() return Utils.serialize_many(query)
def numeros_search_view(request): """ Search numeros """ # Check connected if not Utils.check_connected(request): raise exc.HTTPForbidden() settings = request.registry.settings search_limit = int(settings['search_limit']) params = request.params matDiff = False if 'matDiff' in params: matDiff = True if params['matDiff'] == 'true' else False # Set conditions conditions = Utils.get_search_conditions(VNumeros, params) # filter by conditions query = request.dbsession.query(VNumeros).order_by( VNumeros.cadastre, VNumeros.numero.desc()).filter(*conditions) query = query.filter(VNumeros.type_numero_id <= 4) # if option matDiff selected if matDiff: query = query.filter( and_(VNumeros.diff_entree.isnot(None), VNumeros.diff_sortie.is_(None))) query = query.limit(search_limit).all() return Utils.serialize_many(query)
def etapes_new_view(request): """ POST etapes affaire """ # Check authorization if not Utils.check_connected(request): raise exc.HTTPForbidden() chef_equipe_id = request.params['chef_equipe_id'] if 'chef_equipe_id' in request.params else None # Add new step model = Utils.addNewRecord(request, AffaireEtape) # send mail affaire_etape_index = request.dbsession.query(AffaireEtapeIndex).filter(AffaireEtapeIndex.id == model.etape_id).first() etape_mailer = request.dbsession.query(EtapeMailer).filter(model.etape_id == EtapeMailer.etape_id).all() operateur = request.dbsession.query(Operateur).all() mail_list = [] # only when chef_equipe is specified if chef_equipe_id: mail_list.append( request.dbsession.query(Operateur).filter(Operateur.id == chef_equipe_id).first().mail ) # update chef d'équipe in affaire affaire = request.dbsession.query(Affaire).filter(Affaire.id == model.affaire_id).first() affaire.technicien_id = chef_equipe_id # construct mail_list for em_i in etape_mailer: if em_i.sendmail: mail = next((op.mail for op in operateur if op.id == em_i.operateur_id), None) if mail: mail_list.append(mail) # Send mail only if step prio is 1 and if mail_list not empty if affaire_etape_index.priorite == int(request.registry.settings['affaire_etape_priorite_1_id']) and len(mail_list)>0: # get affaire informations affaire = request.dbsession.query(VAffaire).filter(VAffaire.id == model.affaire_id).first() # get list of done steps lastSteps = request.dbsession.query(VEtapesAffaires).filter( and_( VEtapesAffaires.affaire_id == model.affaire_id, VEtapesAffaires.etape_priorite == int(request.registry.settings['affaire_etape_priorite_1_id']) ) ).order_by(VEtapesAffaires.id.desc()).all() lastSteps = "".join(["<tr><td style='border: 1px solid black; border-collapse: collapse; padding: 5px 25px 5px 10px;'>{}</td>\ <td style='border: 1px solid black; border-collapse: collapse; padding: 5px 25px 5px 10px;'>{} {}</td>\ <td style='border: 1px solid black; border-collapse: collapse; padding: 5px 25px 5px 10px;'>{}</td>\ <td style='border: 1px solid black; border-collapse: collapse; padding: 5px 25px 5px 10px;'>{}</td>\ </tr>".format(i.datetime, i.operateur_prenom, i.operateur_nom, i.etape, i.remarque if i.remarque else "") for i in lastSteps]) affaire_nom = " (" + affaire.nom + ")" if affaire.nom is not None else "" text = "L'affaire <b><a href='" + os.path.join(request.registry.settings['infolica_url_base'], 'affaires', str(affaire.id)) + "'>" + str(affaire.id) + affaire_nom + "</a></b> est en attente pour l'étape <b>"+ affaire_etape_index.nom +"</b>." text += ("<br><br><br><h4>Historique de l'affaire</h4><table style='border: 1px solid black; border-collapse: collapse; padding: 5px 25px 5px 10px;'><tr><th style='border: 1px solid black; border-collapse: collapse; padding: 5px 25px 5px 10px;'>Horodateur</th><th style='border: 1px solid black; border-collapse: collapse; padding: 5px 25px 5px 10px;'>Opérateur</th style='border: 1px solid black; border-collapse: collapse; padding: 5px 25px 5px 10px;'><th>Etape</th><th style='border: 1px solid black; border-collapse: collapse; padding: 5px 25px 5px 10px;'>Remarque</th></tr>" + lastSteps + "</table>") if lastSteps != "" else "" subject = "Infolica - affaire " + str(affaire.id) send_mail(request, mail_list, "", subject, html=text) return Utils.get_data_save_response(Constant.SUCCESS_SAVE.format(AffaireEtape.__tablename__))
def affaire_cockpit_view(request): """ Return active affaires (id, no_access, id_current_step) """ # Check connected if not Utils.check_connected(request): raise exc.HTTPForbidden() type_id = request.params['type_id'] if 'type_id' in request.params else None etape_id = request.params['etape_id'].split(',') if 'etape_id' in request.params else None etape_finProcessus_id = request.registry.settings["affaire_etape_fin_processus_id"] affaire_show_timedelta = int(request.registry.settings['affaire_show_timedelta']) since = datetime.now() - timedelta(days=affaire_show_timedelta) query = request.dbsession.query(VAffaire) if type_id is not None: query = query.filter(VAffaire.type_id == type_id) else: query = query.filter(VAffaire.etape_id != None) if etape_id is not None: query = query.filter(VAffaire.etape_id.in_(etape_id)) else: query = query.filter(or_( VAffaire.etape_id != etape_finProcessus_id, and_( VAffaire.etape_id == etape_finProcessus_id, VAffaire.etape_datetime >= since ) )) query = query.all() affaires = [] for affaire in query: affaires.append({ 'id': affaire.id, 'affaire_type': affaire.type_affaire, 'affaire_type_id': affaire.type_id, 'no_access': affaire.no_access, 'etape': affaire.etape, 'etape_id': affaire.etape_id, 'etape_ordre': affaire.etape_ordre, 'etape_datetime': datetime.strftime(affaire.etape_datetime, '%Y-%m-%d %H:%M:%S'), 'etape_days_elapsed': (datetime.now().date() - affaire.etape_datetime.date()).days, 'operateur_id': affaire.technicien_id, 'operateur_initiales': affaire.technicien_initiales, 'cadastre': affaire.cadastre, 'description': affaire.nom, 'urgent': affaire.urgent, 'urgent_echeance': datetime.strftime(affaire.urgent_echeance, '%Y-%m-%d') if not affaire.urgent_echeance is None else None }) return affaires
def affaire_cockpit_view(request): """ Return active affaires (id, no_access, id_current_step) """ # Check connected if not Utils.check_connected(request): raise exc.HTTPForbidden() type_id = request.params['type_id'] if 'type_id' in request.params else None etape_id = request.params['etape_id'] if 'etape_id' in request.params else None affaire_show_timedelta = int(request.registry.settings['affaire_show_timedelta']) since = datetime.date(datetime.now()) - timedelta(days=affaire_show_timedelta) etape_mat_diff_id = int(request.registry.settings['affaire_etape_mat_diff_id']) query = request.dbsession.query(VAffaire) if type_id is not None: query = query.filter(VAffaire.type_id == type_id) else: query = query.filter(VAffaire.etape_id != None) if etape_id is not None: query = query.filter(VAffaire.etape_id == etape_id) else: query = query.filter(or_( VAffaire.etape_id == etape_mat_diff_id, and_( or_( VAffaire.date_envoi >= since, VAffaire.date_envoi == None ), VAffaire.date_cloture == None ) )) query = query.all() affaires = [] for affaire in query: affaires.append({ 'id': affaire.id, 'affaire_type': affaire.type_affaire, 'affaire_type_id': affaire.type_id, 'no_access': affaire.no_access, 'etape_id': affaire.etape_id, 'etape_ordre': affaire.etape_ordre, 'etape_datetime': datetime.strftime(affaire.etape_datetime, '%Y-%m-%d %H:%M:%S'), 'operateur_id': affaire.technicien_id, 'operateur_initiales': affaire.technicien_initiales, 'cadastre': affaire.cadastre, 'description': affaire.nom }) return json.dumps(affaires)
def affaires_view(request): """ Return all affaires """ # Check connected if not Utils.check_connected(request): raise exc.HTTPForbidden() query = request.dbsession.query(VAffaire).order_by(VAffaire.id.desc()).all() return Utils.serialize_many(query)
def clients_view(request): """ Return all clients """ # Check connected if not Utils.check_connected(request): raise exc.HTTPForbidden() query = request.dbsession.query(Client).filter(Client.sortie == None).all() return Utils.serialize_many(query)
def balance_generate_table_view(request): """ Generate table balance """ # Check connected if not Utils.check_connected(request): raise exc.HTTPForbidden() send_mail(request, [request.registry.settings["infolica_balance_mail"]], "Génération Balance Infolica\nMail généré automatiquement", "Infolica-Balance") return "ok"
def controles_ppe_view(request): """ Return all controles_ppe """ # Check connected if not Utils.check_connected(request): raise exc.HTTPForbidden() query = request.dbsession.query(ControlePPE).all() return Utils.serialize_many(query)
def operateurs_view(request): """ Return all operateurs """ # Check connected if not Utils.check_connected(request): raise exc.HTTPForbidden() query = request.dbsession.query(Operateur).filter(Operateur.sortie == None).all() return Utils.serialize_many(query)
def facture_type_view(request): """ Return all facture types """ # Check connected if not Utils.check_connected(request): raise exc.HTTPForbidden() query = request.dbsession.query(FactureType).all() return Utils.serialize_many(query)
def numeros_relations_view(request): """ Return all numeros_relations """ # Check connected if not Utils.check_connected(request): raise exc.HTTPForbidden() query = request.dbsession.query(VNumerosRelations).all() return Utils.serialize_many(query)
def suivi_mandats_view(request): """ Return all suivi_mandats """ # Check connected if not Utils.check_connected(request): raise exc.HTTPForbidden() query = request.dbsession.query(SuiviMandat).all() return Utils.serialize_many(query)
def tableau_emoluments_view(request): """ Return table of emoluments """ # Check connected if not Utils.check_connected(request): raise exc.HTTPForbidden() query = request.dbsession.query(TableauEmoluments).all() return Utils.serialize_many(query)
def client_by_id_view(request): """ Return client by id """ # Check connected if not Utils.check_connected(request): raise exc.HTTPForbidden() id = request.matchdict['id'] query = request.dbsession.query(Client).filter(Client.id == id).first() return Utils.serialize_one(query)
def plans_mo_view(request): """ Return all plans_mo """ # Check connected if not Utils.check_connected(request): raise exc.HTTPForbidden() query = request.dbsession.query(VPlan).order_by(VPlan.planno.asc()).all() return Utils.serialize_many(query)
def operateur_by_id_view(request): """ Return operateur by id """ # Check connected if not Utils.check_connected(request): raise exc.HTTPForbidden() id = request.matchdict['id'] query = request.dbsession.query(Operateur).filter( Operateur.id == id).first() return Utils.serialize_one(query)
def services_view(request): """ GET services """ # Check connected if not Utils.check_connected(request): raise exc.HTTPForbidden() records = request.dbsession.query(Service).order_by( Service.ordre.asc()).all() return Utils.serialize_many(records)
def reservation_numeros_mo_by_affaire_id_view(request): """ Return all reservations_numeros_mo by affaire_id """ # Check connected if not Utils.check_connected(request): raise exc.HTTPForbidden() affaire_id = request.matchdict['id'] query = request.dbsession.query(VReservationNumerosMO).filter( VReservationNumerosMO.affaire_id == affaire_id).all() return Utils.serialize_many(query)
def affaire_by_id_view(request): """ Return affaires by id """ # Check connected if not Utils.check_connected(request): raise exc.HTTPForbidden() id = request.matchdict['id'] query = request.dbsession.query(VAffaire) one = query.filter(VAffaire.id == id).first() return Utils.serialize_one(one)
def numeros_by_id_view(request): """ Return numeros by id """ # Check connected if not Utils.check_connected(request): raise exc.HTTPForbidden() # Get controle mutation id id = request.id = request.matchdict['id'] query = request.dbsession.query(VNumeros).filter(VNumeros.id == id).first() return Utils.serialize_one(query)
def balance_mutation_names_view(request): """ Get balance by mutation names """ # Check connected if not Utils.check_connected(request): raise exc.HTTPForbidden() query = request.dbsession.query(GeosBalance.mutation).group_by(GeosBalance.mutation).all() query = [i[0] for i in query] return json.dumps(query)
def etapes_index_view(request): """ GET etapes index """ # Check connected if not Utils.check_connected(request): raise exc.HTTPForbidden() records = request.dbsession.query(AffaireEtapeIndex).filter( AffaireEtapeIndex.ordre != None).order_by( AffaireEtapeIndex.ordre.asc()).all() return Utils.serialize_many(records)
def affaires_factures_view(request): """ Return all factures in affaire """ # Check connected if not Utils.check_connected(request): raise exc.HTTPForbidden() affaire_id = request.matchdict["id"] query = request.dbsession.query(VFactures).filter( VFactures.affaire_id == affaire_id).all() return Utils.serialize_many(query)