def upload_costars():
    '''Uploads a new csv file with properly-formatted COSTARS data

    :status 200: Renders the
        :py:class:`~purchasing.conductor.forms.FileUploadForm`
    :status 302: Saves the uploaded file through the
        :py:class:`~purchasing.conductor.forms.FileUploadForm`
        and redirects to processing to upload the saved file
    '''
    form = FileUploadForm()
    if form.validate_on_submit():
        _file = request.files.get('upload')
        filename = secure_filename(_file.filename)
        filepath = os.path.join(current_app.config.get('UPLOAD_FOLDER'),
                                filename)
        try:
            _file.save(filepath)
        except IOError:
            # if the upload folder doesn't exist, create it then save
            os.mkdir(current_app.config.get('UPLOAD_FOLDER'))
            _file.save(filepath)

        session['filepath'] = filepath
        session['filename'] = filename

        return redirect(url_for('conductor_uploads.process'))
    else:
        return render_template('conductor/upload/upload_new.html', form=form)
def upload_costars():
    '''Uploads a new csv file with properly-formatted COSTARS data

    :status 200: Renders the
        :py:class:`~purchasing.conductor.forms.FileUploadForm`
    :status 302: Saves the uploaded file through the
        :py:class:`~purchasing.conductor.forms.FileUploadForm`
        and redirects to processing to upload the saved file
    '''
    form = FileUploadForm()
    if form.validate_on_submit():
        _file = request.files.get('upload')
        filename = secure_filename(_file.filename)
        filepath = os.path.join(current_app.config.get('UPLOAD_FOLDER'), filename)
        try:
            _file.save(filepath)
        except IOError:
            # if the upload folder doesn't exist, create it then save
            os.mkdir(current_app.config.get('UPLOAD_FOLDER'))
            _file.save(filepath)

        session['filepath'] = filepath
        session['filename'] = filename

        return redirect(url_for(
            'conductor_uploads.process'
        ))
    else:
        return render_template('conductor/upload/upload_new.html', form=form)
def upload_costars():
    form = FileUploadForm()
    if form.validate_on_submit():
        _file = request.files.get('upload')
        filename = secure_filename(_file.filename)
        filepath = os.path.join(current_app.config.get('UPLOAD_FOLDER'), filename)
        try:
            _file.save(filepath)
        except IOError:
            # if the upload folder doesn't exist, create it then save
            os.mkdir(current_app.config.get('UPLOAD_FOLDER'))
            _file.save(filepath)

        session['filepath'] = filepath
        session['filename'] = filename

        return redirect(url_for(
            'conductor_uploads.process'
        ))
    else:
        return render_template('conductor/upload/upload_new.html', form=form)