prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Pending import csv lines displayed under "Successful" title until tried
  Importing a CSV into Bookwyrm shows titles being "successfully imported" but they do not show up in the library.
  
  Here's screenshots of the import results, neither the successful nor the failed imports seem to show up:
  ![](https://i.imgur.com/7NYKkMk.png)
  ![](https://i.imgur.com/4GCNCUd.png)
  
  
  [Attached is the file which I attempted to import.](https://github.com/bookwyrm-social/bookwyrm/files/6523421/Tomat0.s.Library.csv)
  
  
  
  </issue>
  <code>
  [start of bookwyrm/views/import_data.py]
  1 """ import books from another app """
  2 from io import TextIOWrapper
  3 
  4 from django.contrib.auth.decorators import login_required
  5 from django.core.exceptions import PermissionDenied
  6 from django.http import HttpResponseBadRequest
  7 from django.shortcuts import get_object_or_404, redirect
  8 from django.template.response import TemplateResponse
  9 from django.utils.decorators import method_decorator
  10 from django.utils.translation import gettext_lazy as _
  11 from django.views import View
  12 
  13 from bookwyrm import forms, models
  14 from bookwyrm.importers import (
  15     Importer,
  16     LibrarythingImporter,
  17     GoodreadsImporter,
  18     StorygraphImporter,
  19 )
  20 from bookwyrm.tasks import app
  21 
  22 # pylint: disable= no-self-use
  23 @method_decorator(login_required, name="dispatch")
  24 class Import(View):
  25     """import view"""
  26 
  27     def get(self, request):
  28         """load import page"""
  29         return TemplateResponse(
  30             request,
  31             "import.html",
  32             {
  33                 "import_form": forms.ImportForm(),
  34                 "jobs": models.ImportJob.objects.filter(user=request.user).order_by(
  35                     "-created_date"
  36                 ),
  37             },
  38         )
  39 
  40     def post(self, request):
  41         """ingest a goodreads csv"""
  42         form = forms.ImportForm(request.POST, request.FILES)
  43         if form.is_valid():
  44             include_reviews = request.POST.get("include_reviews") == "on"
  45             privacy = request.POST.get("privacy")
  46             source = request.POST.get("source")
  47 
  48             importer = None
  49             if source == "LibraryThing":
  50                 importer = LibrarythingImporter()
  51             elif source == "Storygraph":
  52                 importer = StorygraphImporter()
  53             else:
  54                 # Default : GoodReads
  55                 importer = GoodreadsImporter()
  56 
  57             try:
  58                 job = importer.create_job(
  59                     request.user,
  60                     TextIOWrapper(
  61                         request.FILES["csv_file"], encoding=importer.encoding
  62                     ),
  63                     include_reviews,
  64                     privacy,
  65                 )
  66             except (UnicodeDecodeError, ValueError, KeyError):
  67                 return HttpResponseBadRequest(_("Not a valid csv file"))
  68 
  69             importer.start_import(job)
  70 
  71             return redirect("/import/%d" % job.id)
  72         return HttpResponseBadRequest()
  73 
  74 
  75 @method_decorator(login_required, name="dispatch")
  76 class ImportStatus(View):
  77     """status of an existing import"""
  78 
  79     def get(self, request, job_id):
  80         """status of an import job"""
  81         job = models.ImportJob.objects.get(id=job_id)
  82         if job.user != request.user:
  83             raise PermissionDenied
  84         try:
  85             task = app.AsyncResult(job.task_id)
  86         except ValueError:
  87             task = None
  88         items = job.items.order_by("index").all()
  89         failed_items = [i for i in items if i.fail_reason]
  90         items = [i for i in items if not i.fail_reason]
  91         return TemplateResponse(
  92             request,
  93             "import_status.html",
  94             {"job": job, "items": items, "failed_items": failed_items, "task": task},
  95         )
  96 
  97     def post(self, request, job_id):
  98         """retry lines from an import"""
  99         job = get_object_or_404(models.ImportJob, id=job_id)
  100         items = []
  101         for item in request.POST.getlist("import_item"):
  102             items.append(get_object_or_404(models.ImportItem, id=item))
  103 
  104         importer = Importer()
  105         job = importer.create_retry_job(
  106             request.user,
  107             job,
  108             items,
  109         )
  110         importer.start_import(job)
  111         return redirect("/import/%d" % job.id)
  112
  [end of bookwyrm/views/import_data.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/bookwyrm/views/import_data.py b/bookwyrm/views/import_data.py
  --- a/bookwyrm/views/import_data.py
  +++ b/bookwyrm/views/import_data.py
  @@ -78,13 +78,15 @@
   
       def get(self, request, job_id):
           """status of an import job"""
  -        job = models.ImportJob.objects.get(id=job_id)
  +        job = get_object_or_404(models.ImportJob, id=job_id)
           if job.user != request.user:
               raise PermissionDenied
  +
           try:
               task = app.AsyncResult(job.task_id)
           except ValueError:
               task = None
  +
           items = job.items.order_by("index").all()
           failed_items = [i for i in items if i.fail_reason]
           items = [i for i in items if not i.fail_reason]
  
verification_info: {"golden_diff": "diff --git a/bookwyrm/views/import_data.py b/bookwyrm/views/import_data.py\n--- a/bookwyrm/views/import_data.py\n+++ b/bookwyrm/views/import_data.py\n@@ -78,13 +78,15 @@\n \n     def get(self, request, job_id):\n         \"\"\"status of an import job\"\"\"\n-        job = models.ImportJob.objects.get(id=job_id)\n+        job = get_object_or_404(models.ImportJob, id=job_id)\n         if job.user != request.user:\n             raise PermissionDenied\n+\n         try:\n             task = app.AsyncResult(job.task_id)\n         except ValueError:\n             task = None\n+\n         items = job.items.order_by(\"index\").all()\n         failed_items = [i for i in items if i.fail_reason]\n         items = [i for i in items if not i.fail_reason]\n", "issue": "Pending import csv lines displayed under \"Successful\" title until tried\nImporting a CSV into Bookwyrm shows titles being \"successfully imported\" but they do not show up in the library.\r\n\r\nHere's screenshots of the import results, neither the successful nor the failed imports seem to show up:\r\n![](https://i.imgur.com/7NYKkMk.png)\r\n![](https://i.imgur.com/4GCNCUd.png)\r\n\r\n\r\n[Attached is the file which I attempted to import.](https://github.com/bookwyrm-social/bookwyrm/files/6523421/Tomat0.s.Library.csv)\r\n\r\n\n", "before_files": [{"content": "\"\"\" import books from another app \"\"\"\nfrom io import TextIOWrapper\n\nfrom django.contrib.auth.decorators import login_required\nfrom django.core.exceptions import PermissionDenied\nfrom django.http import HttpResponseBadRequest\nfrom django.shortcuts import get_object_or_404, redirect\nfrom django.template.response import TemplateResponse\nfrom django.utils.decorators import method_decorator\nfrom django.utils.translation import gettext_lazy as _\nfrom django.views import View\n\nfrom bookwyrm import forms, models\nfrom bookwyrm.importers import (\n    Importer,\n    LibrarythingImporter,\n    GoodreadsImporter,\n    StorygraphImporter,\n)\nfrom bookwyrm.tasks import app\n\n# pylint: disable= no-self-use\n@method_decorator(login_required, name=\"dispatch\")\nclass Import(View):\n    \"\"\"import view\"\"\"\n\n    def get(self, request):\n        \"\"\"load import page\"\"\"\n        return TemplateResponse(\n            request,\n            \"import.html\",\n            {\n                \"import_form\": forms.ImportForm(),\n                \"jobs\": models.ImportJob.objects.filter(user=request.user).order_by(\n                    \"-created_date\"\n                ),\n            },\n        )\n\n    def post(self, request):\n        \"\"\"ingest a goodreads csv\"\"\"\n        form = forms.ImportForm(request.POST, request.FILES)\n        if form.is_valid():\n            include_reviews = request.POST.get(\"include_reviews\") == \"on\"\n            privacy = request.POST.get(\"privacy\")\n            source = request.POST.get(\"source\")\n\n            importer = None\n            if source == \"LibraryThing\":\n                importer = LibrarythingImporter()\n            elif source == \"Storygraph\":\n                importer = StorygraphImporter()\n            else:\n                # Default : GoodReads\n                importer = GoodreadsImporter()\n\n            try:\n                job = importer.create_job(\n                    request.user,\n                    TextIOWrapper(\n                        request.FILES[\"csv_file\"], encoding=importer.encoding\n                    ),\n                    include_reviews,\n                    privacy,\n                )\n            except (UnicodeDecodeError, ValueError, KeyError):\n                return HttpResponseBadRequest(_(\"Not a valid csv file\"))\n\n            importer.start_import(job)\n\n            return redirect(\"/import/%d\" % job.id)\n        return HttpResponseBadRequest()\n\n\n@method_decorator(login_required, name=\"dispatch\")\nclass ImportStatus(View):\n    \"\"\"status of an existing import\"\"\"\n\n    def get(self, request, job_id):\n        \"\"\"status of an import job\"\"\"\n        job = models.ImportJob.objects.get(id=job_id)\n        if job.user != request.user:\n            raise PermissionDenied\n        try:\n            task = app.AsyncResult(job.task_id)\n        except ValueError:\n            task = None\n        items = job.items.order_by(\"index\").all()\n        failed_items = [i for i in items if i.fail_reason]\n        items = [i for i in items if not i.fail_reason]\n        return TemplateResponse(\n            request,\n            \"import_status.html\",\n            {\"job\": job, \"items\": items, \"failed_items\": failed_items, \"task\": task},\n        )\n\n    def post(self, request, job_id):\n        \"\"\"retry lines from an import\"\"\"\n        job = get_object_or_404(models.ImportJob, id=job_id)\n        items = []\n        for item in request.POST.getlist(\"import_item\"):\n            items.append(get_object_or_404(models.ImportItem, id=item))\n\n        importer = Importer()\n        job = importer.create_retry_job(\n            request.user,\n            job,\n            items,\n        )\n        importer.start_import(job)\n        return redirect(\"/import/%d\" % job.id)\n", "path": "bookwyrm/views/import_data.py"}]}