Fixes model test

This commit is contained in:
Mouse Reeve 2021-01-31 09:08:06 -08:00
parent d73a1b4ec1
commit 4883231347
7 changed files with 58 additions and 11 deletions

View file

@ -1,2 +1,2 @@
<h4><a href="{{ list.local_path }}">{{ list.name }}</a> {% include 'snippets/privacy-icons.html' with item=list %}</h4> <h4><a href="{{ list.local_path }}">{{ list.name }}</a> <span class="subtitle">{% include 'snippets/privacy-icons.html' with item=list %}</span></h4>
{% include 'snippets/trimmed_text.html' with full=list.description %} {% include 'snippets/trimmed_text.html' with full=list.description %}

View file

@ -1,7 +1,44 @@
{% extends 'layout.html' %} {% extends 'layout.html' %}
{% block content %} {% block content %}
<h1>{{ list.name }}</h1>
{{ list }} <header class="columns content">
<div class="column">
<h1 class="title">{{ list.name }} <span class="subtitle">{% include 'snippets/privacy-icons.html' with item=list %}</span></h1>
{% include 'snippets/trimmed_text.html' with full=list.description %}
</div>
<div class="column is-narrow">
{% include 'snippets/toggle/open_button.html' with text="Edit list" icon="pencil" controls_text="edit-list" %}
</div>
</header>
<div class="columns content">
<section class="column">
<h2>Books</h2>
{% if not list.books.exists %}
<p>This list is currently empty</p>
{% else %}
{% for book in list.books.all %}
{{ book }}
{% endfor %}
{% endif %}
</section>
<section class="column is-one-quarter">
<h2>Add Books</h2>
{% for book in suggested_books %}
<div class="block columns">
<div class="column is-narrow">
<a href="{{ book.local_path }}">{% include 'snippets/book_cover.html' with book=book size="small" %}</a>
</div>
<div class="column">
<p>{% include 'snippets/book_titleby.html' with book=book %}</p>
<form name="add-book" method="post" action="{% url 'list-add-book' list.id %}">
{% csrf_token %}
<button type="submit" class="button is-small is-link">Add</button>
</form>
</div>
</div>
{% endfor %}
</section>
</div>
{% endblock %} {% endblock %}

View file

@ -67,7 +67,7 @@
{% if request.user.list_set.exists %} {% if request.user.list_set.exists %}
<ul> <ul>
{% for list in request.user.list_set.all %} {% for list in request.user.list_set.all %}
<li> <li class="block">
{% include 'lists/list-item.html' with list=list %} {% include 'lists/list-item.html' with list=list %}
</li> </li>
{% endfor %} {% endfor %}
@ -81,7 +81,7 @@
<h2 class="title">Recent Lists</h2> <h2 class="title">Recent Lists</h2>
<ul> <ul>
{% for list in lists %} {% for list in lists %}
<li> <li class="block">
{% include 'lists/list-item.html' with list=list %} {% include 'lists/list-item.html' with list=list %}
</li> </li>
{% endfor %} {% endfor %}

View file

@ -2,8 +2,8 @@
<div class="columns"> <div class="columns">
<div class="column is-narrow"> <div class="column is-narrow">
<div> <div>
<a href="/book/{{ book.id }}">{% include 'snippets/book_cover.html' with book=book %}</a> <a href="{{ book.local_path }}">{% include 'snippets/book_cover.html' with book=book %}</a>
{% include 'snippets/shelve_button.html' with book=book %} {% include 'snippets/shelve_button.html' with book=book %}
</div> </div>
</div> </div>
<div class="column"> <div class="column">

View file

@ -16,7 +16,7 @@ class List(TestCase):
def test_remote_id(self): def test_remote_id(self):
''' shelves use custom remote ids ''' ''' shelves use custom remote ids '''
expected_id = 'https://%s/user/mouse/list/%d' % \ expected_id = 'https://%s/list/%d' % \
(settings.DOMAIN, self.list.id) (settings.DOMAIN, self.list.id)
self.assertEqual(self.list.get_remote_id(), expected_id) self.assertEqual(self.list.get_remote_id(), expected_id)

View file

@ -88,7 +88,10 @@ urlpatterns = [
# lists # lists
re_path(r'^list/?$', views.Lists.as_view(), name='lists'), re_path(r'^list/?$', views.Lists.as_view(), name='lists'),
re_path(r'^list/(?P<list_id>\d+)(.json)?/?$', views.List.as_view(), name='list'), re_path(r'^list/(?P<list_id>\d+)(.json)?/?$',
views.List.as_view(), name='list'),
re_path(r'^list/(?P<list_id>\d+)/add/?$',
views.List.as_view(), name='list-add-book'),
# preferences # preferences
re_path(r'^preferences/profile/?$', views.EditUser.as_view()), re_path(r'^preferences/profile/?$', views.EditUser.as_view()),

View file

@ -51,8 +51,15 @@ class List(View):
if is_api_request(request): if is_api_request(request):
return ActivitypubResponse(book_list.to_activity()) return ActivitypubResponse(book_list.to_activity())
suggestions = request.user.shelfbook_set.all().filter(
~Q(book__in=book_list.books)
)
data = { data = {
'list': book_list 'title': '%s | Lists' % book_list.name,
'list': book_list,
'suggested_books': [s.book for s in suggestions[:5]],
} }
return TemplateResponse(request, 'lists/list.html', data) return TemplateResponse(request, 'lists/list.html', data)
@ -60,6 +67,6 @@ class List(View):
@method_decorator(login_required, name='dispatch') @method_decorator(login_required, name='dispatch')
# pylint: disable=unused-argument # pylint: disable=unused-argument
def post(self, request, list_id): def post(self, request, list_id):
''' create a book_list ''' ''' edit a book_list '''
book_list = get_object_or_404(models.List, id=list_id) book_list = get_object_or_404(models.List, id=list_id)
return redirect(book_list.local_path) return redirect(book_list.local_path)