@home.route('/import_package', methods=['GET', 'POST'])
@login_required
def import_package():
    form = ImportPackageForm()
    package_list = user_data.get_user_document_list()
    if ((request.method == 'POST') and (BTN_CANCEL in request.form)):
        return redirect(get_back_url())
    reload_metadata()
    if ((request.method == 'POST') and form.validate_on_submit()):
        if ('file' not in request.files):
            flash('No file part', 'error')
            return redirect(request.url)
        file = request.files['file']
        if file:
            filename = file.filename
            if (not (os.path.splitext(filename)[1] == '.xml')):
                flash('Please select a file with file extension ".xml".', 'error')
                return redirect(request.url)
            package_base_filename = os.path.basename(filename)
            package_name = os.path.splitext(package_base_filename)[0]
            try:
                unversioned_package_name = upload_ezeml_package(file, package_name)
            except FileNotFoundError as err:
                flash(f'The selected file does not appear to be a valid ezEML data package file. Please select a different file or check with the package provider for a corrected file.', 'error')
                return redirect(request.url)
            except ValueError as err:
                filename = err.args[0]
                flash(f'The selected package appears to have been modified manually outside of ezEML. Please ask the package provider to provide a package file exported directly from ezEML.', 'error')
                return redirect(request.url)
            if (unversioned_package_name in user_data.get_user_document_list()):
                return redirect(url_for('home.import_package_2', package_name=unversioned_package_name))
            else:
                import_ezeml_package(unversioned_package_name)
                fixup_upload_management()
                current_user.set_filename(filename=unversioned_package_name)
                return redirect(url_for(PAGE_TITLE, filename=unversioned_package_name))
    help = get_helps(['import_package'])
    return render_template('import_package.html', title='Import an ezEML Data Package', packages=package_list, form=form, help=help)
@home.route('/import_package', methods=['GET', 'POST'])
@login_required
def import_package():
    form = ImportPackageForm()
    package_list = user_data.get_user_document_list()
    if ((request.method == 'POST') and (BTN_CANCEL in request.form)):
        return redirect(get_back_url())
    reload_metadata()
    if ((request.method == 'POST') and form.validate_on_submit()):
        if ('file' not in request.files):
            flash('No file part', 'error')
            return redirect(request.url)
        file = request.files['file']
        if file:
            filename = file.filename
            if (not (os.path.splitext(filename)[1] == '.xml')):
                flash('Please select a file with file extension ".xml".', 'error')
                return redirect(request.url)
            package_base_filename = os.path.basename(filename)
            package_name = os.path.splitext(package_base_filename)[0]
            try:
                unversioned_package_name = upload_ezeml_package(file, package_name)
            except FileNotFoundError as err:
                flash(f'The selected file does not appear to be a valid ezEML data package file. Please select a different file or check with the package provider for a corrected file.', 'error')
                return redirect(request.url)
            except ValueError as err:
                filename = err.args[0]
                flash(f'The selected package appears to have been modified manually outside of ezEML. Please ask the package provider to provide a package file exported directly from ezEML.', 'error')
                return redirect(request.url)
            if (unversioned_package_name in user_data.get_user_document_list()):
                return redirect(url_for('home.import_package_2', package_name=unversioned_package_name))
            else:
                import_ezeml_package(unversioned_package_name)
                fixup_upload_management()
                current_user.set_filename(filename=unversioned_package_name)
                return redirect(url_for(PAGE_TITLE, filename=unversioned_package_name))
    help = get_helps(['import_package'])
    return render_template('import_package.html', title='Import an ezEML Data Package', packages=package_list, form=form, help=help)