import csv
from django.http import HttpResponse
from datetime import datetime


def export_csv(filename, headers, rows):
    """
    Generic CSV export helper.
    headers: list of column names
    rows: list of lists/tuples of values
    """
    response = HttpResponse(content_type='text/csv')
    response['Content-Disposition'] = f'attachment; filename="{filename}-{datetime.now().strftime("%Y%m%d")}.csv"'

    writer = csv.writer(response)
    writer.writerow(headers)
    for row in rows:
        writer.writerow(row)

    return response