示例#1
0
def landing():
    if 'username' in session.keys():
        username = session['username']
        adminUser = AdminUser()
        hasReviews = adminUser.getByUsername(username).hasReviews()  
        return render_template("landing.html", hasReviews = hasReviews, username=username)
    return render_template("landing.html")
示例#2
0
def recomendate():
    if 'username' not in session.keys():
        return render_template('landing.html')

    username = session["username"]
    adminUser = AdminUser()
    user = adminUser.getByUsername(username)

    #adminML = AdminMachineLearning()
    #correlations = adminML.getMachineLearning()

    #correlations.recomendate(user)
    recomendations = []

    if user.hasReviews():
        for recomendation in user.getRecomendations():
            recomendations.append(recomendation.toJSON())
        

        #adminML.closeConnection()
        adminUser.closeConnection()

        return render_template('recomendacion.html', recomendations = recomendations, username=username)
    else:
        return render_template('landing.html')
示例#3
0
def index():
    if 'username' not in session.keys():
        return redirect(url_for("login"))
    username = session["username"]
    
    adminUser = AdminUser()
    hasReviews = adminUser.getByUsername(username).hasReviews()
    if hasReviews:
        return redirect(url_for("recomendate"))
    else:
        return redirect(url_for("review"))
示例#4
0
def quienessomos():
    if 'username' not in session.keys():
        return render_template('landing.html')

    username = session["username"]
    adminUser = AdminUser()
    user = adminUser.getByUsername(username)

    #adminML = AdminMachineLearning()
    #correlations = adminML.getMachineLearning()
        

    #adminML.closeConnection()
    adminUser.closeConnection()

    return render_template('quienessomos.html', username=username)
示例#5
0
def register():
    error = None
    if request.method == 'POST':
        username = request.form.getlist('user')[0]
        password = request.form.getlist('password')[0]
        adminUser = AdminUser()
        user = adminUser.getByUsername(username)
        if type(user) != User:
            user = User(username, password)
            adminUser.addUser(user)
            return login_user(username)
        else:
            error = "¡Este nombre de usuario ya existe!"
    # the code below is executed if the request method
    # was GET or the credentials were invalid
    if 'username' in session.keys():
        return redirect(url_for("review")) 
    return render_template('register.html', error = error)
示例#6
0
def login():
    error = None
    if request.method == 'POST':
        username = request.form.getlist('user')[0]
        password = request.form.getlist('password')[0]
        adminUser = AdminUser()
        user = adminUser.getByUsername(username)
        if type(user) == User:
            user = adminUser.getByUsernameAndPassword(username, password)
            if type(user) == User:
                return login_user(username)
            else:
                error = "¡Has introducido una contraseña incorrecta!"
        else:
            error = "¡Este nombre de usuario no existe!"
    # the code below is executed if the request method
    # was GET or the credentials were invalid
    if 'username' in session.keys():
        return redirect(url_for("review")) 
    return render_template('login.html', error=error)
示例#7
0
def review():
    if 'username' not in session.keys():
        return render_template('landing.html')
    adminExperience = AdminExperience()
    username = session["username"]
    adminUser = AdminUser()
    if request.method == 'POST':        
        experience_name = request.form.getlist('experience')[0]
        rating_value = float(request.form.getlist('rating')[0])
        experience = adminExperience.getByName(experience_name)
        rating = Rating(rating_value)
        if experience == None:
            return 420
        # if rating_value > Rating.getMax() or rating_value < Rating.getMin():
        #     return 421

        user = adminUser.getByUsername(username)
        review = Review(experience, rating)
        user.addReview(review)

        adminUser.updateUser(user)

        adminExperience.closeConnection()
        adminUser.closeConnection()

        # Redirigimos a recomendar
        return redirect(url_for("recomendate"))
    else:
        experiences = []
        types = []
        hasReviews = adminUser.getByUsername(username).hasReviews()
        for experience in adminExperience.getAll():
            experiences.append(experience.toJSON())
            type = experience.getType()
            if type not in types:
                types.append(type)
        return render_template('review.html', hasReviews=hasReviews, username=username, experiences = experiences, types = types)
        if not rating.isdecimal() or float(rating) < Rating.getMin() or float(rating) > Rating.getMax():
            print ("Valoración no válida")        
        else:
            return float(rating)

adminExperiences = AdminExperience()
experiences = adminExperiences.getAll()
tab = 0
for experience in experiences:
    if tab < len(experience.getName()):
        tab = len(experience.getName())
cadena = "%-"+str(tab)+"s"

adminExperiences.closeConnection()

userDao = AdminUser()
#nombre = input("Nombre: ")
#password = input ("Contraseña: ")
nombre = "carlos"
user = userDao.getByUsername(nombre)
print ("leido")


userDao.closeConnection()

#print (cadena %"EXPERIENCIA", "\t%s" %"TIPO")
#for experience in experiences:
#    if experience.getType() == "restaurant":
#        print(cadena %experience.getName(), "\t%s" %experience.getType())