Merge pull request #260 from mouse-reeve/shelves

tab through user shelves
This commit is contained in:
Mouse Reeve 2020-10-30 15:23:12 -07:00 committed by GitHub
commit 72219ace77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 21 deletions

View file

@ -1,19 +1,22 @@
{% extends 'layout.html' %} {% extends 'layout.html' %}
{% load fr_display %}
{% block content %} {% block content %}
{% include 'user_header.html' with user=user %}
<div class="block"> <div class="block">
<nav class="breadcrumb has-succeeds-separator" aria-label="breadcrumbs"> <div class="tabs">
<ul> <ul>
<li><a href="/user/{{ user.username }}">{% include 'snippets/username.html' with user=user %}</a></li> {% for shelf_tab in shelves %}
<li><a href="/user/{{ user.username }}/shelves">Shelves</a></li> <li class="{% if shelf_tab.identifier == shelf.identifier %}is-active{% endif %}">
<li class="is-active"><a href="#" aria-current="page">{{ shelf.name }}</a></li> <a href="/user/{{ user | username }}/shelf/{{ shelf_tab.identifier }}">{{ shelf_tab.name }}</a>
</li>
{% endfor %}
</ul> </ul>
</nav> </div>
</div> </div>
<div class="block"> <div class="block">
<div> <div>
<h2 class="title">{{ shelf.name }}</h2>
{% include 'snippets/shelf.html' with shelf=shelf ratings=ratings %} {% include 'snippets/shelf.html' with shelf=shelf ratings=ratings %}
</div> </div>
</div> </div>

View file

@ -1,6 +1,6 @@
{% load humanize %} {% load humanize %}
{% load fr_display %} {% load fr_display %}
{% if shelf.books %} {% if shelf.books.all|length > 0 %}
<table class="table is-striped is-fullwidth"> <table class="table is-striped is-fullwidth">
<tr class="book-preview"> <tr class="book-preview">

View file

@ -3,9 +3,20 @@
{% block content %} {% block content %}
{% include 'user_header.html' with user=user %} {% include 'user_header.html' with user=user %}
<div class="block">
<div class="tabs">
<ul>
{% for shelf in shelves %}
<li class="{% if true %}is-active{% endif %}">
<a href="/user/{{ user | username }}/shelves/{{ shelf.identifier }}">{{ shelf.name }}</a>
</li>
{% endfor %}
</ul>
<h2 class="title">{{ shelf.name }}</h2>
</div>
{% for shelf in shelves %} {% for shelf in shelves %}
<div class="block"> <div class="block">
<h2 class="title">{{ shelf.name }}</h2>
{% include 'snippets/shelf.html' with shelf=shelf ratings=ratings %} {% include 'snippets/shelf.html' with shelf=shelf ratings=ratings %}
</div> </div>
{% endfor %} {% endfor %}

View file

@ -299,7 +299,7 @@ def notifications_page(request):
return TemplateResponse(request, 'notifications.html', data) return TemplateResponse(request, 'notifications.html', data)
@csrf_exempt @csrf_exempt
def user_page(request, username, subpage=None): def user_page(request, username, subpage=None, shelf=None):
''' profile page for a user ''' ''' profile page for a user '''
try: try:
user = get_user_from_username(username) user = get_user_from_username(username)
@ -323,18 +323,22 @@ def user_page(request, username, subpage=None):
return TemplateResponse(request, 'following.html', data) return TemplateResponse(request, 'following.html', data)
if subpage == 'shelves': if subpage == 'shelves':
data['shelves'] = user.shelf_set.all() data['shelves'] = user.shelf_set.all()
return TemplateResponse(request, 'user_shelves.html', data) if shelf:
data['shelf'] = user.shelf_set.get(identifier=shelf)
else:
data['shelf'] = user.shelf_set.first()
return TemplateResponse(request, 'shelf.html', data)
data['shelf_count'] = user.shelf_set.count() data['shelf_count'] = user.shelf_set.count()
shelves = [] shelves = []
for shelf in user.shelf_set.all(): for user_shelf in user.shelf_set.all():
if not shelf.books.count(): if not user_shelf.books.count():
continue continue
shelves.append({ shelves.append({
'name': shelf.name, 'name': user_shelf.name,
'remote_id': shelf.remote_id, 'remote_id': user_shelf.remote_id,
'books': shelf.books.all()[:3], 'books': user_shelf.books.all()[:3],
'size': shelf.books.count(), 'size': user_shelf.books.count(),
}) })
if len(shelves) > 2: if len(shelves) > 2:
break break
@ -599,8 +603,5 @@ def shelf_page(request, username, shelf_identifier):
if is_api_request(request): if is_api_request(request):
return JsonResponse(shelf.to_activity(**request.GET)) return JsonResponse(shelf.to_activity(**request.GET))
data = { return user_page(
'shelf': shelf, request, username, subpage='shelves', shelf=shelf_identifier)
'user': user,
}
return TemplateResponse(request, 'shelf.html', data)