Пример #1
0
def index():

    form = UploadForm(pilot=g.current_user.id)

    if form.validate_on_submit():
        return index_post(form)

    return render_template('upload/form.jinja', form=form)
Пример #2
0
def index():
    # Create/parse file selection form
    form = UploadForm(pilot=g.current_user.id)

    if form.validate_on_submit():
        return index_post(form)

    return render_template('upload/form.jinja', form=form)
Пример #3
0
def index():
    if request.values.get('stage', type=int) == 1:
        # Parse update form
        num_flights = request.values.get('num_flights', 0, type=int)

        flights = []
        flight_id_list = []
        form_error = False

        for prefix in range(1, num_flights + 1):
            flight_id = request.values.get('{}-sfid'.format(prefix), None, type=int)
            name = request.values.get('{}-name'.format(prefix))

            try:
                status = UploadStatus(request.values.get('{}-status'.format(prefix), type=int))
            except ValueError:
                raise BadRequest('Status unknown')

            flight, trace, form = check_update_form(prefix, flight_id, name, status)

            flights.append((name, flight, status, str(prefix), trace, form))

            if form and form.validate_on_submit():
                _update_flight(flight_id,
                               form.model_id.data,
                               form.registration.data,
                               form.competition_id.data,
                               form.takeoff_time.data,
                               form.scoring_start_time.data,
                               form.scoring_end_time.data,
                               form.landing_time.data)
                flight_id_list.append(flight_id)
            elif form:
                form_error = True

        if form_error:
            return render_template(
                'upload/result.jinja', num_flights=num_flights, flights=flights, success=True)
        elif flight_id_list:
            flash(_('Your flight(s) have been successfully published.'))
            return redirect(url_for('flights.list', ids=','.join(str(x) for x in flight_id_list)))
        else:
            return redirect(url_for('flights.today'))

    else:
        # Create/parse file selection form
        form = UploadForm(pilot=g.current_user.id)

        if form.validate_on_submit():
            return index_post(form)

        return render_template('upload/form.jinja', form=form)
Пример #4
0
def index():
    if request.values.get('stage', type=int) == 1:
        # Parse update form
        num_flights = request.values.get('num_flights', 0, type=int)

        flights = []
        flight_id_list = []
        form_error = False

        for prefix in range(1, num_flights + 1):
            flight_id = request.values.get('{}-sfid'.format(prefix), None, type=int)
            name = request.values.get('{}-name'.format(prefix))

            try:
                status = UploadStatus(request.values.get('{}-status'.format(prefix), type=int))
            except ValueError:
                raise BadRequest('Status unknown')

            flight, form = check_update_form(prefix, flight_id, name, status)

            flights.append((name, flight, status, str(prefix), form))

            if form and form.validate_on_submit():
                _update_flight(flight_id,
                               form.model_id.data,
                               form.registration.data,
                               form.competition_id.data)
                flight_id_list.append(flight_id)
            elif form:
                form_error = True

        if form_error:
            return render_template(
                'upload/result.jinja', num_flights=num_flights, flights=flights, success=True)
        elif flight_id_list:
            flash(_('Your flight(s) have been successfully published.'))
            return redirect(url_for('flights.list', ids=','.join(str(x) for x in flight_id_list)))
        else:
            return redirect(url_for('flights.today'))

    else:
        # Create/parse file selection form
        form = UploadForm(pilot=g.current_user.id)

        if form.validate_on_submit():
            return index_post(form)

        return render_template('upload/form.jinja', form=form)
Пример #5
0
def index():
    if request.values.get('stage', type=int) == 1:
        # Parse update form
        num_flights = request.values.get('num_flights', 0, type=int)

        flights = []
        flight_id_list = []
        form_error = False

        for prefix in range(1, num_flights + 1):
            name = request.values.get('{}-name'.format(prefix))

            try:
                status = UploadStatus(request.values.get('{}-status'.format(prefix), type=int))
            except ValueError:
                raise BadRequest('Status unknown')

            flight, fp, form = check_update_form(prefix, status)

            if fp:
                trace = _encode_flight_path(fp, flight.qnh)
                infringements = get_airspace_infringements(fp, qnh=flight.qnh)
            else:
                trace = None
                infringements = {}

            cache_key = None

            if form and not infringements:
                # remove airspace field from form if no airspace infringements found
                del form.airspace_usage

            elif form and infringements:
                # if airspace infringements found create cache_key from flight id and user id
                cache_key = hashlib.sha1(str(flight.id) + '_' + str(g.current_user.id)).hexdigest()

            airspace = db.session.query(Airspace) \
                                 .filter(Airspace.id.in_(infringements.keys())) \
                                 .all()

            flights.append((name, flight, status, str(prefix), trace, airspace, cache_key, form))

            if form and form.validate_on_submit():
                _update_flight(flight.id,
                               fp,
                               form.model_id.data,
                               form.registration.data,
                               form.competition_id.data,
                               form.takeoff_time.data,
                               form.scoring_start_time.data,
                               form.scoring_end_time.data,
                               form.landing_time.data,
                               form.pilot_id.data, form.pilot_name.data,
                               form.co_pilot_id.data, form.co_pilot_name.data)
                flight_id_list.append(flight.id)
            elif form:
                form_error = True

        if form_error:
            return render_template(
                'upload/result.jinja', num_flights=num_flights, flights=flights, success=True)
        elif flight_id_list:
            flash(_('Your flight(s) have been successfully published.'))
            return redirect(url_for('flights.list', ids=','.join(str(x) for x in flight_id_list)))
        else:
            return redirect(url_for('flights.today'))

    else:
        # Create/parse file selection form
        form = UploadForm(pilot=g.current_user.id)

        if form.validate_on_submit():
            return index_post(form)

        return render_template('upload/form.jinja', form=form)
Пример #6
0
def index():
    if request.values.get('stage', type=int) == 1:
        # Parse update form
        num_flights = request.values.get('num_flights', 0, type=int)

        flights = []
        flight_id_list = []
        form_error = False

        for prefix in range(1, num_flights + 1):
            name = request.values.get('{}-name'.format(prefix))

            try:
                status = UploadStatus(request.values.get('{}-status'.format(prefix), type=int))
            except ValueError:
                raise BadRequest('Status unknown')

            flight, fp, form = check_update_form(prefix, status)

            if fp:
                trace = _encode_flight_path(fp, flight.qnh)
                infringements = get_airspace_infringements(fp, qnh=flight.qnh)
            else:
                trace = None
                infringements = {}

            cache_key = None

            if form and not infringements:
                # remove airspace field from form if no airspace infringements found
                del form.airspace_usage

            elif form and infringements:
                # if airspace infringements found create cache_key from flight id and user id
                cache_key = hashlib.sha1(str(flight.id) + '_' + str(g.current_user.id)).hexdigest()

            airspace = db.session.query(Airspace) \
                                 .filter(Airspace.id.in_(infringements.keys())) \
                                 .all()

            flights.append((name, flight, status, str(prefix), trace, airspace, cache_key, form))

            if form and form.validate_on_submit():
                _update_flight(flight.id,
                               fp,
                               form.model_id.data,
                               form.registration.data,
                               form.competition_id.data,
                               form.takeoff_time.data,
                               form.scoring_start_time.data,
                               form.scoring_end_time.data,
                               form.landing_time.data,
                               form.pilot_id.data, form.pilot_name.data,
                               form.co_pilot_id.data, form.co_pilot_name.data)
                flight_id_list.append(flight.id)
            elif form:
                form_error = True

        if form_error:
            return render_template(
                'upload/result.jinja', num_flights=num_flights, flights=flights, success=True)
        elif flight_id_list:
            flash(_('Your flight(s) have been successfully published.'))
            return redirect(url_for('flights.list', ids=','.join(str(x) for x in flight_id_list)))
        else:
            return redirect(url_for('flights.today'))

    else:
        # Create/parse file selection form
        form = UploadForm(pilot=g.current_user.id)

        if form.validate_on_submit():
            return index_post(form)

        return render_template('upload/form.jinja', form=form)