def ajax_csv_importer(request):
    save = True if request.POST.get('save', False) else False
    raw_csv_data = request.POST.get('csv-data', '')
    primary_attr = request.POST.get('primary-attr', 'hostname')

    @transaction.commit_manually
    def do_csv_import(data):
        try:
            return csv_import(data, primary_attr=primary_attr, save=save)
        except __HOLE__, e:
            transaction.rollback()
            return {'error': e.messages}
        except Exception, e:
            transaction.rollback()
            return {'error': ['Error: ' + e.message]}
        finally:
            transaction.commit()

    result = do_csv_import(raw_csv_data)

    attrs = [field.name for field in System._meta.fields]

    return render(request, 'csv/ajax_csv_importer.html', {
        'attrs': attrs,
        'result': result,
        'getattr': getattr,
        'save': save,
        'len': len
    }, status=200 if 'error' not in result else 400)
dataset/ETHPy150Open mozilla/inventory/mcsv/views.py/ajax_csv_importer