def user_system_csv(request):
    systems = models.UnmanagedSystem.objects.all().order_by('owner__name')
    try:
        ref_split = request.META['HTTP_REFERER'].split('/')
        type, id = ref_split[-3:-1]
        if type == 'model':
            systems = systems.filter(server_model__id=id)
    except:
        pass


    response = HttpResponse(mimetype='text/csv')
    response['Content-Disposition'] = 'attachment; filename=user_systems.csv'

    writer = csv.writer(response)
    writer.writerow(['Owner', 'Location', 'Serial', 'Asset Tag',
                    'Operating System', 'Model', 'Date Purchased', 'Cost'])

    for s in systems:
        try:
            location = s.owner.user_location
        except __HOLE__:
            location = ''
        writer.writerow([s.owner, location, s.serial, s.asset_tag,
                s.operating_system, s.server_model, s.date_purchased, s.cost])

    return response
dataset/ETHPy150Open mozilla/inventory/user_systems/views.py/user_system_csv