コード例 #1
0
def mine():
    # Start with carpools you're driving in
    carpools = current_user.get_driving_carpools().all()

    # Add in carpools you have ride requests for
    carpools.extend(
        [req.carpool for req in current_user.get_ride_requests_query()])

    # Then sort by departure date
    carpools.sort(key=lambda c: c.leave_time)

    return render_template('carpools/mine.html', carpools=carpools)
コード例 #2
0
def mine():
    carpools = {'future': [], 'past': []}
    # Start with carpools you're driving in
    for carpool in current_user.get_driving_carpools():
        carpools['future' if carpool.future else 'past'].append(carpool)

    # Add in carpools you have ride requests for
    for req in current_user.get_ride_requests_query():
        carpools['future' if req.carpool.future else 'past'].append(req.carpool)

    # Then sort by departure date
    carpools['future'].sort(key=lambda c: c.leave_time)
    carpools['past'].sort(key=lambda c: c.leave_time)

    return render_template('carpools/mine.html', carpools=carpools)
コード例 #3
0
ファイル: views.py プロジェクト: kcraybould/nomad
def profile_delete():
    profile_form = ProfileDeleteForm()

    if profile_form.validate_on_submit():
        if profile_form.name.data != current_user.name:
            flash("The text you entered did not match your name.", 'error')
            return redirect(url_for('auth.profile'))

        try:
            # Delete the ride requests for this user
            for req in current_user.get_ride_requests_query():
                current_app.logger.info("Deleting user %s's request %s",
                                        current_user.id, req.id)
                email_driver_rider_cancelled_request(req, req.carpool,
                                                     current_user)
                db.session.delete(req)

            # Delete the carpools for this user
            for pool in current_user.get_driving_carpools():
                current_app.logger.info("Deleting user %s's pool %s",
                                        current_user.id, pool.id)
                cancel_carpool(pool)
                db.session.delete(pool)

            # Delete the user's account
            current_app.logger.info("Deleting user %s", current_user.id)
            user = Person.query.get(current_user.id)
            db.session.delete(user)
            db.session.commit()

            logout_user()
        except:
            db.session.rollback()
            current_app.logger.exception("Problem deleting user account")
            flash(
                "There was a problem deleting your profile. "
                "Try again or contact us.", 'error')
            return redirect(url_for('auth.profile'))

        flash("You deleted your profile.", 'success')

        return redirect(url_for('carpool.index'))

    return render_template('profiles/delete.html', form=profile_form)
コード例 #4
0
ファイル: views.py プロジェクト: jmcarp/nomad
def mine():
    carpools = current_user.get_driving_carpools()

    return render_template('carpools/mine.html', carpools=carpools)
コード例 #5
0
def new_rider(carpool_uuid):
    carpool = Carpool.uuid_or_404(carpool_uuid)

    if carpool.canceled:
        flash("This carpool has been canceled and can no longer be edited.", 'error')
        return redirect(url_for('carpool.details', uuid=carpool.uuid))

    if current_user.is_driver(carpool):
        flash("You can't request a ride on a carpool you're driving in", 'error')
        return redirect(url_for('carpool.details', uuid=carpool.uuid))

    if not current_user.gender:
        flash("Please specify your gender before creating a carpool request")
        session['next'] = url_for('carpool.new_rider', carpool_uuid=carpool.uuid)
        return redirect(url_for('auth.profile'))

    # max 10 rides for non-admin users
    if not current_user.has_roles('admin'):
        now = datetime.datetime.now().replace(tzinfo=tz.gettz('UTC'))
        # ride requests in future, active carpools
        pending_req = current_user.get_ride_requests_query().\
            filter(RideRequest.carpool_id == Carpool.id).\
            filter(Carpool.canceled.is_(False)).\
            filter(Carpool.leave_time > now)
        driving = current_user.get_driving_carpools().\
            filter(Carpool.canceled.is_(False)).\
            filter(Carpool.leave_time > now)
        if pending_req.count() + driving.count() >= 10:
            flash('''
                Sorry, you can be in at most ten carpools.
                Please try again after some of your carpools have finished.
            ''', 'error')
            return render_template('carpools/error.html')


    rider_form = RiderForm()
    if rider_form.validate_on_submit():
        if carpool.seats_available < 1:
            flash("There isn't enough space for you on "
                  "this ride. Try another one?", 'error')
            return redirect(url_for('carpool.details', uuid=carpool.uuid))

        if current_user.get_ride_request_in_carpool(carpool):
            flash("You've already requested a seat on "
                  "this ride. Try another one or cancel your "
                  "existing request.", 'error')
            return redirect(url_for('carpool.details', uuid=carpool.uuid))

        rr = RideRequest(
            carpool_id=carpool.id,
            person_id=current_user.id,
            notes=rider_form.notes.data,
            status='requested',
        )
        db.session.add(rr)
        db.session.commit()

        flash("Your ride request has been sent to the driver for approval! "
              "You'll get an email when you are approved.", 'success')
        _email_driver_ride_requested(carpool, rr, current_user)

        return redirect(url_for('carpool.details', uuid=carpool.uuid))

    return render_template('carpools/add_rider.html', form=rider_form)