示例#1
0
def show_entry(entry_id):

    if session.get('current_user'):

        entry = crud.get_entry_by_id(entry_id)

        if entry.user_id != session.get('current_user'):

            return redirect(f'/entries/view_only/{entry_id}')

        city_id = entry.city_id

        city = crud.get_city_by_id(city_id)

        photo = crud.get_photo_by_entry(entry_id)

        ratings = crud.get_entry_ratings(entry_id)

        created_at_raw = entry.created_at

        created_at = str(created_at_raw)[0:10]

        total_ratings = 0

        for rating in ratings:
            total_ratings += 1

        return render_template('entry_details.html',
                               entry=entry,
                               city=city,
                               photo=photo,
                               total_ratings=total_ratings,
                               created_at=created_at)
示例#2
0
def view_only_entry(entry_id):

    entry = crud.get_entry_by_id(entry_id)

    user = crud.get_user_by_id(entry.user_id)

    city_id = entry.city_id

    city = crud.get_city_by_id(city_id)

    ratings = crud.get_entry_ratings(entry_id)

    total_ratings = 0

    for rating in ratings:
        total_ratings += 1

    photo = crud.get_photo_by_entry(entry_id)

    created_at_raw = entry.created_at

    created_at = str(created_at_raw)[0:10]

    return render_template('see_entry_only.html',
                           user=user,
                           entry=entry,
                           city=city,
                           photo=photo,
                           total_ratings=total_ratings,
                           created_at=created_at)
示例#3
0
def city_specific_entries(city_id):

    entries = crud.get_city_entries_ordered_by_ratings_count(city_id)[::-1]
    city = crud.get_city_by_id(city_id)

    return render_template('city_specific_entries.html',
                           entries=entries,
                           city=city)
示例#4
0
def update_details():

    user_id = session['current_user']
    user = crud.get_user_by_id(user_id)

    new_email = request.form.get('email_search')
    new_username = request.form.get('username_search')
    print(new_username)
    print("*" * 100)

    new_password = request.form.get('password')
    new_city = request.form.get('city_search')

    city = crud.get_city_by_id(new_city)

    image_uploaded = request.files.get('image_upload')
    new_description = request.form.get('description')
    new_instagram = request.form.get('instagram')
    new_twitter = request.form.get('twitter')
    new_website = request.form.get('website')

    profile = crud.get_user_profile(user_id)

    returned_url = None

    if image_uploaded:
        response = cloudinary.uploader.upload(image_uploaded)
        returned_url = response['url']

    all_username = crud.search_username(new_username)

    all_email = crud.search_email(new_email)

    print(all_username)
    print(all_email)
    print("*" * 100)

    if all_username or all_email:
        flash('That username or email is taken already, try another one!')

    else:
        crud.update_user(user, new_email, new_password, new_username, city)

    if not profile:
        crud.create_profile(user, new_description, new_instagram, new_twitter,
                            new_website, returned_url)
        flash("user details created")

    else:
        crud.update_profile(user, returned_url, new_description, new_instagram,
                            new_twitter, new_website)
        flash("user details updated")

    return redirect('/users/your_entries')
示例#5
0
def register_user():
    """Create a new user."""

    email = request.form.get('email')
    password = request.form.get('password')
    username = request.form.get('username')
    city_id = request.form.get('city_search')
    city = crud.get_city_by_id(city_id)

    user = crud.get_user_by_email(email)

    if user:
        flash('Cannot create an account with that email. Try again.')
    else:
        crud.create_user(email, password, username, city)
        user = crud.get_user_by_email(email)
        session['current_user'] = user.user_id
        flash('Account created! You are logged in!')

    return redirect('/')
示例#6
0
def route_to_entry(city_id):

    city = crud.get_city_by_id(city_id)
    entry = crud.get_entry_by_city(city_id)
    entry_id = entry.entry_id

    photo = crud.get_photo_by_entry(entry_id)

    ratings = crud.get_entry_ratings(entry_id)

    total_ratings = 0

    for rating in ratings:
        total_ratings += 1

    created_at_raw = entry.created_at

    created_at = str(created_at_raw)[0:10]

    return redirect('/entries/{}'.format(entry_id))