Link import job to import status and display status on status page.

This commit is contained in:
Adam Kelly 2020-04-22 14:16:46 +01:00
parent 22b2a95fd3
commit 60dabe442e
5 changed files with 31 additions and 2 deletions

View file

@ -42,7 +42,7 @@ def import_data(job_id):
item.fail_reason = "Could not match book on OpenLibrary"
item.save()
outgoing.handle_import_books(job.user, results)
status = outgoing.handle_import_books(job.user, results)
for item in reviews:
review_title = "Review of {!r} on Goodreads".format(
item.book.title,
@ -54,5 +54,8 @@ def import_data(job_id):
item.review,
item.rating,
)
if status:
job.import_status = status
job.save()
finally:
create_notification(job.user, 'IMPORT', related_import=job)

View file

@ -0,0 +1,19 @@
# Generated by Django 3.0.3 on 2020-04-22 13:12
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('fedireads', '0033_auto_20200422_1249'),
]
operations = [
migrations.AddField(
model_name='importjob',
name='import_status',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='fedireads.Status'),
),
]

View file

@ -36,6 +36,8 @@ class ImportJob(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
created_date = models.DateTimeField(default=timezone.now)
task_id = models.CharField(max_length=100, null=True)
import_status = models.ForeignKey(
'Status', null=True, on_delete=models.PROTECT)
class ImportItem(models.Model):
job = models.ForeignKey(

View file

@ -158,7 +158,7 @@ def handle_shelve(user, book, shelf):
activity = activitypub.get_status(status)
create_activity = activitypub.get_create(user, activity)
broadcast(user, create_activity, recipients)
broadcast(user, create_activity)
def handle_unshelve(user, book, shelf):
@ -206,6 +206,7 @@ def handle_import_books(user, items):
create_activity = activitypub.get_create(
user, activitypub.get_status(status))
broadcast(user, create_activity)
return status
def handle_rate(user, book, rating):

View file

@ -16,6 +16,10 @@
<p>
{{ task.info }}
{% endif %}
{% if job.import_status %}
{% include 'snippets/status.html' with status=job.import_status %}
{% endif %}
{% else %}
Import still in progress.
<p>