Exemplo n.º 1
0
def move_hydration(crew=None):
    """Action route from button on main page. Initiates moving equipment to selected crew in dropdown."""
    if crew is not None and current_user.is_admin:
        hydration_numbers = models.create_list(crew, 'hydration')
        response = make_response(redirect(url_for('admin')))
    else:
        response = make_response(redirect(url_for('main')))
        hydration_numbers = models.create_list(current_user.crew, 'hydration')
    data = get_saved_data()
    data.update(dict(request.form.items()))
    response.set_cookie('user_input', json.dumps(data))
    hydration_form = forms.HydrationForm()
    hydration_form.hydrations.choices = hydration_numbers
    treater_name = request.form.get('user_name')
    if hydration_form.validate_on_submit():
        if current_user.is_admin:
            if models.check_crew(hydration_form.hydrations_crew.data,
                                 hydration_form.hydrations.data):
                flash('{} is already on {} crew.'.format(
                    hydration_form.hydrations.data,
                    hydration_form.hydrations_crew.data))
                return response
            else:
                move(hydration_form.hydrations, hydration_form.hydrations_crew,
                     treater_name)
                return response

        elif hydration_form.hydrations_crew.data == current_user.crew:
            flash('{} is already on {} crew.'.format(
                hydration_form.hydrations.data,
                hydration_form.hydrations_crew.data))
            return response
        else:
            move(hydration_form.hydrations, hydration_form.hydrations_crew,
                 treater_name)
            return response
    else:
        response = redirect(url_for('main'))
        return response
Exemplo n.º 2
0
def move_pump(crew=None):
    """Action route from button on main page. Initiates moving equipment to selected crew in dropdown."""
    if crew is not None and current_user.is_admin:
        pump_numbers = models.create_list(crew, 'pump')
        response = make_response(redirect(url_for('admin')))
    else:
        pump_numbers = models.create_list(current_user.crew, 'pump')
        response = make_response(redirect(url_for('main')))
    data = get_saved_data()
    data.update(dict(request.form.items()))
    response.set_cookie('user_input', json.dumps(data))
    pump_form = forms.PumpForm()
    pump_form.pumps.choices = pump_numbers
    treater_name = request.form.get('user_name')
    if pump_form.validate_on_submit():
        if request.form['button'] == 'maintenance':
            response = make_response(
                redirect(url_for('maintenance', pump=pump_form.pumps.data)))
            return response
        if current_user.is_admin:
            if models.check_crew(pump_form.pumps_crew.data,
                                 pump_form.pumps.data):
                flash('{} is already on {} crew.'.format(
                    pump_form.pumps.data, pump_form.pumps_crew.data))
                return response
            else:
                move(pump_form.pumps, pump_form.pumps_crew, treater_name)
                return response
        elif pump_form.pumps_crew.data == current_user.crew:
            flash('{} is already on {} crew.'.format(
                pump_form.pumps.data, pump_form.pumps_crew.data))
            return response
        else:
            move(pump_form.pumps, pump_form.pumps_crew, treater_name)
            return response
    else:
        response = redirect(url_for('main'))
        flash('Please Select a Pump')
        return response