Ejemplo n.º 1
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
Ejemplo n.º 2
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
Ejemplo n.º 3
0
def main(crew=None):
    """Builds initial main template. Buttons go to different routes that perform actions and redirect back to here."""
    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))
    movement_stream = models.Movement.select().order_by(
        models.Movement.timestamp.desc()).limit(10)
    if crew is not None and current_user.is_admin:
        pump_numbers = models.create_list(crew, 'pump')
        blender_numbers = models.create_list(crew, 'blender')
        hydration_numbers = models.create_list(crew, 'hydration')
        float_numbers = models.create_list(crew, 'float')
    else:
        pump_numbers = models.create_list(current_user.crew, 'pump')
        blender_numbers = models.create_list(current_user.crew, 'blender')
        hydration_numbers = models.create_list(current_user.crew, 'hydration')
        float_numbers = models.create_list(current_user.crew, 'float')
    pump_form = forms.PumpForm()
    search_form = forms.SearchForm()
    pump_form.pumps.choices = pump_numbers
    blender_form = forms.BlenderForm()
    blender_form.blenders.choices = blender_numbers
    float_form = forms.FloatForm()
    float_form.floats.choices = float_numbers
    hydration_form = forms.HydrationForm()
    hydration_form.hydrations.choices = hydration_numbers

    return render_template('main.html',
                           saves=get_saved_data(),
                           pump_form=pump_form,
                           blender_form=blender_form,
                           search_form=search_form,
                           float_form=float_form,
                           hydration_form=hydration_form,
                           movement_stream=movement_stream,
                           crew=crew)