Esempio n. 1
0
def account():
    if "user" in session:
        global current_user
        passenger = ''
        driver = ''
        user = find_by_email(session["user"])
        current_user = user
        account_form = AccountForm()

        if request.method == 'GET':
            account_form.email.data = user["email"]
            account_form.username.data = user["username"]
            account_form.first_name.data = user["first_name"]
            account_form.last_name.data = user["last_name"]
            account_form.address.data = user["address"]
            account_form.phone_number.data = user["phone"]
        if account_form.validate_on_submit(
        ) and request.form.get('select') != 'not selected':
            update_account(
                session["user"], account_form.username.data,
                account_form.first_name.data, account_form.last_name.data,
                account_form.email.data, account_form.phone_number.data,
                account_form.address.data, request.form.get('select'))
            session["user"] = account_form.email.data

            if account_form.picture.data:
                profile_image = account_form.picture.data
                save_picture(profile_image, session["user"])
            current_user = find_by_email(session["user"])
            flash('Sikeres frissítés !', 'success')
        return render_template('account.html',
                               account_form=account_form,
                               user=current_user)
    return redirect(url_for('index'))
Esempio n. 2
0
def passenger():
    if "user" in session:
        user = find_by_email(session["user"])
        roads = reserved_roads(session['user'])
        global reserved_post_azon

        if reserved_post_azon:
            current_reserved_post = ObjectId(reserved_post_azon)
        else:
            current_reserved_post = ''
        reserved_post_azon = ''
        posts = []
        if roads:
            for _id in roads['reserved_roads']:
                post = find_reserved_post(_id['post_id'])
                for i in post:
                    posts.append((i, _id['reserved_seats']))

            return render_template('passenger.html',
                                   drivers=posts,
                                   user=user,
                                   current_reserved_post=current_reserved_post)
        else:
            return render_template('passenger.html',
                                   drivers=posts,
                                   user=user,
                                   current_reserved_post=current_reserved_post)
Esempio n. 3
0
def create_post():
    if "user" in session:
        user = find_by_email(session["user"])
        modal_attr = ""
        today_date = datetime.now().strftime('%Y-%m-%d')
        post_form = CreatePostForm()
        if post_form.validate_on_submit(
        ) and request.form.get('select_vehicle') != 'not selected':
            if find_by_email(session["user"])["phone"] == '':
                modal_attr = "myModal2"
                return render_template('create_post.html',
                                       post_form=post_form,
                                       today_date=today_date,
                                       modal_attr=modal_attr,
                                       user=user)
            if find_by_email(session["user"])["passenger_or_driver"] == 'Utas':
                modal_attr = "myModal3"
                return render_template('create_post.html',
                                       post_form=post_form,
                                       today_date=today_date,
                                       modal_attr=modal_attr,
                                       user=user)
            create_post_db(session["user"], post_form.car_brand.data,
                           post_form.car_model.data, post_form.car_color.data,
                           post_form.date_of_manufacture.data,
                           post_form.seats.data,
                           post_form.place_of_departure.data,
                           post_form.destination.data, post_form.price.data,
                           post_form.note.data, post_form.house_to_house.data,
                           post_form.package_delivery.data,
                           request.form.get('select_vehicle'),
                           post_form.travel_date.data.strftime('%Y-%m-%d'),
                           post_form.start_time.data.strftime('%H:%M'),
                           post_form.arrival_time.data.strftime('%H:%M'))

            modal_attr = "myModal"
        elif request.method == 'POST' and request.form.get(
                'select_vehicle') == 'not selected':
            flash(f'Válassz a listából !', 'danger')
        return render_template('create_post.html',
                               post_form=post_form,
                               today_date=today_date,
                               modal_attr=modal_attr,
                               user=user)
    return redirect(url_for('index'))
Esempio n. 4
0
def home():
    if "user" in session:
        today_date = datetime.now().strftime('%Y-%m-%d')
        search_form = SearchForm()
        user = find_by_email(session["user"])
        passengers = []
        if user["address"]:
            drivers = find_posts_by_address(user['address'])
            drivers = [driver for driver in drivers if 'posts' in driver]
            for index, i in enumerate(drivers):
                j = i.pop('_id', None)
                drivers[index] = {**j, **i}
        else:
            drivers = find_posts()
            drivers = [driver for driver in drivers if 'posts' in driver]
            post_temp = []

            for driver in drivers:
                for post in driver['posts']:
                    if post['seats'] > 0:
                        post_temp.append(post)
                driver['posts'] = post_temp[:]
                post_temp.clear()

        if search_form.submit_search.data:
            place_of_departure = search_form.honnan.data
            destination = search_form.hova.data
            estimated_travel_date = search_form.estimated_travel_date.data
            if estimated_travel_date:
                estimated_travel_date = estimated_travel_date.strftime(
                    '%Y-%m-%d')
            drivers = search_calc(place_of_departure, destination,
                                  estimated_travel_date)
            drivers = [post for post in drivers]
            for index, i in enumerate(drivers):
                j = i.pop('_id', None)
                drivers[index] = {**j, **i}
            return render_template('home.html',
                                   drivers=drivers,
                                   user=user,
                                   search_form=search_form,
                                   today_date=today_date)
        return render_template('home.html',
                               drivers=drivers,
                               user=user,
                               search_form=search_form,
                               today_date=today_date,
                               passengers=passengers)

    return redirect(url_for('index'))
Esempio n. 5
0
def driver():
    if "user" in session:
        user = find_by_email(session["user"])
        posts_and_passengers = find_posts_and_passengers(session["user"])
        if posts_and_passengers:
            posts_and_passengers = posts_and_passengers['posts']
        else:
            posts_and_passengers = []
        return render_template('driver.html',
                               posts_and_passengers=posts_and_passengers,
                               user=user,
                               reserved_seats_by_passenger=passenger_seats,
                               update_post=update_post)
    return redirect(url_for('index'))
Esempio n. 6
0
def reserve():
    if request.method == 'POST':
        reserve_seats(request.form.get('post_azon'),
                      int(request.form.get('free_seats')))
        user = find_by_email(session["user"])
        insert_passengers_for_driver(request.form.get('post_azon'),
                                     user["email"], user["username"],
                                     user["first_name"], user["last_name"],
                                     user["phone"],
                                     int(request.form.get('free_seats')))
        insert_reserved_posts_for_passenger(
            request.form.get('post_azon'), session['user'],
            int(request.form.get('free_seats')))
        global reserved_post_azon
        reserved_post_azon = request.form.get('post_azon')
        return redirect(url_for('passenger'))
    return redirect(url_for('home'))
Esempio n. 7
0
def update_post():
    if "user" in session:
        global updt_post_id
        user = find_by_email(session["user"])
        modal_attr = ""
        today_date = datetime.now().strftime('%Y-%m-%d')
        post_form = CreatePostForm()
        update_p_id_temp = request.form.get('updt_post_id')
        if update_p_id_temp:
            global update
            updt_post_id = update_p_id_temp
            actual_post = find_post_by_post_id(update_p_id_temp)
            actual_post = [p['posts'] for p in actual_post]
            actual_post = actual_post.pop().pop()
            post_form.post_fill(
                car_brand=actual_post['car_brand'],
                car_model=actual_post['car_model'],
                car_color=actual_post['car_color'],
                date_of_manufacture=actual_post['date_of_manufacture'],
                seats=actual_post['seats'],
                place_of_departure=actual_post['place_of_departure'],
                destination=actual_post['destination'],
                price=actual_post['price'],
                house_to_house=actual_post['house_to_house'],
                note=actual_post['note'],
                package_delivery=actual_post['package_delivery'],
                travel_date=actual_post['travel_date'],
                start_time=actual_post['start_time'],
                arrival_time=actual_post['arrival_time'])
        else:
            actual_post = {'vehicle_type': ''}
        if post_form.validate_on_submit(
        ) and request.form.get('select_vehicle') != 'not selected':
            if find_by_email(session["user"])["phone"] == '':
                modal_attr = "myModal2"
                return render_template(
                    'create_post.html',
                    post_form=post_form,
                    today_date=today_date,
                    modal_attr=modal_attr,
                    user=user,
                    vehicle_type=actual_post['vehicle_type'])
            if find_by_email(session["user"])["passenger_or_driver"] == 'Utas':
                modal_attr = "myModal3"
                return render_template(
                    'create_post.html',
                    post_form=post_form,
                    today_date=today_date,
                    modal_attr=modal_attr,
                    user=user,
                    vehicle_type=actual_post['vehicle_type'])
            update_post_db(updt_post_id, post_form.car_brand.data,
                           post_form.car_model.data, post_form.car_color.data,
                           post_form.date_of_manufacture.data,
                           post_form.seats.data,
                           post_form.place_of_departure.data,
                           post_form.destination.data, post_form.price.data,
                           post_form.note.data, post_form.house_to_house.data,
                           post_form.package_delivery.data,
                           request.form.get('select_vehicle'),
                           post_form.travel_date.data.strftime('%Y-%m-%d'),
                           post_form.start_time.data.strftime('%H:%M'),
                           post_form.arrival_time.data.strftime('%H:%M'))

            modal_attr = "myModal"
            update = True
        elif request.method == 'POST' and request.form.get(
                'select_vehicle') == 'not selected':
            flash(f'Válassz a listából !', 'danger')
        return render_template('create_post.html',
                               post_form=post_form,
                               today_date=today_date,
                               modal_attr=modal_attr,
                               user=user,
                               vehicle_type=actual_post['vehicle_type'],
                               update=True)
    return redirect(url_for('index'))
Esempio n. 8
0
 def validate_username(self, username):
     if username.data != find_by_email(session["user"])["username"]:
         if existing_username(username.data):
             raise ValidationError('Ez a felhaználónév már létezik')