mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-10-31 22:19:00 +00:00
Merge branch 'main' into production
This commit is contained in:
commit
ae1be06bb4
4 changed files with 15 additions and 5 deletions
|
@ -36,7 +36,11 @@ class Importer:
|
||||||
def create_job(self, user, csv_file, include_reviews, privacy):
|
def create_job(self, user, csv_file, include_reviews, privacy):
|
||||||
"""check over a csv and creates a database entry for the job"""
|
"""check over a csv and creates a database entry for the job"""
|
||||||
csv_reader = csv.DictReader(csv_file, delimiter=self.delimiter)
|
csv_reader = csv.DictReader(csv_file, delimiter=self.delimiter)
|
||||||
rows = enumerate(list(csv_reader))
|
rows = list(csv_reader)
|
||||||
|
if len(rows) < 1:
|
||||||
|
raise ValueError("CSV file is empty")
|
||||||
|
rows = enumerate(rows)
|
||||||
|
|
||||||
job = ImportJob.objects.create(
|
job = ImportJob.objects.create(
|
||||||
user=user,
|
user=user,
|
||||||
include_reviews=include_reviews,
|
include_reviews=include_reviews,
|
||||||
|
|
|
@ -11,7 +11,7 @@ from django.utils.translation import gettext_lazy as _
|
||||||
env = Env()
|
env = Env()
|
||||||
env.read_env()
|
env.read_env()
|
||||||
DOMAIN = env("DOMAIN")
|
DOMAIN = env("DOMAIN")
|
||||||
VERSION = "0.5.1"
|
VERSION = "0.5.2"
|
||||||
|
|
||||||
RELEASE_API = env(
|
RELEASE_API = env(
|
||||||
"RELEASE_API",
|
"RELEASE_API",
|
||||||
|
|
|
@ -8,6 +8,12 @@
|
||||||
<div class="block">
|
<div class="block">
|
||||||
<h1 class="title">{% trans "Import Books" %}</h1>
|
<h1 class="title">{% trans "Import Books" %}</h1>
|
||||||
|
|
||||||
|
{% if invalid %}
|
||||||
|
<div class="notification is-danger">
|
||||||
|
{% trans "Not a valid CSV file" %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if site.imports_enabled %}
|
{% if site.imports_enabled %}
|
||||||
{% if recent_avg_hours or recent_avg_minutes %}
|
{% if recent_avg_hours or recent_avg_minutes %}
|
||||||
<div class="notification">
|
<div class="notification">
|
||||||
|
|
|
@ -11,7 +11,6 @@ from django.shortcuts import redirect
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
from django.views import View
|
from django.views import View
|
||||||
|
|
||||||
from bookwyrm import forms, models
|
from bookwyrm import forms, models
|
||||||
|
@ -30,7 +29,7 @@ from bookwyrm.utils.cache import get_or_set
|
||||||
class Import(View):
|
class Import(View):
|
||||||
"""import view"""
|
"""import view"""
|
||||||
|
|
||||||
def get(self, request):
|
def get(self, request, invalid=False):
|
||||||
"""load import page"""
|
"""load import page"""
|
||||||
jobs = models.ImportJob.objects.filter(user=request.user).order_by(
|
jobs = models.ImportJob.objects.filter(user=request.user).order_by(
|
||||||
"-created_date"
|
"-created_date"
|
||||||
|
@ -43,6 +42,7 @@ class Import(View):
|
||||||
"page_range": paginated.get_elided_page_range(
|
"page_range": paginated.get_elided_page_range(
|
||||||
page.number, on_each_side=2, on_ends=1
|
page.number, on_each_side=2, on_ends=1
|
||||||
),
|
),
|
||||||
|
"invalid": invalid,
|
||||||
}
|
}
|
||||||
|
|
||||||
seconds = get_or_set("avg-import-time", get_average_import_time, timeout=86400)
|
seconds = get_or_set("avg-import-time", get_average_import_time, timeout=86400)
|
||||||
|
@ -88,7 +88,7 @@ class Import(View):
|
||||||
privacy,
|
privacy,
|
||||||
)
|
)
|
||||||
except (UnicodeDecodeError, ValueError, KeyError):
|
except (UnicodeDecodeError, ValueError, KeyError):
|
||||||
return HttpResponseBadRequest(_("Not a valid csv file"))
|
return self.get(request, invalid=True)
|
||||||
|
|
||||||
job.start_job()
|
job.start_job()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue