mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-22 17:41:08 +00:00
parent
3eb91980e0
commit
6c629be667
8 changed files with 105 additions and 65 deletions
|
@ -14,7 +14,7 @@
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if shelf.size > shelf.books.count %}
|
{% if shelf.size > shelf.books.count %}
|
||||||
<a href="/shelf/{{ shelf.identifier }}">See all {{ shelf.size }}</a>
|
<a href="/shelf/{{ user | username }}/{{ shelf.identifier }}">See all {{ shelf.size }}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
|
10
fedireads/templates/shelf.html
Normal file
10
fedireads/templates/shelf.html
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{% extends 'layout.html' %}
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<div id="content">
|
||||||
|
<div>
|
||||||
|
<h2>{% include 'snippets/username.html' %} > {{ shelf.name }}</h2>
|
||||||
|
{% include 'snippets/shelf.html' with shelf=shelf ratings=ratings %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
61
fedireads/templates/snippets/shelf.html
Normal file
61
fedireads/templates/snippets/shelf.html
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
{% load humanize %}
|
||||||
|
{% load fr_display %}
|
||||||
|
{% if shelf.books %}
|
||||||
|
<table>
|
||||||
|
<tr class="book-preview">
|
||||||
|
<th>
|
||||||
|
Cover
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Title
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Author
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Published
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Shelved
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
External links
|
||||||
|
</th>
|
||||||
|
{% if ratings %}
|
||||||
|
<th>
|
||||||
|
Rating
|
||||||
|
</th>
|
||||||
|
{% endif %}
|
||||||
|
</tr>
|
||||||
|
{% for book in shelf.books.all %}
|
||||||
|
<tr class="book-preview">
|
||||||
|
<td>
|
||||||
|
{% include 'snippets/book_cover.html' with book=book %}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="/book/{{ book.openlibrary_key }}">{{ book.data.title }}</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{ book.authors.first.data.name }}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{ book.data.first_publish_date }}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{ book.added_date | naturalday }}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="https://openlibrary.org{{ book.data.key }}" target="_blank">OpenLibrary</a>
|
||||||
|
</td>
|
||||||
|
{% if ratings %}
|
||||||
|
<td>
|
||||||
|
{{ ratings | dict_key:book.id | stars}}
|
||||||
|
</td>
|
||||||
|
{% endif %}
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
{% else %}
|
||||||
|
<p>This shelf is empty.</p>
|
||||||
|
{% endif %}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
<a href="/user/{% if user.localname %}{{ user.localname }}{% else %}{{ user.username }}{% endif %}" class="user">{% if user.name %}{{ user.name }}{% elif user.localname %}{{ user.localname }}{% else %}{{ user.username }}{% endif %}</a>
|
{% load fr_display %}
|
||||||
|
<a href="/user/{{ user | username }}" class="user">{% if user.name %}{{ user.name }}{% else %}{{ user | username }}{% endif %}</a>
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
{% extends 'layout.html' %}
|
{% extends 'layout.html' %}
|
||||||
{% load humanize %}
|
|
||||||
{% load fr_display %}
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div id="sidebar">
|
<div id="sidebar">
|
||||||
<div class="user-profile">
|
<div class="user-profile">
|
||||||
|
@ -59,60 +57,7 @@
|
||||||
{% for shelf in shelves %}
|
{% for shelf in shelves %}
|
||||||
<div>
|
<div>
|
||||||
<h2>{{ shelf.name }}</h2>
|
<h2>{{ shelf.name }}</h2>
|
||||||
{% if shelf.books %}
|
{% include 'snippets/shelf.html' with shelf=shelf ratings=ratings %}
|
||||||
<table>
|
|
||||||
<tr class="book-preview">
|
|
||||||
<th>
|
|
||||||
Cover
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
Title
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
Author
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
Published
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
Shelved
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
External links
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
Rating
|
|
||||||
</th>
|
|
||||||
</tr>
|
|
||||||
{% for book in shelf.books.all %}
|
|
||||||
<tr class="book-preview">
|
|
||||||
<td>
|
|
||||||
{% include 'snippets/book_cover.html' with book=book %}
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<a href="/book/{{ book.openlibrary_key }}">{{ book.data.title }}</a>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
{{ book.authors.first.data.name }}
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
{{ book.data.first_publish_date }}
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
{{ book.added_date | naturalday }}
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<a href="https://openlibrary.org{{ book.data.key }}" target="_blank">OpenLibrary</a>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
{{ ratings | dict_key:book.id | stars}}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
</table>
|
|
||||||
{% else %}
|
|
||||||
<p>This shelf is empty.</p>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -39,6 +39,12 @@ def bio_format(bio):
|
||||||
return bio[0].strip()
|
return bio[0].strip()
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter(name='username')
|
||||||
|
def get_user_identifier(user):
|
||||||
|
''' use localname for local users, username for remote '''
|
||||||
|
return user.localname if user.localname else user.username
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag(takes_context=True)
|
@register.simple_tag(takes_context=True)
|
||||||
def shelve_button_identifier(context, book):
|
def shelve_button_identifier(context, book):
|
||||||
''' check what shelf a user has a book on, if any '''
|
''' check what shelf a user has a book on, if any '''
|
||||||
|
@ -73,3 +79,4 @@ def shelve_button_text(context, book):
|
||||||
elif identifier == 'reading':
|
elif identifier == 'reading':
|
||||||
return 'I\'m done!'
|
return 'I\'m done!'
|
||||||
return 'Want to read'
|
return 'Want to read'
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ urlpatterns = [
|
||||||
r'^user/(?P<username>\w+)/(status|review)/(?P<status_id>\d+)/replies/?$',
|
r'^user/(?P<username>\w+)/(status|review)/(?P<status_id>\d+)/replies/?$',
|
||||||
incoming.get_replies
|
incoming.get_replies
|
||||||
),
|
),
|
||||||
# TODO: shelves need pages in the UI and for their activitypub Collection
|
|
||||||
|
|
||||||
# .well-known endpoints
|
# .well-known endpoints
|
||||||
re_path(r'^.well-known/webfinger/?$', wellknown.webfinger),
|
re_path(r'^.well-known/webfinger/?$', wellknown.webfinger),
|
||||||
|
@ -49,6 +48,7 @@ urlpatterns = [
|
||||||
re_path(r'^book/(?P<book_identifier>\w+)/?$', views.book_page),
|
re_path(r'^book/(?P<book_identifier>\w+)/?$', views.book_page),
|
||||||
re_path(r'^author/(?P<author_identifier>\w+)/?$', views.author_page),
|
re_path(r'^author/(?P<author_identifier>\w+)/?$', views.author_page),
|
||||||
re_path(r'^tag/(?P<tag_id>[\w-]+)/?$', views.tag_page),
|
re_path(r'^tag/(?P<tag_id>[\w-]+)/?$', views.tag_page),
|
||||||
|
re_path(r'^shelf/(?P<username>[\w@\.-]+)/(?P<shelf_identifier>[\w-]+)/?$', views.shelf_page),
|
||||||
|
|
||||||
# internal action endpoints
|
# internal action endpoints
|
||||||
re_path(r'^review/?$', views.review),
|
re_path(r'^review/?$', views.review),
|
||||||
|
|
|
@ -143,12 +143,9 @@ def user_profile(request, username):
|
||||||
|
|
||||||
# otherwise we're at a UI view
|
# otherwise we're at a UI view
|
||||||
try:
|
try:
|
||||||
user = models.User.objects.get(localname=username)
|
user = get_user_from_username(username)
|
||||||
except models.User.DoesNotExist:
|
except models.User.DoesNotExist:
|
||||||
try:
|
return HttpResponseNotFound()
|
||||||
user = models.User.objects.get(username=username)
|
|
||||||
except models.User.DoesNotExist:
|
|
||||||
return HttpResponseNotFound()
|
|
||||||
|
|
||||||
# TODO: change display with privacy and authentication considerations
|
# TODO: change display with privacy and authentication considerations
|
||||||
shelves = models.Shelf.objects.filter(user=user)
|
shelves = models.Shelf.objects.filter(user=user)
|
||||||
|
@ -163,6 +160,14 @@ def user_profile(request, username):
|
||||||
}
|
}
|
||||||
return TemplateResponse(request, 'user.html', data)
|
return TemplateResponse(request, 'user.html', data)
|
||||||
|
|
||||||
|
def get_user_from_username(username):
|
||||||
|
''' resolve a localname or a username to a user '''
|
||||||
|
try:
|
||||||
|
user = models.User.objects.get(localname=username)
|
||||||
|
except models.User.DoesNotExist:
|
||||||
|
user = models.User.objects.get(username=username)
|
||||||
|
return user
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def user_profile_edit(request, username):
|
def user_profile_edit(request, username):
|
||||||
|
@ -256,6 +261,18 @@ def tag_page(request, tag_id):
|
||||||
return TemplateResponse(request, 'tag.html', data)
|
return TemplateResponse(request, 'tag.html', data)
|
||||||
|
|
||||||
|
|
||||||
|
def shelf_page(request, username, shelf_identifier):
|
||||||
|
''' display a shelf '''
|
||||||
|
# TODO: json view
|
||||||
|
try:
|
||||||
|
user = get_user_from_username(username)
|
||||||
|
except models.User.DoesNotExist:
|
||||||
|
return HttpResponseNotFound()
|
||||||
|
|
||||||
|
shelf = models.Shelf.objects.get(user=user, identifier=shelf_identifier)
|
||||||
|
return TemplateResponse(request, 'shelf.html', {'shelf': shelf})
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def shelve(request, username, shelf_id, book_id, reshelve=True):
|
def shelve(request, username, shelf_id, book_id, reshelve=True):
|
||||||
''' put a book on a user's shelf '''
|
''' put a book on a user's shelf '''
|
||||||
|
|
Loading…
Reference in a new issue