Don't use book absolute ids for nav

This commit is contained in:
Mouse Reeve 2020-05-03 18:07:06 -07:00
parent 2fd7792f34
commit 1dffe425e0
10 changed files with 45 additions and 16 deletions

View file

@ -0,0 +1,21 @@
# Generated by Django 3.0.3 on 2020-05-04 00:49
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('fedireads', '0036_auto_20200503_2007'),
]
operations = [
migrations.RemoveField(
model_name='author',
name='fedireads_key',
),
migrations.RemoveField(
model_name='book',
name='fedireads_key',
),
]

View file

@ -94,9 +94,10 @@ class Book(FedireadsModel):
@property
def absolute_id(self):
''' constructs the absolute reference to any db object '''
if self.sync and self.remote_id:
return self.remote_id
base_path = 'https://%s' % DOMAIN
model_name = type(self).__name__.lower()
return '%s/book/%s' % (base_path, self.openlibrary_key)
return '%s/book/%d' % (base_path, self.id)
def save(self, *args, **kwargs):
''' can't be abstract for query reasons, but you shouldn't USE it '''

View file

@ -16,7 +16,7 @@
<div class="book-grid row shrink wrap">
{% for book in books %}
<div class="book-preview">
<a href="{{ book.absolute_id }}">
<a href="/book/{{ book.id }}">
{% include 'snippets/book_cover.html' with book=book %}
</a>
{% include 'snippets/shelve_button.html' with book=book %}

View file

@ -6,7 +6,7 @@
<div class="book-grid row wrap shrink">
{% for book in books %}
<div class="cover-container">
<a href="{{ book.absolute_id }}">
<a href="/book/{{ book.id }}">
{% include 'snippets/book_cover.html' with book=book %}
</a>
{% include 'snippets/shelve_button.html' with book=book %}

View file

@ -5,9 +5,15 @@
<h2>Editions of <a href="/book/{{ work.id }}">"{{ work.title }}"</a></h2>
<ol class="book-grid row wrap">
{% for book in editions %}
<<<<<<< HEAD
<li class="book-preview">
<a href="{{ book.absolute_id }}">
{% include 'snippets/book_cover.html' with book=book %}
=======
<div class="book-preview">
<a href="/book/{{ book.id }}">
{% include 'snippets/book_cover.html' with book=book %}
>>>>>>> Don't use book absolute ids for nav
</a>
{% include 'snippets/shelve_button.html' with book=book %}
</li>

View file

@ -44,7 +44,7 @@
<tr>
<td>
{% if item.book %}
<a href="{{ item.book.absolute_id }}">
<a href="/book/{{ item.book.id }}">
{% include 'snippets/book_cover.html' with book=item.book size='small' %}
</a>
{% endif %}

View file

@ -3,13 +3,13 @@
<div class="tabs secondary">
<div class="tab active" data-id="tab-review-{{ book.id }}" data-category="tab-option-{{ book.id }}">
<a href="{{ book.absolute_id }}/review" onclick="tabChange(event)">Review</a>
<a href="/book/{{ book.id }}/review" onclick="tabChange(event)">Review</a>
</div>
<div class="tab" data-id="tab-comment-{{ book.id }}" data-category="tab-option-{{ book.id }}">
<a href="{{ book.absolute_id }}/comment" onclick="tabChange(event)">Comment</a>
<a href="/book/{{ book.id }}/comment" onclick="tabChange(event)">Comment</a>
</div>
<div class="tab" data-id="tab-quotation-{{ book.id }}" data-category="tab-option-{{ book.id }}">
<a href="{{ book.absolute_id }}/quotation" onclick="tabChange(event)">Quote</a>
<a href="/book/{{ book.id }}/quotation" onclick="tabChange(event)">Quote</a>
</div>
</div>

View file

@ -6,13 +6,13 @@
{% if status.status_type == 'Update' %}
{{ status.content | safe }}
{% elif status.status_type == 'Review' and not status.name and not status.content%}
rated <a href="{{ status.book.absolute_id }}">{{ status.book.title }}</a>
rated <a href="/book/{{ status.book.id }}">{{ status.book.title }}</a>
{% elif status.status_type == 'Review' %}
reviewed <a href="{{ status.book.absolute_id }}">{{ status.book.title }}</a>
reviewed <a href="/book/{{ status.book.id }}">{{ status.book.title }}</a>
{% elif status.status_type == 'Comment' %}
commented on <a href="{{ status.book.absolute_id }}">{{ status.book.title }}</a>
commented on <a href="/book/{{ status.book.id }}">{{ status.book.title }}</a>
{% elif status.status_type == 'Quotation' %}
quoted <a href="{{ status.book.absolute_id }}">{{ status.book.title }}</a>
quoted <a href="/book/{{ status.book.id }}">{{ status.book.title }}</a>
{% elif status.status_type == 'Boost' %}
boosted
{% elif status.reply_parent %}

View file

@ -6,7 +6,7 @@
<div class="book-grid row wrap shrink">
{% for book in books.all %}
<div class="cover-container">
<a href="{{ book.absolute_id }}">
<a href="/book/{{ book.id }}">
{% include 'snippets/book_cover.html' with book=book %}
</a>
{% include 'snippets/rate_action.html' with user=request.user book=book %}

View file

@ -4,6 +4,7 @@ from django.db.models import Avg, Q
from django.http import HttpResponseBadRequest, HttpResponseNotFound,\
JsonResponse
from django.core.exceptions import PermissionDenied
from django.shortcuts import redirect
from django.template.response import TemplateResponse
from django.views.decorators.csrf import csrf_exempt
@ -366,15 +367,15 @@ def edit_profile_page(request):
def book_page(request, book_id, tab='friends'):
''' info about a book '''
key = 'id'
connector_id = None
if ':' in book_id:
try:
connector_id, key, book_id = book_id.split(':')
except ValueError:
return HttpResponseNotFound()
book = get_or_create_book(book_id, key=key, connector_id=connector_id)
return redirect('/book/%d' % book.id)
book = get_or_create_book(book_id)
if is_api_request(request):
return JsonResponse(activitypub.get_book(book))