예제 #1
0
def change_email():
    g = Gui()
    current_user = g.user

    questions = [inquirer.Email("email", message="nouvelle email")]
    answers = inquirer.prompt(questions)
    if "email" not in answers.keys():
        return False
    email = answers["email"]
    if len(Personne.where("`email`='{}'".format(email))) > 0:
        print("Un utilisateur possède déjà cette email...")
        Page.wait_input()
        return False

    query = "UPDATE personne SET email='{}' WHERE id = {}".format(
        answers["email"], current_user.id)
    logging.debug("QUERY: %s", query)
    cursor = db.cursor()
    cursor.execute(query)
    db.commit()
    if cursor.rowcount > 0:
        print("Email mis à jour")
    else:
        print("Echec de la mise à jour")
    Page.wait_input()
    return True
예제 #2
0
def register_():
   print("Hello new user, please fill out the following form \n\n")
   entity = Personne()
   answers = None
   fields = [
      "nom",
      "prenom",
   ]
   questions = [
      inquirer.Text("nom", message="Nouveau nom"),
      inquirer.Text("prenom", message="Nouveau prénom"),
      inquirer.List("genre", message="Genre", choices=["Homme", "Femme", "Agender", "Pangender", "Androgyne", "Genre fluide"]),
      inquirer.Email("email","Email"),
      inquirer.Password("mot_de_passe", message="Mot de passe")
   ]

   while "Create a user uniquely with his email":
      answers = inquirer.prompt(questions)
      if answers is None or not len(answers.keys()) :
         return False
      #check if user doesn't aready exist
      #TODO change he email field to actual email table field
      if len(Personne.where("`email` = '{}'".format(answers["email"]))) > 0: 
         print("Un utilisateur avec l'email {} existe déjà...\n\n".format(answers["email"]))
         
      else:
         break

   logging.debug("Creating user (%s) with values %s", entity, answers)
   
   for field, value in answers.items():
      setattr(entity, field, value)
   
   logging.debug("Entite personne %s", entity)
   print("\nMerci, maintenant nous voulons encore recuillir votre adresse \n")
   ad_data = get_address()
   if not len(ad_data.keys()):
      return False
   adresse = Addresse.create(**ad_data)
   
   p = Personne(**answers)
   p.adresse_id = adresse.id
   p.save()
   logging.debug("personne %s", p)
   g = Gui()
   g.user = p
   print("Utilisateur crée avec succès!")
   Page.wait_input()
   return True
예제 #3
0
def change_address():
    g = Gui()
    current_user = g.user
    query = "DELETE FROM adresse WHERE id = {}".format(current_user.adresse_id)
    logging.debug("EXECUTING QUERY: %s", query)
    cursor = db.cursor()
    cursor.execute(query)
    db.commit()
    if cursor.rowcount > 0:
        address = Addresse.create(**get_address())
        current_user.adresse_id = address.id
        current_user.save()
        print("Mise à jour de l'adresse effectué!")
    else:
        print("Impossible de mettre à jour l'adresse actuel")
    Page.wait_input()
    return True
예제 #4
0
def change_password():
    g = Gui()
    current_user = g.user

    questions = [inquirer.Password("password", message="nouveau mot de passe")]
    answers = inquirer.prompt(questions)
    if "password" not in answers.keys():
        return False
    query = "UPDATE personne SET mot_de_passe='{}' WHERE id = {}".format(
        answers["password"], current_user.id)
    logging.debug("QUERY: %s", query)
    cursor = db.cursor()
    cursor.execute(query)
    db.commit()
    if cursor.rowcount > 0:
        print("Mot de passe mis à jour")
    else:
        print("Echec de la mise à jour")
    Page.wait_input()
    return True
예제 #5
0
def change_data():
    g = Gui()
    current_user = g.user
    questions = [
        inquirer.Text("nom", message="Nouveau nom"),
        inquirer.Text("prenom", message="Nouveau prénom"),
        inquirer.List("genre",
                      message="Genre",
                      choices=[
                          "Homme", "Femme", "Agender", "Pangender",
                          "Androgyne", "Genre fluide"
                      ],
                      default=current_user.genre)
    ]
    answers = inquirer.prompt(questions)
    if "genre" not in answers.keys():
        return False

    fields = {k: v for k, v in answers.items() if v}

    if len(fields.keys()) <= 0:
        return False
    set_query = "SET "
    for k, v in fields.items():
        set_query += "{} = '{}', ".format(k, v)
    query = "UPDATE personne {} WHERE id = {}".format(set_query[:-2],
                                                      current_user.id)
    logging.debug("QUERY: %s", query)
    cursor = db.cursor()
    cursor.execute(query)
    db.commit()
    if cursor.rowcount > 0:
        print("Mot de passe mis à jour")
    else:
        print("Echec de la mise à jour")
    Page.wait_input()
    return True
    print("Mise à jour de vos donnée personnel effectué avec succès")
    Page.wait_input()
예제 #6
0
def rentals_future():
    Page.clear()

    g = Gui()
    current_user = g.user
    logging.debug("Current user id %s", current_user.id)
    #Print my buildings
    cursor = db.cursor(dictionary=True)
    query = "SELECT *, location.id location_id, location.date_arrivee, DATE_ADD(location.date_arrivee, INTERVAL location.duree DAY) date_depart FROM location_prioprietaire INNER JOIN location on location.bien_immobilier_id = location_prioprietaire.bien_id WHERE proprietaire_id = {} AND estConfirme = 1 AND DATE_ADD(location.date_arrivee, INTERVAL location.duree DAY) > DATE(NOW())".format(
        current_user.id)
    logging.debug("QUERY: %s", query)
    cursor.execute(query)
    my_rentals = cursor.fetchall()
    db.commit()
    logging.debug("LOCATION EN ATTENTE : %s", my_rentals)
    headers = [
        "id", "Type de bien", "description", "addresse", "date arrivée",
        "date départ"
    ]

    def build_addresse(ad):
        if ad is None:
            return ""
        return "" + ad["rue"] + " " + ad["numero"] + " " + ad[
            "etat"] + "(" + ad["commune"] + ")"

    data = list(
        map(
            lambda x: (x["bien_id"], x["type_bien"], x["description"][:20],
                       build_addresse(x), x["date_arrivee"], x["date_depart"]),
            my_rentals))
    if len(data) <= 0:
        data = [["" for i in range(len(headers))]]
    string = tt.to_string(
        data,
        header=headers,
        style=tt.styles.ascii_thin_double,
    )
    print(string)

    #Actions on buildings
    mapping_actions = {"Refuser la location": "refuse", "Retour": "return"}
    actions = [
        inquirer.List("action",
                      message="Que voulez vous faire?",
                      choices=["Refuser la location", "Retour"])
    ]
    action = inquirer.prompt(actions)
    logging.debug("CHOOSING TO DO %s ON BUILDING", action)
    if action is None or "action" not in action.keys():
        return False

    action = mapping_actions[action["action"]]
    if action == "return":
        return False

    #Check that it actually is our building
    building_id = input("\n Numéro du bien: ")
    if not len(building_id):
        return False
    building_id = int(building_id)
    building_by_id = {x["bien_immobilier_id"]: x for x in my_rentals}
    logging.debug(building_by_id)
    if building_id not in building_by_id.keys():
        print("Vous ne pouvez editer ce bien.")
        Page.wait_input()
        return False
    #Build query
    query = ""
    if action == "refuse":
        query = "UPDATE location SET `estConfirme` = NULL WHERE bien_immobilier_id = {}".format(
            building_id)

    logging.debug("QUERY: %s", query)
    cursor = db.cursor()
    cursor.execute(query)
    try:
        db.commit()
        if cursor.rowcount > 0:
            print("Location mis à jour avec succès")
            return True
        else:
            print("Impossible de mettre à jour la location")
            return False
    except:
        db.rollback()
    Page.wait_input()
예제 #7
0
def my_properties_():
    Page.clear()

    g = Gui()
    current_user = g.user
    logging.debug("Current user id %s", current_user.id)
    #Print my buildings
    cursor = db.cursor(dictionary=True)
    query = "SELECT * FROM search_biens WHERE proprietaire = {}".format(
        current_user.id)
    logging.debug("QUERY: %s", query)
    cursor.execute(query)
    my_rentals = cursor.fetchall()
    db.commit()
    logging.debug(my_rentals)
    headers = ["id", "Type de bien", "description", "addresse"]

    def build_addresse(ad):
        if ad is None:
            return ""
        return "" + ad["rue"] + " " + ad["numero"] + " " + ad[
            "etat"] + "(" + ad["commune"] + ")"

    data = list(
        map(
            lambda x: (x["bien_id"], x["type_bien"], x["description"][:20],
                       build_addresse(x)), my_rentals))
    if len(data) <= 0:
        data = [["" for i in range(len(headers))]]
    string = tt.to_string(
        data,
        header=headers,
        style=tt.styles.ascii_thin_double,
    )
    print(string)

    #Actions on buildings
    mapping_actions = {
        "Créer un nouveau bien": "create",
        "Mettre à jour un bien": "update",
        "Supprimer un bien": "delete",
        "Retour": "return"
    }
    actions = [
        inquirer.List("action",
                      message="Que voulez vous faire?",
                      choices=[
                          "Créer un nouveau bien", "Mettre à jour un bien",
                          "Supprimer un bien", "Retour"
                      ])
    ]
    action = inquirer.prompt(actions)
    logging.debug("CHOOSING TO DO %s ON BUILDING", action)
    if action is None or "action" not in action.keys():
        return False

    action = mapping_actions[action["action"]]
    if action == "return":
        return False

    if action == "create":
        b = building_modal()
        if b:
            print("Nouvelle imeuble créé!")
            Page.wait_input()
        return True

    building_id = input("\n Numéro du bien: ")
    if not len(building_id):
        return False
    building_id = int(building_id)
    building_by_id = {x["bien_id"]: x for x in my_rentals}
    logging.debug("MES APPARTEMENTS %s", building_by_id)

    if building_id not in building_by_id.keys():
        print("Vous ne pouvez editer ce bien.")
        Page.wait_input()
        return False

    current_building = building_by_id[building_id]
    if action == "update":

        building_modal(current_building)
        Page.wait_input()
    elif action == "delete":
        #get building
        query = "DELETE from bien_immobilier WHERE id = {}".format(building_id)
        logging.debug("QUERY: %s", query)
        cursor = db.cursor()
        cursor.execute(query)
        try:
            db.commit()
            if cursor.rowcount > 0:
                print("Bien immobilier supprimé avec succès")
                return True
            else:
                print("Impossible de supprimer le bien immobilier")
                return False
        except:
            db.rollback()
        Page.wait_input()