diff --git a/bookwyrm/templates/lists/curate.html b/bookwyrm/templates/lists/curate.html new file mode 100644 index 00000000..20c8175d --- /dev/null +++ b/bookwyrm/templates/lists/curate.html @@ -0,0 +1,49 @@ +{% extends 'lists/list_layout.html' %} +{% block panel %} + +
+

Pending Books

+

Go to list

+ {% if not pending.exists %} +

You're all set!

+ {% else %} + + + + + + + + {% for item in pending %} + + + + + + + {% endfor %} +
BookSuggested by
+ {% include 'snippets/book_cover.html' with book=item.book size="small" %} + + {% include 'snippets/book_titleby.html' with book=item.book %} + + {% include 'snippets/username.html' with user=item.added_by %} + +
+
+ {% csrf_token %} + + + +
+
+ {% csrf_token %} + + + +
+ +
+ {% endif %} +
+{% endblock %} diff --git a/bookwyrm/templates/lists/list.html b/bookwyrm/templates/lists/list.html index 6210c2bc..76c12aca 100644 --- a/bookwyrm/templates/lists/list.html +++ b/bookwyrm/templates/lists/list.html @@ -1,68 +1,12 @@ -{% extends 'layout.html' %} +{% extends 'lists/list_layout.html' %} {% load bookwyrm_tags %} -{% block content %} +{% block panel %} -
-
-

{{ list.name }} {% include 'snippets/privacy-icons.html' with item=list %}

-

Created {% if list.curation != 'open' %} and curated{% endif %} by {% include 'snippets/username.html' with user=list.user %}

- {% include 'snippets/trimmed_text.html' with full=list.description %} -
- {% if request.user == list.user %} -
- {% include 'snippets/toggle/open_button.html' with text="Edit list" icon="pencil" controls_text="create-list" %} -
- {% endif %} -
- - - -{% if pending.exists %} +{% if request.user == list.user and pending_count %}
-
-

{{ pending.count }} book{{pending.count | pluralize }} awaiting your approval

- {% include 'snippets/toggle/open_button.html' with text="Curate suggestions" controls_text="pending-books" class="is-small" %} -
- +

+ {{ pending_count }} book{{ pending_count | pluralize }} awaiting your approval +

{% endif %} diff --git a/bookwyrm/templates/lists/list_layout.html b/bookwyrm/templates/lists/list_layout.html new file mode 100644 index 00000000..135655ee --- /dev/null +++ b/bookwyrm/templates/lists/list_layout.html @@ -0,0 +1,25 @@ +{% extends 'layout.html' %} +{% load bookwyrm_tags %} +{% block content %} + +
+
+

{{ list.name }} {% include 'snippets/privacy-icons.html' with item=list %}

+

Created {% if list.curation != 'open' %} and curated{% endif %} by {% include 'snippets/username.html' with user=list.user %}

+ {% include 'snippets/trimmed_text.html' with full=list.description %} +
+ {% if request.user == list.user %} +
+ {% include 'snippets/toggle/open_button.html' with text="Edit list" icon="pencil" controls_text="create-list" %} +
+ {% endif %} +
+ + + +{% block panel %}{% endblock %} + +{% endblock %} diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 7b0975c0..89cc5c41 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -92,6 +92,8 @@ urlpatterns = [ views.List.as_view(), name='list'), re_path(r'^list/(?P\d+)/add/?$', views.list.add_book, name='list-add-book'), + re_path(r'^list/(?P\d+)/curate/?$', + views.Curate.as_view(), name='list-curate'), # preferences re_path(r'^preferences/profile/?$', views.EditUser.as_view()), diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index 5302d6c7..422931e3 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -14,7 +14,7 @@ from .import_data import Import, ImportStatus from .interaction import Favorite, Unfavorite, Boost, Unboost from .invite import ManageInvites, Invite from .landing import About, Home, Discover -from .list import Lists, List +from .list import Lists, List, Curate from .notifications import Notifications from .outbox import Outbox from .reading import edit_readthrough, create_readthrough, delete_readthrough diff --git a/bookwyrm/views/list.py b/bookwyrm/views/list.py index a885c553..9e76e12c 100644 --- a/bookwyrm/views/list.py +++ b/bookwyrm/views/list.py @@ -76,7 +76,8 @@ class List(View): 'title': '%s | Lists' % book_list.name, 'list': book_list, 'items': book_list.listitem_set.filter(approved=True), - 'pending': book_list.listitem_set.filter(approved=False), + 'pending_count': book_list.listitem_set.filter( + approved=False).count(), 'suggested_books': suggestions, 'list_form': forms.ListForm(instance=book_list), 'query': query or '' @@ -96,6 +97,41 @@ class List(View): return redirect(book_list.local_path) +class Curate(View): + ''' approve or discard list suggestsions ''' + @method_decorator(login_required, name='dispatch') + def get(self, request, list_id): + ''' display a pending list ''' + book_list = get_object_or_404(models.List, id=list_id) + if not book_list.user == request.user: + # only the creater can curate the list + return HttpResponseNotFound() + + data = { + 'title': 'Curate "%s" | Lists' % book_list.name, + 'list': book_list, + 'pending': book_list.listitem_set.filter(approved=False), + 'list_form': forms.ListForm(instance=book_list), + } + return TemplateResponse(request, 'lists/curate.html', data) + + + @method_decorator(login_required, name='dispatch') + # pylint: disable=unused-argument + def post(self, request, list_id): + ''' edit a book_list ''' + book_list = get_object_or_404(models.List, id=list_id) + suggestion = get_object_or_404( + models.ListItem, id=request.POST.get('item')) + approved = request.POST.get('approved') == 'true' + if approved: + suggestion.approved = True + suggestion.save() + else: + suggestion.delete() + return redirect('list-curate', book_list.id) + + @require_POST def add_book(request, list_id): ''' put a book on a list '''