Improve error handling for web upload of bad CSV
This commit is contained in:
		
							parent
							
								
									ad0a1aa44a
								
							
						
					
					
						commit
						e9a7bbe48c
					
				
					 2 changed files with 9 additions and 3 deletions
				
			
		| 
						 | 
				
			
			@ -54,10 +54,10 @@ class CSVImporter:
 | 
			
		|||
            "Priority",
 | 
			
		||||
        ]
 | 
			
		||||
        if header != expected:
 | 
			
		||||
            self.results.get("summaries").append(
 | 
			
		||||
            self.errors.append(
 | 
			
		||||
                f"Inbound data does not have expected columns.\nShould be: {expected}"
 | 
			
		||||
            )
 | 
			
		||||
            return self.results
 | 
			
		||||
            return
 | 
			
		||||
 | 
			
		||||
        for row in csv_reader:
 | 
			
		||||
            self.line_count += 1
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -24,6 +24,12 @@ def import_csv(request) -> HttpResponse:
 | 
			
		|||
 | 
			
		||||
        importer = CSVImporter()
 | 
			
		||||
        results = importer.upsert(filepath)
 | 
			
		||||
 | 
			
		||||
        ctx["results"] = None
 | 
			
		||||
        if results:
 | 
			
		||||
            ctx["results"] = results
 | 
			
		||||
        else:
 | 
			
		||||
            messages.error(request, "Could not parse provided CSV file.")
 | 
			
		||||
            return redirect(reverse("todo:import_csv"))
 | 
			
		||||
 | 
			
		||||
    return render(request, "todo/import_csv.html", context=ctx)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue