From 8bcd3da25e73b4f874f9c85281f1b168542aa548 Mon Sep 17 00:00:00 2001 From: Adam Kelly Date: Mon, 23 Mar 2020 16:40:09 +0000 Subject: [PATCH] Add a form to upload goodreads data. --- fedireads/forms.py | 4 ++++ fedireads/templates/import.html | 10 ++++++++++ fedireads/templates/layout.html | 1 + fedireads/urls.py | 2 ++ fedireads/views.py | 8 ++++++++ 5 files changed, 25 insertions(+) create mode 100644 fedireads/templates/import.html diff --git a/fedireads/forms.py b/fedireads/forms.py index e812fc0e6..bddef528f 100644 --- a/fedireads/forms.py +++ b/fedireads/forms.py @@ -1,6 +1,7 @@ ''' usin django model forms ''' from django.core.validators import MaxValueValidator, MinValueValidator from django.forms import ModelForm, PasswordInput, IntegerField +from django import forms from fedireads import models @@ -73,3 +74,6 @@ class TagForm(ModelForm): help_texts = {f: None for f in fields} labels = {'name': 'Add a tag'} + +class ImportForm(forms.Form): + csv_file = forms.FileField() diff --git a/fedireads/templates/import.html b/fedireads/templates/import.html new file mode 100644 index 000000000..694fe9914 --- /dev/null +++ b/fedireads/templates/import.html @@ -0,0 +1,10 @@ +{% extends 'layout.html' %} +{% block content %} +
+
+ {% csrf_token %} + {{ import_form.as_p }} + +
+
+{% endblock %} diff --git a/fedireads/templates/layout.html b/fedireads/templates/layout.html index e76cc2d46..8537a4e7a 100644 --- a/fedireads/templates/layout.html +++ b/fedireads/templates/layout.html @@ -29,6 +29,7 @@
  • Your shelves
  • Updates
  • Discover Books
  • +
  • Import Books
  • diff --git a/fedireads/urls.py b/fedireads/urls.py index eb0aa3d16..677b86823 100644 --- a/fedireads/urls.py +++ b/fedireads/urls.py @@ -34,6 +34,7 @@ urlpatterns = [ re_path(r'^(?Phome|local|federated)/?$', views.home_tab), re_path(r'^notifications/?', views.notifications_page), re_path(r'books/?$', views.books_page), + re_path(r'import/?$', views.import_page), # should return a ui view or activitypub json blob as requested # users @@ -81,5 +82,6 @@ urlpatterns = [ re_path(r'^accept_follow_request/?$', actions.accept_follow_request), re_path(r'^delete_follow_request/?$', actions.delete_follow_request), + re_path(r'import_data', actions.import_data), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/fedireads/views.py b/fedireads/views.py index ec80b726f..83bf3df7f 100644 --- a/fedireads/views.py +++ b/fedireads/views.py @@ -108,6 +108,14 @@ def books_page(request): } return TemplateResponse(request, 'books.html', data) +@login_required +def import_page(request): + ''' import history from goodreads ''' + return TemplateResponse(request, 'import.html', { + 'import_form': forms.ImportForm(), + }) + + def login_page(request): ''' authentication '''