Ejemplo n.º 1
0
def profile(username):
    list1 = []
    if "logged_in" in session and session['logged_in']:
        a = True
        following = False
        user = database.get_user(username)
        pics = database.get_photos_by_user_id(user.id)
        followers = database.get_followers_for(user.id)
        for i in pics:
            a = i.id
            list1.append(a)
        list1.sort(reverse=True)
        if user.id == session["id"]:
            a = False

        for i in range(len(followers)):
            if followers[i].followed_by == session["id"]:
                following = True
        return render_template("profilepage.html",
                               user=user,
                               pics=pics,
                               a=a,
                               following=following)
    else:
        return redirect(url_for("home_page"))
Ejemplo n.º 2
0
def signin():
    passs = None
    uuuu = None
    if "logged_in" in session and session['logged_in']:
        return redirect(url_for("home_page"))
    else:
        if request.method == 'POST':
            u = request.form['username']
            p = request.form['password']
            person = database.get_user(u)
            if database.get_user(u) == None:
                not_u = True
                return render_template("login.html", not_u=not_u)
            elif person.username == u and person.password == p:
                a = database.get_photos_by_user_id(person.id)
                session['logged_in'] = True
                session['id'] = person.id
                session['username'] = person.username
                session['password'] = person.password
                session['email'] = person.email
                session['followers'] = person.followers
                session['following'] = person.following
                session['profile_pic'] = person.profile_pic
                for b in a:
                    session['pics'] = b.pic
                return redirect(url_for("home_page"))
            elif person.username == u and person.password != p:
                not_p = True
                return render_template("login.html", not_p=not_p)
        else:
            return render_template("login.html")
Ejemplo n.º 3
0
def following_user(username):
    if "logged_in" in session and session['logged_in']:
        following = []
        number_of_photos = []
        least_p = []
        most_p = []
        has_photos = []
        user = database.get_user(username)
        following_2 = database.get_following_for(user.id)
        for i in range(len(following_2)):
            following.append(database.get_user_by_id(following_2[i].followed))
            number_of_photos.append(
                len(database.get_photos_by_user_id(following_2[i].followed)))

            prices = []
            if number_of_photos[i] == 0:
                has_photos.append(False)

            else:
                has_photos.append(True)
                for j in database.get_photos_by_user_id(
                        following_2[i].followed):
                    converted_p = converter.convert(j.price, j.currency, 'USD')
                    prices.append(converted_p)
                least_p.append(min(prices))
                most_p.append(max(prices))

        return render_template("following_page.html",
                               following=following,
                               user=user,
                               number_of_photos=number_of_photos,
                               least_p=least_p,
                               most_p=most_p,
                               has_photos=has_photos)
    else:
        return redirect(url_for("home_page"))
Ejemplo n.º 4
0
def results():
    if "logged_in" in session and session['logged_in']:
        if request.method == 'POST':
            a = None
            user_search = None
            results = []
            if request.form['search_type'] == "users":
                number_of_photos = []
                least_p = []
                most_p = []
                has_photos = []
                all_users = database.get_all_users()
                for i in range(len(all_users)):
                    found = search(request.form['search'].lower(),
                                   all_users[i].username.lower())
                    if found == True:
                        if all_users[i] not in results:
                            results.append(all_users[i])
                            number_of_photos.append(
                                len(
                                    database.get_photos_by_user_id(
                                        all_users[i].id)))
                            prices = []
                            if number_of_photos[-1] == 0:
                                has_photos.append(False)

                            else:
                                has_photos.append(True)
                                for j in database.get_photos_by_user_id(
                                        all_users[i].id):
                                    converted_p = converter.convert(
                                        j.price, j.currency, 'USD')
                                    prices.append(converted_p)
                                least_p.append(min(prices))
                                most_p.append(max(prices))
                # results = database.get_users(request.form['search'])
                user_search = True
                if results == []:
                    a = True
                return render_template("searchpage.html",
                                       results=results,
                                       a=a,
                                       user_search=user_search,
                                       search=True,
                                       number_of_photos=number_of_photos,
                                       least_p=least_p,
                                       most_p=most_p,
                                       has_photos=has_photos)

            if request.form['search_type'] == "images":
                # path = database.get_photo_id_by_keywords(request.form['search'])
                # print(path)
                # for i in path:
                # 	results.append(database.get_photo_by_id(i.pic_id))
                all_keywords = database.get_all_keywords()
                for i in range(len(all_keywords)):
                    found = search(request.form['search'].lower(),
                                   all_keywords[i].keyword.lower())
                    if found == True:
                        photo = database.get_photo_by_id(
                            all_keywords[i].pic_id)
                        if photo not in results:
                            results.append(photo)
                user_search = False
                if results == []:
                    a = True
                return render_template("searchpage.html",
                                       results=results,
                                       a=a,
                                       user_search=user_search,
                                       search=True)
            else:
                return redirect(url_for("home_page"))
        else:
            return render_template("searchpage.html")
    else:
        return redirect(url_for("home_page"))