* Bare start on CSV support * Move core of CSV importer to operations * More validations, break out validation function * Validate dates and TaskList; convert errors to list of dictionaries * Finish upsert code, and documentation * Print msgs from the mgmt command, not the operations module * Handle BOM marks * Handle both in-memory and local file objects * Update readme * Working browser-upload view * Bail on incorrect headers * Fix default values and finish example spreadsheet * Change column order, update docs * Update index.md for RTD * First round of responses to PR feedback * Restore independent summaries/errors/upserts properties * PR responses * Split off reusable date validator into separate function * Fix URLs append * General test suite for CSV importer
22 lines
668 B
Python
22 lines
668 B
Python
from django.contrib.auth.decorators import login_required, user_passes_test
|
|
from django.http import HttpResponse
|
|
from django.shortcuts import render
|
|
from todo.operations.csv_importer import CSVImporter
|
|
|
|
from todo.utils import staff_check
|
|
|
|
@login_required
|
|
@user_passes_test(staff_check)
|
|
def import_csv(request) -> HttpResponse:
|
|
"""Import a specifically formatted CSV into stored tasks.
|
|
"""
|
|
|
|
ctx = {}
|
|
|
|
if request.method == "POST":
|
|
filepath = request.FILES.get('csvfile')
|
|
importer = CSVImporter()
|
|
results = importer.upsert(filepath)
|
|
ctx["results"] = results
|
|
|
|
return render(request, "todo/import_csv.html", context=ctx)
|