Beispiel #1
0
    def post(self, request):
        """ingest a goodreads csv"""
        form = forms.ImportForm(request.POST, request.FILES)
        if form.is_valid():
            include_reviews = request.POST.get("include_reviews") == "on"
            privacy = request.POST.get("privacy")
            source = request.POST.get("source")

            importer = None
            if source == "LibraryThing":
                importer = LibrarythingImporter()
            elif source == "Storygraph":
                importer = StorygraphImporter()
            else:
                # Default : GoodReads
                importer = GoodreadsImporter()

            try:
                job = importer.create_job(
                    request.user,
                    TextIOWrapper(request.FILES["csv_file"],
                                  encoding=importer.encoding),
                    include_reviews,
                    privacy,
                )
            except (UnicodeDecodeError, ValueError, KeyError):
                return HttpResponseBadRequest(_("Not a valid csv file"))

            importer.start_import(job)

            return redirect("/import/%d" % job.id)
        return HttpResponseBadRequest()
Beispiel #2
0
    def setUp(self):
        """use a test csv"""
        self.importer = GoodreadsImporter()
        datafile = pathlib.Path(__file__).parent.joinpath(
            "../data/goodreads.csv")
        self.csv = open(datafile, "r", encoding=self.importer.encoding)
        self.user = models.User.objects.create_user("mouse",
                                                    "*****@*****.**",
                                                    "password",
                                                    local=True)

        models.Connector.objects.create(
            identifier=DOMAIN,
            name="Local",
            local=True,
            connector_file="self_connector",
            base_url="https://%s" % DOMAIN,
            books_url="https://%s/book" % DOMAIN,
            covers_url="https://%s/images/covers" % DOMAIN,
            search_url="https://%s/search?q=" % DOMAIN,
            priority=1,
        )
        work = models.Work.objects.create(title="Test Work")
        self.book = models.Edition.objects.create(
            title="Example Edition",
            remote_id="https://example.com/book/1",
            parent_work=work,
        )
Beispiel #3
0
 def post(self, request, job_id):
     """bring a legacy import into the latest format"""
     job = get_object_or_404(models.ImportJob, id=job_id)
     if job.user != request.user:
         raise PermissionDenied()
     GoodreadsImporter().update_legacy_job(job)
     return redirect("import-status", job_id)
Beispiel #4
0
    def setUp(self):
        """use a test csv"""
        self.importer = GoodreadsImporter()
        datafile = pathlib.Path(__file__).parent.joinpath(
            "../data/goodreads.csv")
        self.csv = open(datafile, "r", encoding=self.importer.encoding)
        with patch(
                "bookwyrm.suggested_users.rerank_suggestions_task.delay"
        ), patch("bookwyrm.activitystreams.populate_stream_task.delay"), patch(
                "bookwyrm.lists_stream.populate_lists_task.delay"):
            self.local_user = models.User.objects.create_user(
                "mouse", "*****@*****.**", "password", local=True)

        work = models.Work.objects.create(title="Test Work")
        self.book = models.Edition.objects.create(
            title="Example Edition",
            remote_id="https://example.com/book/1",
            parent_work=work,
        )