mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-23 01:51:08 +00:00
Stylistic changes for goodreads import
This commit is contained in:
parent
d41a420355
commit
09f030db88
3 changed files with 18 additions and 8 deletions
|
@ -158,6 +158,7 @@ def handle_unshelve(user, book, shelf):
|
|||
|
||||
|
||||
def handle_import_books(user, items):
|
||||
''' process a goodreads csv and then post about it '''
|
||||
new_books = []
|
||||
for item in items:
|
||||
if item.shelf:
|
||||
|
@ -165,7 +166,8 @@ def handle_import_books(user, items):
|
|||
identifier=item.shelf,
|
||||
user=user
|
||||
)
|
||||
shelf, created = models.ShelfBook.objects.get_or_create(book=item.book, shelf=desired_shelf, added_by=user)
|
||||
_, created = models.ShelfBook.objects.get_or_create(
|
||||
book=item.book, shelf=desired_shelf, added_by=user)
|
||||
if created:
|
||||
new_books.append(item.book)
|
||||
activity = activitypub.get_add(user, item.book, desired_shelf)
|
||||
|
@ -178,7 +180,8 @@ def handle_import_books(user, items):
|
|||
status.status_type = 'Update'
|
||||
status.save()
|
||||
|
||||
create_activity = activitypub.get_create(user, activitypub.get_status(status))
|
||||
create_activity = activitypub.get_create(
|
||||
user, activitypub.get_status(status))
|
||||
broadcast(user, create_activity, get_recipients(user, 'public'))
|
||||
|
||||
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
{% extends 'layout.html' %}
|
||||
{% block content %}
|
||||
<div id="content">
|
||||
<div class="content-container">
|
||||
<h2>Import Books from GoodReads</h2>
|
||||
<form name="import" action="/import_data/" method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
{{ import_form.as_p }}
|
||||
<button type="submit">Import</button>
|
||||
<small>Hang tight, this may take a minute!</small>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -6,6 +6,7 @@ from django.contrib.auth.decorators import login_required
|
|||
from django.http import HttpResponseBadRequest
|
||||
from django.shortcuts import redirect
|
||||
from django.template.response import TemplateResponse
|
||||
import re
|
||||
|
||||
from fedireads import forms, models, books_manager, outgoing
|
||||
from fedireads.settings import DOMAIN
|
||||
|
@ -290,14 +291,18 @@ def delete_follow_request(request):
|
|||
|
||||
outgoing.handle_outgoing_reject(requester, request.user, follow_request)
|
||||
return redirect('/user/%s' % request.user.localname)
|
||||
|
||||
|
||||
|
||||
@login_required
|
||||
def import_data(request):
|
||||
''' ingest a goodreads csv '''
|
||||
form = forms.ImportForm(request.POST, request.FILES)
|
||||
if form.is_valid():
|
||||
results = []
|
||||
failures = []
|
||||
for item in GoodreadsCsv(TextIOWrapper(request.FILES['csv_file'], encoding=request.encoding)):
|
||||
for item in GoodreadsCsv(TextIOWrapper(
|
||||
request.FILES['csv_file'],
|
||||
encoding=request.encoding)):
|
||||
if item.book:
|
||||
results.append(item)
|
||||
else:
|
||||
|
@ -306,9 +311,9 @@ def import_data(request):
|
|||
outgoing.handle_import_books(request.user, results)
|
||||
if failures:
|
||||
return TemplateResponse(request, 'import_results.html', {
|
||||
'success_count': len(results),
|
||||
'failures': failures,
|
||||
})
|
||||
'success_count': len(results),
|
||||
'failures': failures,
|
||||
})
|
||||
else:
|
||||
return redirect('/')
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue