mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-23 10:01:04 +00:00
Merge branch 'book-file-links' into autocomplete
This commit is contained in:
commit
99ec87c67c
60 changed files with 606 additions and 267 deletions
|
@ -208,35 +208,34 @@ def set_related_field(
|
|||
model = apps.get_model(f"bookwyrm.{model_name}", require_ready=True)
|
||||
origin_model = apps.get_model(f"bookwyrm.{origin_model_name}", require_ready=True)
|
||||
|
||||
with transaction.atomic():
|
||||
if isinstance(data, str):
|
||||
existing = model.find_existing_by_remote_id(data)
|
||||
if existing:
|
||||
data = existing.to_activity()
|
||||
else:
|
||||
data = get_data(data)
|
||||
activity = model.activity_serializer(**data)
|
||||
if isinstance(data, str):
|
||||
existing = model.find_existing_by_remote_id(data)
|
||||
if existing:
|
||||
data = existing.to_activity()
|
||||
else:
|
||||
data = get_data(data)
|
||||
activity = model.activity_serializer(**data)
|
||||
|
||||
# this must exist because it's the object that triggered this function
|
||||
instance = origin_model.find_existing_by_remote_id(related_remote_id)
|
||||
if not instance:
|
||||
raise ValueError(f"Invalid related remote id: {related_remote_id}")
|
||||
# this must exist because it's the object that triggered this function
|
||||
instance = origin_model.find_existing_by_remote_id(related_remote_id)
|
||||
if not instance:
|
||||
raise ValueError(f"Invalid related remote id: {related_remote_id}")
|
||||
|
||||
# set the origin's remote id on the activity so it will be there when
|
||||
# the model instance is created
|
||||
# edition.parentWork = instance, for example
|
||||
model_field = getattr(model, related_field_name)
|
||||
if hasattr(model_field, "activitypub_field"):
|
||||
setattr(
|
||||
activity, getattr(model_field, "activitypub_field"), instance.remote_id
|
||||
)
|
||||
item = activity.to_model()
|
||||
# set the origin's remote id on the activity so it will be there when
|
||||
# the model instance is created
|
||||
# edition.parentWork = instance, for example
|
||||
model_field = getattr(model, related_field_name)
|
||||
if hasattr(model_field, "activitypub_field"):
|
||||
setattr(
|
||||
activity, getattr(model_field, "activitypub_field"), instance.remote_id
|
||||
)
|
||||
item = activity.to_model()
|
||||
|
||||
# if the related field isn't serialized (attachments on Status), then
|
||||
# we have to set it post-creation
|
||||
if not hasattr(model_field, "activitypub_field"):
|
||||
setattr(item, related_field_name, instance)
|
||||
item.save()
|
||||
# if the related field isn't serialized (attachments on Status), then
|
||||
# we have to set it post-creation
|
||||
if not hasattr(model_field, "activitypub_field"):
|
||||
setattr(item, related_field_name, instance)
|
||||
item.save()
|
||||
|
||||
|
||||
def get_model_from_type(activity_type):
|
||||
|
|
|
@ -492,3 +492,19 @@ class SortListForm(forms.Form):
|
|||
("descending", _("Descending")),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class ReadThroughForm(CustomForm):
|
||||
def clean(self):
|
||||
"""make sure the email isn't in use by a registered user"""
|
||||
cleaned_data = super().clean()
|
||||
start_date = cleaned_data.get("start_date")
|
||||
finish_date = cleaned_data.get("finish_date")
|
||||
if start_date > finish_date:
|
||||
self.add_error(
|
||||
"finish_date", _("Reading finish date cannot be before start date.")
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = models.ReadThrough
|
||||
fields = ["user", "book", "start_date", "finish_date"]
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
""" progress in a book """
|
||||
from django.core import validators
|
||||
from django.core.cache import cache
|
||||
from django.db import models
|
||||
from django.db.models import F, Q
|
||||
|
||||
|
@ -30,6 +31,7 @@ class ReadThrough(BookWyrmModel):
|
|||
|
||||
def save(self, *args, **kwargs):
|
||||
"""update user active time"""
|
||||
cache.delete(f"latest_read_through-{self.user.id}-{self.book.id}")
|
||||
self.user.update_active_date()
|
||||
# an active readthrough must have an unset finish date
|
||||
if self.finish_date:
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
""" defines relationships between users """
|
||||
from django.apps import apps
|
||||
from django.core.cache import cache
|
||||
from django.core.cache.utils import make_template_fragment_key
|
||||
from django.db import models, transaction, IntegrityError
|
||||
from django.db.models import Q
|
||||
|
||||
|
@ -41,15 +40,12 @@ class UserRelationship(BookWyrmModel):
|
|||
def save(self, *args, **kwargs):
|
||||
"""clear the template cache"""
|
||||
# invalidate the template cache
|
||||
cache_keys = [
|
||||
make_template_fragment_key(
|
||||
"follow_button", [self.user_subject.id, self.user_object.id]
|
||||
),
|
||||
make_template_fragment_key(
|
||||
"follow_button", [self.user_object.id, self.user_subject.id]
|
||||
),
|
||||
]
|
||||
cache.delete_many(cache_keys)
|
||||
cache.delete_many(
|
||||
[
|
||||
f"relationship-{self.user_subject.id}-{self.user_object.id}",
|
||||
f"relationship-{self.user_object.id}-{self.user_subject.id}",
|
||||
]
|
||||
)
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
class Meta:
|
||||
|
|
|
@ -755,6 +755,13 @@ ol.ordered-list li::before {
|
|||
padding: 0 0.75em;
|
||||
}
|
||||
|
||||
/* Notifications page
|
||||
******************************************************************************/
|
||||
|
||||
.notification a.icon {
|
||||
text-decoration: none !important;
|
||||
}
|
||||
|
||||
/* Breadcrumbs
|
||||
******************************************************************************/
|
||||
|
||||
|
|
|
@ -237,29 +237,21 @@
|
|||
<h2 class="title is-5">{% trans "Your reading activity" %}</h2>
|
||||
</div>
|
||||
<div class="column is-narrow">
|
||||
{% trans "Add read dates" as button_text %}
|
||||
{% include 'snippets/toggle/open_button.html' with text=button_text icon_with_text="plus" class="is-small" controls_text="add_readthrough" focus="add_readthrough_focus_" %}
|
||||
<button class="button is-small" data-modal-open="add-readthrough">
|
||||
<span class="icon icon-plus m-mobile-0" aria-hidden="true"></span>
|
||||
<span class="is-sr-only-mobile">
|
||||
{% trans "Add read dates" %}
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
<section class="is-hidden box" id="add_readthrough">
|
||||
<form name="add-readthrough" action="/create-readthrough" method="post">
|
||||
{% include 'snippets/readthrough_form.html' with readthrough=None %}
|
||||
<div class="field is-grouped">
|
||||
<div class="control">
|
||||
<button class="button is-primary" type="submit">{% trans "Create" %}</button>
|
||||
</div>
|
||||
<div class="control">
|
||||
{% trans "Cancel" as button_text %}
|
||||
{% include 'snippets/toggle/close_button.html' with text=button_text controls_text="add_readthrough" %}
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
{% include "readthrough/readthrough_modal.html" with id="add-readthrough" %}
|
||||
|
||||
{% if not readthroughs.exists %}
|
||||
<p>{% trans "You don't have any reading activity for this book." %}</p>
|
||||
{% endif %}
|
||||
{% for readthrough in readthroughs %}
|
||||
{% include 'book/readthrough.html' with readthrough=readthrough %}
|
||||
{% include 'readthrough/readthrough_list.html' with readthrough=readthrough %}
|
||||
{% endfor %}
|
||||
</section>
|
||||
<hr aria-hidden="true">
|
||||
|
@ -383,7 +375,7 @@
|
|||
{% endif %}
|
||||
|
||||
<section class="content block">
|
||||
{% include "book/links.html" %}
|
||||
{% include "book/file_links/links.html" %}
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block modal-form-open %}
|
||||
<form name="add-link" method="POST" action="{% url 'file-link' book.id %}">
|
||||
<form name="add-link" method="POST" action="{% url 'file-link-add' book.id %}">
|
||||
{% endblock %}
|
||||
|
||||
{% block modal-body %}
|
82
bookwyrm/templates/book/file_links/edit_links.html
Normal file
82
bookwyrm/templates/book/file_links/edit_links.html
Normal file
|
@ -0,0 +1,82 @@
|
|||
{% extends 'layout.html' %}
|
||||
{% load i18n %}
|
||||
{% load utilities %}
|
||||
|
||||
{% block title %}{% trans "Edit links" %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<header class="block content">
|
||||
<h1 class="title">
|
||||
{% blocktrans with title=book|book_title %}
|
||||
Links for "<em>{{ title }}</em>"
|
||||
{% endblocktrans %}
|
||||
</h1>
|
||||
</header>
|
||||
|
||||
<nav class="breadcrumb subtitle" aria-label="breadcrumbs">
|
||||
<ul>
|
||||
<li><a href="{% url 'book' book.id %}">{{ book|book_title }}</a></li>
|
||||
<li class="is-active">
|
||||
<a href="#" aria-current="page">
|
||||
{% trans "Edit links" %}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<section class="block content">
|
||||
<div class="table-container">
|
||||
<table class="is-striped is-fullwidth">
|
||||
<tr>
|
||||
<th>{% trans "URL" %}</th>
|
||||
<th>{% trans "Added by" %}</th>
|
||||
<th>{% trans "Filetype" %}</th>
|
||||
<th>{% trans "Domain" %}</th>
|
||||
<th>{% trans "Actions" %}</th>
|
||||
</tr>
|
||||
{% for link in book.file_links.all %}
|
||||
<tr>
|
||||
<td class="overflow-wrap-anywhere">
|
||||
<a href="{{ link.url }}" target="_blank" rel="noopener">{{ link.url }}</a>
|
||||
</td>
|
||||
<td>
|
||||
<a href="{% url 'user-feed' link.added_by.id %}">{{ link.added_by.display_name }}</a>
|
||||
</td>
|
||||
<td>
|
||||
{{ link.filelink.filetype }}
|
||||
</td>
|
||||
<td>
|
||||
{{ link.domain.name }} ({{ link.domain.get_status_display }})
|
||||
<p>
|
||||
<a href="{% url 'report-link' link.added_by.id link.id %}">{% trans "Report spam" %}</a>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<form name="delete-link-{{ link.id }}" class="control" method="post" action="{% url 'file-link' book.id link.id %}">
|
||||
{% csrf_token %}
|
||||
<button class="button is-danger is-light" type="submit">Delete link</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% if not book.file_links.exists %}
|
||||
<tr>
|
||||
<td colspan="5"><em>{% trans "No links available for this book." %}</em></td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{% url 'file-link-add' book.id as fallback_url %}
|
||||
<form name="add-link" method="get" action="{{ fallback_url }}">
|
||||
<button class="button" type="submit" data-modal-open="add-links">
|
||||
<span class="icon icon-plus m-0-mobile" aria-hidden="true"></span>
|
||||
<span class="is-sr-only-mobile">
|
||||
{% trans "Add link to file" %}
|
||||
</span>
|
||||
</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
{% endblock %}
|
|
@ -6,5 +6,5 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% include "book/file_link_modal.html" with book=book active=True static=True id="file-link" %}
|
||||
{% include "book/file_links/add_link_modal.html" with book=book active=True static=True id="file-link" %}
|
||||
{% endblock %}
|
|
@ -10,14 +10,16 @@
|
|||
</div>
|
||||
{% if can_edit_book %}
|
||||
<div class="column is-narrow">
|
||||
{% url 'file-link' book.id as fallback_url %}
|
||||
<button class="button is-small" type="button" data-modal-open="edit-links">
|
||||
<span class="icon icon-plus">
|
||||
<span class="is-sr-only">
|
||||
{% trans "Add link to copy" %}
|
||||
{% url 'file-link-add' book.id as fallback_url %}
|
||||
<form name="add-link" method="get" action="{{ fallback_url }}">
|
||||
<button class="button is-small" type="submit" data-modal-open="add-links">
|
||||
<span class="icon icon-plus">
|
||||
<span class="is-sr-only">
|
||||
{% trans "Add link to file" %}
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
</button>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
{% endif %}
|
||||
</header>
|
||||
|
@ -33,14 +35,18 @@
|
|||
</ul>
|
||||
{% for link in links.all %}
|
||||
{% join "verify" link.id as verify_modal %}
|
||||
{% include "book/link_verification_modal.html" with id=verify_modal %}
|
||||
{% include "book/file_links/verification_modal.html" with id=verify_modal %}
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<em>{% trans "No links available" %}</em>
|
||||
{% endif %}
|
||||
|
||||
{% if can_edit_book %}
|
||||
{% include 'book/file_link_modal.html' with book=book id="edit-links" %}
|
||||
{% if can_edit_book and links.exists %}
|
||||
<a href="{% url 'file-link' book.id %}" class="is-pulled-right">
|
||||
<span class="icon icon-pencil" aria-hidden="true"></span>
|
||||
<span>{% trans "Edit links" %}</span>
|
||||
</a>
|
||||
{% include 'book/file_links/add_link_modal.html' with book=book id="add-links" %}
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
|
@ -22,7 +22,7 @@ Is that where you'd like to go?
|
|||
|
||||
{% if request.user.is_authenticated %}
|
||||
<div class="has-text-right is-flex-grow-1">
|
||||
<a href="{% url 'report-link' link.added_by.id link.id %}">{% trans "Report spam" %}</button>
|
||||
<a href="{% url 'report-link' link.added_by.id link.id %}">{% trans "Report spam" %}</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
|
@ -16,10 +16,7 @@
|
|||
{% with shelf_counter=forloop.counter %}
|
||||
<li>
|
||||
<p>
|
||||
{% if shelf.identifier == 'to-read' %}{% trans "To Read" %}
|
||||
{% elif shelf.identifier == 'reading' %}{% trans "Currently Reading" %}
|
||||
{% elif shelf.identifier == 'read' %}{% trans "Read" %}
|
||||
{% else %}{{ shelf.name }}{% endif %}
|
||||
{% include "snippets/translated_shelf_name.html" with shelf=shelf %}
|
||||
</p>
|
||||
<div class="tabs is-small is-toggle">
|
||||
<ul>
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
{% extends 'landing/layout.html' %}
|
||||
{% load i18n %}
|
||||
{% load cache %}
|
||||
{% load bookwyrm_tags %}
|
||||
|
||||
{% block panel %}
|
||||
|
||||
<div class="block is-hidden-tablet">
|
||||
<h2 class="title has-text-centered">{% trans "Recent Books" %}</h2>
|
||||
</div>
|
||||
|
||||
{% cache 60 * 60 %}
|
||||
{% get_current_language as LANGUAGE_CODE %}
|
||||
{% cache 60 * 60 LANGUAGE_CODE %}
|
||||
{% get_landing_books as books %}
|
||||
<section class="tile is-ancestor">
|
||||
<div class="tile is-vertical is-6">
|
||||
<div class="tile is-parent">
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% extends 'notifications/items/item_layout.html' %}
|
||||
{% extends 'notifications/items/layout.html' %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load utilities %}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% extends 'notifications/items/item_layout.html' %}
|
||||
{% extends 'notifications/items/layout.html' %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load utilities %}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% extends 'notifications/items/item_layout.html' %}
|
||||
{% extends 'notifications/items/layout.html' %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load utilities %}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% extends 'notifications/items/item_layout.html' %}
|
||||
{% extends 'notifications/items/layout.html' %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load utilities %}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% extends 'notifications/items/item_layout.html' %}
|
||||
{% extends 'notifications/items/layout.html' %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load utilities %}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% extends 'notifications/items/item_layout.html' %}
|
||||
{% extends 'notifications/items/layout.html' %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load utilities %}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% extends 'notifications/items/item_layout.html' %}
|
||||
{% extends 'notifications/items/layout.html' %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block primary_link %}{% spaceless %}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% extends 'notifications/items/item_layout.html' %}
|
||||
{% extends 'notifications/items/layout.html' %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load utilities %}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% extends 'notifications/items/item_layout.html' %}
|
||||
{% extends 'notifications/items/layout.html' %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load utilities %}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
{% load bookwyrm_tags %}
|
||||
{% related_status notification as related_status %}
|
||||
<div class="box is-shadowless has-background-white-ter {% if notification.id in unread %} is-primary{% endif %}">
|
||||
<div class="columns is-mobile">
|
||||
<div class="column is-narrow is-size-3 {% if notification.id in unread%}has-text-white{% else %}has-text-grey{% endif %}">
|
||||
<a class="has-text-dark" href="{% block primary_link %}{% endblock %}">
|
||||
<div class="notification {% if notification.id in unread %}has-background-primary{% endif %}">
|
||||
<div class="columns is-mobile {% if notification.id in unread %}has-text-white{% else %}has-text-grey{% endif %}">
|
||||
<div class="column is-narrow is-size-3">
|
||||
<a class="icon" href="{% block primary_link %}{% endblock %}">
|
||||
{% block icon %}{% endblock %}
|
||||
</a>
|
||||
</div>
|
|
@ -1,4 +1,4 @@
|
|||
{% extends 'notifications/items/item_layout.html' %}
|
||||
{% extends 'notifications/items/layout.html' %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load utilities %}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% extends 'notifications/items/item_layout.html' %}
|
||||
{% extends 'notifications/items/layout.html' %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load utilities %}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% extends 'notifications/items/item_layout.html' %}
|
||||
{% extends 'notifications/items/layout.html' %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load utilities %}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% extends 'notifications/items/item_layout.html' %}
|
||||
{% extends 'notifications/items/layout.html' %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load utilities %}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% extends 'notifications/items/item_layout.html' %}
|
||||
{% extends 'notifications/items/layout.html' %}
|
||||
|
||||
{% load i18n %}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% extends 'notifications/items/item_layout.html' %}
|
||||
{% extends 'notifications/items/layout.html' %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load utilities %}
|
||||
|
|
15
bookwyrm/templates/readthrough/readthrough.html
Normal file
15
bookwyrm/templates/readthrough/readthrough.html
Normal file
|
@ -0,0 +1,15 @@
|
|||
{% extends 'layout.html' %}
|
||||
{% load i18n %}
|
||||
{% load utilities %}
|
||||
|
||||
{% block title %}
|
||||
{% blocktrans trimmed with title=book|book_title %}
|
||||
Update read dates for "<em>{{ title }}</em>"
|
||||
{% endblocktrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% include "readthrough/readthrough_modal.html" with book=book active=True static=True %}
|
||||
|
||||
{% endblock %}
|
|
@ -4,6 +4,7 @@
|
|||
{% csrf_token %}
|
||||
<input type="hidden" name="id" value="{{ readthrough.id }}">
|
||||
<input type="hidden" name="book" value="{{ book.id }}">
|
||||
<input type="hidden" name="user" value="{{ request.user.id }}">
|
||||
<div class="field">
|
||||
<label class="label" tabindex="0" id="add_readthrough_focus_{{ readthrough.id }}" for="id_start_date_{{ readthrough.id }}">
|
||||
{% trans "Started reading" %}
|
|
@ -3,7 +3,7 @@
|
|||
{% load tz %}
|
||||
{% load utilities %}
|
||||
<div class="content">
|
||||
<div id="hide_edit_readthrough_{{ readthrough.id }}" class="box is-shadowless has-background-white-bis">
|
||||
<div class="box is-shadowless has-background-white-bis">
|
||||
<div class="columns">
|
||||
<div class="column">
|
||||
{% trans "Progress Updates:" %}
|
||||
|
@ -58,7 +58,11 @@
|
|||
<div class="field has-addons">
|
||||
<div class="control">
|
||||
{% trans "Edit read dates" as button_text %}
|
||||
{% include 'snippets/toggle/toggle_button.html' with class="is-small" text=button_text icon="pencil" controls_text="edit_readthrough" controls_uid=readthrough.id focus="edit_readthrough" %}
|
||||
<button class="button is-small" type="button" data-modal-open="edit_readthrough_{{ readthrough.id }}">
|
||||
<span class="icon icon-pencil" title="{{ button_text }}">
|
||||
<span class="is-sr-only">{{ button_text }}</span>
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="control">
|
||||
{% trans "Delete these read dates" as button_text %}
|
||||
|
@ -74,16 +78,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="box is-hidden" id="edit_readthrough_{{ readthrough.id }}" tabindex="0">
|
||||
<h3 class="title is-5">{% trans "Edit read dates" %}</h3>
|
||||
<form name="edit-readthrough" action="/edit-readthrough" method="post">
|
||||
{% include 'snippets/readthrough_form.html' with readthrough=readthrough %}
|
||||
<div class="field is-grouped">
|
||||
<button class="button is-primary" type="submit">{% trans "Save" %}</button>
|
||||
{% trans "Cancel" as button_text %}
|
||||
{% include 'snippets/toggle/close_button.html' with text=button_text controls_text="edit_readthrough" controls_uid=readthrough.id %}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{% join "delete_readthrough" readthrough.id as modal_id %}
|
||||
{% include 'book/delete_readthrough_modal.html' with id=modal_id %}
|
||||
{% join "edit_readthrough" readthrough.id as edit_modal_id %}
|
||||
{% include "readthrough/readthrough_modal.html" with readthrough=readthrough id=edit_modal_id %}
|
||||
{% join "delete_readthrough" readthrough.id as delete_modal_id %}
|
||||
{% include 'readthrough/delete_readthrough_modal.html' with id=delete_modal_id %}
|
80
bookwyrm/templates/readthrough/readthrough_modal.html
Normal file
80
bookwyrm/templates/readthrough/readthrough_modal.html
Normal file
|
@ -0,0 +1,80 @@
|
|||
{% extends "components/modal.html" %}
|
||||
{% load i18n %}
|
||||
{% load utilities %}
|
||||
|
||||
{% block modal-title %}
|
||||
|
||||
{% if readthrough %}
|
||||
{% blocktrans trimmed with title=book|book_title %}
|
||||
Update read dates for "<em>{{ title }}</em>"
|
||||
{% endblocktrans %}
|
||||
{% else %}
|
||||
{% blocktrans trimmed with title=book|book_title %}
|
||||
Add read dates for "<em>{{ title }}</em>"
|
||||
{% endblocktrans %}
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block modal-form-open %}
|
||||
<form name="add-readthrough-{{ readthrough.id }}" action="/create-readthrough" method="post">
|
||||
{% endblock %}
|
||||
|
||||
{% block modal-body %}
|
||||
{% csrf_token %}
|
||||
|
||||
<input type="hidden" name="id" value="{{ readthrough.id }}">
|
||||
<input type="hidden" name="book" value="{{ book.id }}">
|
||||
<input type="hidden" name="user" value="{{ request.user.id }}">
|
||||
<div class="field">
|
||||
<label class="label" tabindex="0" id="add_readthrough_focus_{{ readthrough.id }}" for="id_start_date_{{ readthrough.id }}">
|
||||
{% trans "Started reading" %}
|
||||
</label>
|
||||
{% firstof form.start_date.value readthrough.start_date|date:"Y-m-d" as value %}
|
||||
<input
|
||||
type="date"
|
||||
name="start_date"
|
||||
class="input"
|
||||
id="id_start_date_{{ readthrough.id }}"
|
||||
value="{{ value }}"
|
||||
aria-describedby="desc_start_date"
|
||||
>
|
||||
{% include 'snippets/form_errors.html' with errors_list=form.start_date.errors id="desc_start_date" %}
|
||||
</div>
|
||||
|
||||
{# Only show progress for editing existing readthroughs #}
|
||||
{% if readthrough.id and not readthrough.finish_date %}
|
||||
{% join "id_progress" readthrough.id as field_id %}
|
||||
<label class="label" for="{{ field_id }}">
|
||||
{% trans "Progress" %}
|
||||
</label>
|
||||
{% include "snippets/progress_field.html" with id=field_id %}
|
||||
{% endif %}
|
||||
|
||||
<div class="field">
|
||||
<label class="label" for="id_finish_date_{{ readthrough.id }}">
|
||||
{% trans "Finished reading" %}
|
||||
</label>
|
||||
{% firstof form.finish_date.value readthrough.finish_date|date:"Y-m-d" as value %}
|
||||
<input
|
||||
type="date"
|
||||
name="finish_date"
|
||||
class="input"
|
||||
id="id_finish_date_{{ readthrough.id }}"
|
||||
value="{{ value }}"
|
||||
aria-describedby="desc_finish_date"
|
||||
>
|
||||
{% include 'snippets/form_errors.html' with errors_list=form.finish_date.errors id="desc_finish_date" %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block modal-footer %}
|
||||
<button class="button is-primary" type="submit">{% trans "Save" %}</button>
|
||||
{% if not static %}
|
||||
<button type="button" class="button" data-modal-close>{% trans "Cancel" %}</button>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block modal-form-close %}
|
||||
</form>
|
||||
{% endblock %}
|
|
@ -75,9 +75,11 @@
|
|||
<form class="mt-1" action="/resolve-book" method="post">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="remote_id" value="{{ result.key }}">
|
||||
<button type="submit" class="button is-small is-link">
|
||||
{% trans "Import book" %}
|
||||
</button>
|
||||
<div class="control">
|
||||
<button type="submit" class="button is-small is-link">
|
||||
{% trans "Import book" %}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% load i18n %}
|
||||
{% load utilities %}
|
||||
|
||||
<table class="is-striped">
|
||||
<table class="is-striped is-fullwidth">
|
||||
<tr>
|
||||
<th>{% trans "URL" %}</th>
|
||||
<th>{% trans "Added by" %}</th>
|
||||
|
@ -9,7 +9,7 @@
|
|||
<th>{% trans "Book" %}</th>
|
||||
{% block additional_headers %}{% endblock %}
|
||||
</tr>
|
||||
{% for link in links%}
|
||||
{% for link in links %}
|
||||
<tr>
|
||||
<td class="overflow-wrap-anywhere">
|
||||
<a href="{{ link.url }}" target="_blank" rel="noopener">{{ link.url }}</a>
|
||||
|
@ -24,13 +24,19 @@
|
|||
</td>
|
||||
|
||||
<td>
|
||||
{% if link.filelink.filetype %}
|
||||
{% if link.filelink.book %}
|
||||
{% with book=link.filelink.book %}
|
||||
<a href="{{ book.local_path }}">{% include "snippets/book_titleby.html" with book=book %}</a>
|
||||
{% include "snippets/book_titleby.html" with book=book %}
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
</td>
|
||||
|
||||
{% block additional_data %}{% endblock %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% if not links %}
|
||||
<tr>
|
||||
<td colspan="7"><em>{% trans "No links available for this domain." %}</em></td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
</table>
|
||||
|
|
|
@ -19,6 +19,17 @@
|
|||
</h1>
|
||||
</header>
|
||||
|
||||
<nav class="breadcrumb subtitle" aria-label="breadcrumbs">
|
||||
<ul>
|
||||
<li><a href="{% url 'user-feed' user|username %}">{% trans "User profile" %}</a></li>
|
||||
<li class="is-active">
|
||||
<a href="#" aria-current="page">
|
||||
{% include "snippets/translated_shelf_name.html" with shelf=shelf %}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<nav class="block columns is-mobile scroll-x">
|
||||
<div class="column pr-0">
|
||||
<div class="tabs">
|
||||
|
@ -34,15 +45,7 @@
|
|||
href="{{ shelf_tab.local_path }}"
|
||||
{% if shelf_tab.identifier == shelf.identifier %} aria-current="page"{% endif %}
|
||||
>
|
||||
{% if shelf_tab.identifier == 'to-read' %}
|
||||
{% trans "To Read" %}
|
||||
{% elif shelf_tab.identifier == 'reading' %}
|
||||
{% trans "Currently Reading" %}
|
||||
{% elif shelf_tab.identifier == 'read' %}
|
||||
{% trans "Read" %}
|
||||
{% else %}
|
||||
{{ shelf_tab.name }}
|
||||
{% endif %}
|
||||
{% include 'user/books_header.html' with shelf=shelf_tab %}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
|
|
|
@ -3,16 +3,15 @@
|
|||
<summary class="is-flex is-align-items-center is-flex-wrap-wrap is-gap-2">
|
||||
<span class="mb-0 title {% if size == 'small' %}is-6{% else %}is-5{% endif %} is-flex-shrink-0">
|
||||
{% trans "Filters" %}
|
||||
|
||||
</span>
|
||||
|
||||
{% if filters_applied %}
|
||||
<span class="tag is-success is-light ml-2 mb-0 is-{{ size|default:'normal' }}">
|
||||
{{ _("Filters are applied") }}
|
||||
{% trans "Filters are applied" %}
|
||||
</span>
|
||||
{% endif %}
|
||||
|
||||
{% if request.GET %}
|
||||
{% if method != "post" and request.GET %}
|
||||
<span class="mb-0 tags has-addons">
|
||||
<span class="mb-0 tag is-success is-light is-{{ size|default:'normal' }}">
|
||||
{% trans "Filters are applied" %}
|
||||
|
|
|
@ -1,13 +1,18 @@
|
|||
{% load i18n %}
|
||||
{% load interaction %}
|
||||
|
||||
{% if request.user == user or not request.user.is_authenticated %}
|
||||
{% elif user in request.user.blocks.all %}
|
||||
{# nothing to see here -- either it's yourself or your logged out #}
|
||||
{% else %}
|
||||
|
||||
{% get_relationship user as relationship %}
|
||||
{% if relationship.is_blocked %}
|
||||
{% include 'snippets/block_button.html' with blocks=True %}
|
||||
{% else %}
|
||||
|
||||
<div class="field{% if not minimal %} has-addons{% else %} mb-0{% endif %}">
|
||||
<div class="control">
|
||||
<form action="{% url 'follow' %}" method="POST" class="interaction follow_{{ user.id }} {% if request.user in user.followers.all or request.user in user.follower_requests.all %}is-hidden{%endif %}" data-id="follow_{{ user.id }}">
|
||||
<form action="{% url 'follow' %}" method="POST" class="interaction follow_{{ user.id }} {% if relationship.is_following or relationship.is_follow_pending %}is-hidden{%endif %}" data-id="follow_{{ user.id }}">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="user" value="{{ user.username }}">
|
||||
<button class="button is-small{% if not minimal %} is-link{% endif %}" type="submit">
|
||||
|
@ -18,10 +23,10 @@
|
|||
{% endif %}
|
||||
</button>
|
||||
</form>
|
||||
<form action="{% url 'unfollow' %}" method="POST" class="interaction follow_{{ user.id }} {% if not request.user in user.followers.all and not request.user in user.follower_requests.all %}is-hidden{%endif %}" data-id="follow_{{ user.id }}">
|
||||
<form action="{% url 'unfollow' %}" method="POST" class="interaction follow_{{ user.id }} {% if not relationship.is_following and not relationship.is_follow_pending %}is-hidden{%endif %}" data-id="follow_{{ user.id }}">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="user" value="{{ user.username }}">
|
||||
{% if user.manually_approves_followers and request.user not in user.followers.all %}
|
||||
{% if user.manually_approves_followers and not relationship.is_following %}
|
||||
<button class="button is-small is-danger is-light" type="submit">
|
||||
{% trans "Undo follow request" %}
|
||||
</button>
|
||||
|
@ -42,4 +47,7 @@
|
|||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
|
|
|
@ -25,10 +25,7 @@
|
|||
|
||||
<button class="button is-fullwidth is-small shelf-option is-radiusless is-white" type="submit" {% if shelf.identifier == current.identifier %}disabled{% endif %}>
|
||||
<span>
|
||||
{% if shelf.identifier == 'to-read' %}{% trans "To Read" %}
|
||||
{% elif shelf.identifier == 'reading' %}{% trans "Currently Reading" %}
|
||||
{% elif shelf.identifier == 'read' %}{% trans "Read" %}
|
||||
{% else %}{{ shelf.name }}{% endif %}
|
||||
{% include "snippets/translated_shelf_name.html" with shelf=shelf %}
|
||||
</span>
|
||||
</button>
|
||||
</form>
|
||||
|
@ -41,20 +38,23 @@
|
|||
|
||||
{% trans "Start reading" as button_text %}
|
||||
{% url 'reading-status' 'start' book.id as fallback_url %}
|
||||
{% include 'snippets/toggle/toggle_button.html' with class=button_class text=button_text controls_text="start_reading" controls_uid=uuid focus="modal_title_start_reading" disabled=is_current fallback_url=fallback_url %}
|
||||
{% join "start_reading" uuid as modal_id %}
|
||||
{% include 'snippets/shelve_button/modal_button.html' with class=button_class fallback_url=fallback_url %}
|
||||
|
||||
|
||||
{% elif shelf.identifier == 'read' %}
|
||||
|
||||
{% trans "Read" as button_text %}
|
||||
{% url 'reading-status' 'finish' book.id as fallback_url %}
|
||||
{% include 'snippets/toggle/toggle_button.html' with class=button_class text=button_text controls_text="finish_reading" controls_uid=uuid focus="modal_title_finish_reading" disabled=is_current fallback_url=fallback_url %}
|
||||
{% join "finish_reading" uuid as modal_id %}
|
||||
{% include 'snippets/shelve_button/modal_button.html' with class=button_class fallback_url=fallback_url %}
|
||||
|
||||
{% elif shelf.identifier == 'to-read' %}
|
||||
|
||||
{% trans "Want to read" as button_text %}
|
||||
{% url 'reading-status' 'want' book.id as fallback_url %}
|
||||
{% include 'snippets/toggle/toggle_button.html' with class=button_class text=button_text controls_text="want_to_read" controls_uid=uuid focus="modal_title_want_to_read" disabled=is_current fallback_url=fallback_url %}
|
||||
{% join "want_to_read" uuid as modal_id %}
|
||||
{% include 'snippets/shelve_button/modal_button.html' with class=button_class fallback_url=fallback_url %}
|
||||
|
||||
{% endif %}
|
||||
</li>
|
||||
|
@ -95,7 +95,7 @@
|
|||
{% include 'snippets/reading_modals/start_reading_modal.html' with book=active_shelf.book id=modal_id move_from=current.id refresh=True class="" %}
|
||||
|
||||
{% join "finish_reading" uuid as modal_id %}
|
||||
{% include 'snippets/reading_modals/finish_reading_modal.html' with book=active_shelf.book id=modal_id move_from=current.id readthrough=readthrough refresh=True class="" %}
|
||||
{% include 'snippets/reading_modals/finish_reading_modal.html' with book=active_shelf.book id=modal_id move_from=current.id readthrough=readthrough refresh=True class="" %}
|
||||
|
||||
{% endwith %}
|
||||
{% endblock %}
|
||||
|
|
12
bookwyrm/templates/snippets/translated_shelf_name.html
Normal file
12
bookwyrm/templates/snippets/translated_shelf_name.html
Normal file
|
@ -0,0 +1,12 @@
|
|||
{% load i18n %}
|
||||
{% if shelf.identifier == 'all' %}
|
||||
{% trans "All books" %}
|
||||
{% elif shelf.identifier == 'to-read' %}
|
||||
{% trans "To Read" %}
|
||||
{% elif shelf.identifier == 'reading' %}
|
||||
{% trans "Currently Reading" %}
|
||||
{% elif shelf.identifier == 'read' %}
|
||||
{% trans "Read" %}
|
||||
{% else %}
|
||||
{{ shelf.name }}
|
||||
{% endif %}
|
|
@ -1,16 +1,10 @@
|
|||
{% load i18n %}
|
||||
{% if is_self %}
|
||||
{% if shelf.identifier == 'to-read' %}
|
||||
{% trans "To Read" %}
|
||||
{% elif shelf.identifier == 'reading' %}
|
||||
{% trans "Currently Reading" %}
|
||||
{% elif shelf.identifier == 'read' %}
|
||||
{% trans "Read" %}
|
||||
{% elif shelf.identifier == 'all' %}
|
||||
{% trans "Your books" %}
|
||||
{% if shelf.identifier == 'all' %}
|
||||
{% trans "Your books" %}
|
||||
{% else %}
|
||||
{% include "snippets/translated_shelf_name.html" with shelf=shelf %}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{{ shelf.name }}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{% blocktrans with username=user.display_name %}{{ username }}'s books{% endblocktrans %}
|
||||
{% blocktrans with username=user.display_name %}{{ username }}'s books{% endblocktrans %}
|
||||
{% endif %}
|
||||
|
|
|
@ -3,6 +3,7 @@ from django import template
|
|||
from django.db.models import Avg, StdDev, Count, F, Q
|
||||
|
||||
from bookwyrm import models
|
||||
from bookwyrm.utils import cache
|
||||
from bookwyrm.views.feed import get_suggested_books
|
||||
|
||||
|
||||
|
@ -130,35 +131,55 @@ def related_status(notification):
|
|||
@register.simple_tag(takes_context=True)
|
||||
def active_shelf(context, book):
|
||||
"""check what shelf a user has a book on, if any"""
|
||||
if hasattr(book, "current_shelves"):
|
||||
read_shelves = [
|
||||
s
|
||||
for s in book.current_shelves
|
||||
if s.shelf.identifier in models.Shelf.READ_STATUS_IDENTIFIERS
|
||||
]
|
||||
return read_shelves[0] if len(read_shelves) else {"book": book}
|
||||
|
||||
shelf = (
|
||||
models.ShelfBook.objects.filter(
|
||||
shelf__user=context["request"].user,
|
||||
book__parent_work__editions=book,
|
||||
user = context["request"].user
|
||||
return (
|
||||
cache.get_or_set(
|
||||
f"active_shelf-{user.id}-{book.id}",
|
||||
lambda u, b: (
|
||||
models.ShelfBook.objects.filter(
|
||||
shelf__user=u,
|
||||
book__parent_work__editions=b,
|
||||
).first()
|
||||
),
|
||||
user,
|
||||
book,
|
||||
timeout=15552000,
|
||||
)
|
||||
.select_related("book", "shelf")
|
||||
.first()
|
||||
or {"book": book}
|
||||
)
|
||||
return shelf if shelf else {"book": book}
|
||||
|
||||
|
||||
@register.simple_tag(takes_context=False)
|
||||
def latest_read_through(book, user):
|
||||
"""the most recent read activity"""
|
||||
if hasattr(book, "active_readthroughs"):
|
||||
return book.active_readthroughs[0] if len(book.active_readthroughs) else None
|
||||
return cache.get_or_set(
|
||||
f"latest_read_through-{user.id}-{book.id}",
|
||||
lambda u, b: (
|
||||
models.ReadThrough.objects.filter(user=u, book=b, is_active=True)
|
||||
.order_by("-start_date")
|
||||
.first()
|
||||
),
|
||||
user,
|
||||
book,
|
||||
timeout=15552000,
|
||||
)
|
||||
|
||||
return (
|
||||
models.ReadThrough.objects.filter(user=user, book=book, is_active=True)
|
||||
.order_by("-start_date")
|
||||
.first()
|
||||
|
||||
@register.simple_tag(takes_context=False)
|
||||
def get_landing_books():
|
||||
"""list of books for the landing page"""
|
||||
return list(
|
||||
set(
|
||||
models.Edition.objects.filter(
|
||||
review__published_date__isnull=False,
|
||||
review__deleted=False,
|
||||
review__user__local=True,
|
||||
review__privacy__in=["public", "unlisted"],
|
||||
)
|
||||
.exclude(cover__exact="")
|
||||
.distinct()
|
||||
.order_by("-review__published_date")[:6]
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
""" template filters for status interaction buttons """
|
||||
from django import template
|
||||
from django.core.cache import cache
|
||||
|
||||
from bookwyrm import models
|
||||
from bookwyrm.utils.cache import get_or_set
|
||||
|
||||
|
||||
register = template.Library()
|
||||
|
@ -11,20 +11,23 @@ register = template.Library()
|
|||
@register.filter(name="liked")
|
||||
def get_user_liked(user, status):
|
||||
"""did the given user fav a status?"""
|
||||
return cache.get_or_set(
|
||||
return get_or_set(
|
||||
f"fav-{user.id}-{status.id}",
|
||||
models.Favorite.objects.filter(user=user, status=status).exists(),
|
||||
259200,
|
||||
lambda u, s: models.Favorite.objects.filter(user=u, status=s).exists(),
|
||||
user,
|
||||
status,
|
||||
timeout=259200,
|
||||
)
|
||||
|
||||
|
||||
@register.filter(name="boosted")
|
||||
def get_user_boosted(user, status):
|
||||
"""did the given user fav a status?"""
|
||||
return cache.get_or_set(
|
||||
return get_or_set(
|
||||
f"boost-{user.id}-{status.id}",
|
||||
status.boosters.filter(user=user).exists(),
|
||||
259200,
|
||||
lambda u: status.boosters.filter(user=u).exists(),
|
||||
user,
|
||||
timeout=259200,
|
||||
)
|
||||
|
||||
|
||||
|
@ -32,3 +35,32 @@ def get_user_boosted(user, status):
|
|||
def get_user_saved_lists(user, book_list):
|
||||
"""did the user save a list"""
|
||||
return user.saved_lists.filter(id=book_list.id).exists()
|
||||
|
||||
|
||||
@register.simple_tag(takes_context=True)
|
||||
def get_relationship(context, user_object):
|
||||
"""caches the relationship between the logged in user and another user"""
|
||||
user = context["request"].user
|
||||
return get_or_set(
|
||||
f"relationship-{user.id}-{user_object.id}",
|
||||
get_relationship_name,
|
||||
user,
|
||||
user_object,
|
||||
timeout=259200,
|
||||
)
|
||||
|
||||
|
||||
def get_relationship_name(user, user_object):
|
||||
"""returns the relationship type"""
|
||||
types = {
|
||||
"is_following": False,
|
||||
"is_follow_pending": False,
|
||||
"is_blocked": False,
|
||||
}
|
||||
if user_object in user.blocks.all():
|
||||
types["is_blocked"] = True
|
||||
elif user_object in user.following.all():
|
||||
types["is_following"] = True
|
||||
elif user_object in user.follower_requests.all():
|
||||
types["is_follow_pending"] = True
|
||||
return types
|
||||
|
|
|
@ -29,6 +29,7 @@ class LinkDomainViews(TestCase):
|
|||
models.FileLink.objects.create(
|
||||
book=self.book,
|
||||
url="https://beep.com/book/1",
|
||||
added_by=self.local_user,
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
|
|
@ -37,7 +37,7 @@ class ReportViews(TestCase):
|
|||
|
||||
def test_reports_page(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.Reports.as_view()
|
||||
view = views.ReportsAdmin.as_view()
|
||||
request = self.factory.get("")
|
||||
request.user = self.local_user
|
||||
request.user.is_superuser = True
|
||||
|
@ -49,7 +49,7 @@ class ReportViews(TestCase):
|
|||
|
||||
def test_reports_page_with_data(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.Reports.as_view()
|
||||
view = views.ReportsAdmin.as_view()
|
||||
request = self.factory.get("")
|
||||
request.user = self.local_user
|
||||
request.user.is_superuser = True
|
||||
|
@ -62,7 +62,7 @@ class ReportViews(TestCase):
|
|||
|
||||
def test_report_page(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.Report.as_view()
|
||||
view = views.ReportAdmin.as_view()
|
||||
request = self.factory.get("")
|
||||
request.user = self.local_user
|
||||
request.user.is_superuser = True
|
||||
|
@ -76,7 +76,7 @@ class ReportViews(TestCase):
|
|||
|
||||
def test_report_comment(self):
|
||||
"""comment on a report"""
|
||||
view = views.Report.as_view()
|
||||
view = views.ReportAdmin.as_view()
|
||||
request = self.factory.post("", {"note": "hi"})
|
||||
request.user = self.local_user
|
||||
request.user.is_superuser = True
|
||||
|
@ -97,7 +97,7 @@ class ReportViews(TestCase):
|
|||
request = self.factory.post("", form.data)
|
||||
request.user = self.local_user
|
||||
|
||||
views.make_report(request)
|
||||
views.Report.as_view()(request)
|
||||
|
||||
report = models.Report.objects.get()
|
||||
self.assertEqual(report.reporter, self.local_user)
|
||||
|
|
|
@ -48,9 +48,9 @@ class LinkViews(TestCase):
|
|||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_edit_link_page(self):
|
||||
def test_add_link_page(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.FileLink.as_view()
|
||||
view = views.AddFileLink.as_view()
|
||||
request = self.factory.get("")
|
||||
request.user = self.local_user
|
||||
result = view(request, self.book.id)
|
||||
|
@ -59,14 +59,14 @@ class LinkViews(TestCase):
|
|||
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
def test_edit_link_post(self, *_):
|
||||
def test_add_link_post(self, *_):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.FileLink.as_view()
|
||||
view = views.AddFileLink.as_view()
|
||||
form = forms.FileLinkForm()
|
||||
form.data["url"] = "https://www.example.com"
|
||||
form.data["filetype"] = "HTML"
|
||||
form.data["book"] = self.book.id
|
||||
form.data["added_by"] = self.local_user
|
||||
form.data["added_by"] = self.local_user.id
|
||||
|
||||
request = self.factory.post("", form.data)
|
||||
request.user = self.local_user
|
||||
|
|
|
@ -6,6 +6,7 @@ from unittest.mock import patch
|
|||
from django.test import TestCase
|
||||
|
||||
from bookwyrm import models, views
|
||||
from bookwyrm.activitypub.base_activity import set_related_field
|
||||
|
||||
|
||||
# pylint: disable=too-many-public-methods
|
||||
|
@ -147,6 +148,46 @@ class InboxUpdate(TestCase):
|
|||
self.assertEqual(book.title, "Piranesi")
|
||||
self.assertEqual(book.last_edited_by, self.remote_user)
|
||||
|
||||
def test_update_edition_links(self):
|
||||
"""add links to edition"""
|
||||
datafile = pathlib.Path(__file__).parent.joinpath("../../data/bw_edition.json")
|
||||
bookdata = json.loads(datafile.read_bytes())
|
||||
del bookdata["authors"]
|
||||
# pylint: disable=line-too-long
|
||||
link_data = {
|
||||
"href": "https://openlibrary.org/books/OL11645413M/Queen_Victoria/daisy",
|
||||
"mediaType": "Daisy",
|
||||
"attributedTo": self.remote_user.remote_id
|
||||
}
|
||||
bookdata["fileLinks"] = [link_data]
|
||||
|
||||
models.Work.objects.create(
|
||||
title="Test Work", remote_id="https://bookwyrm.social/book/5988"
|
||||
)
|
||||
book = models.Edition.objects.create(
|
||||
title="Test Book", remote_id="https://bookwyrm.social/book/5989"
|
||||
)
|
||||
self.assertFalse(book.file_links.exists())
|
||||
|
||||
with patch("bookwyrm.activitypub.base_activity.set_related_field.delay") as mock:
|
||||
views.inbox.activity_task(
|
||||
{
|
||||
"type": "Update",
|
||||
"to": [],
|
||||
"cc": [],
|
||||
"actor": "hi",
|
||||
"id": "sdkjf",
|
||||
"object": bookdata,
|
||||
}
|
||||
)
|
||||
args = mock.call_args[0]
|
||||
self.assertEqual(args[0], "FileLink")
|
||||
self.assertEqual(args[1], "Edition")
|
||||
self.assertEqual(args[2], "book")
|
||||
self.assertEqual(args[3], book.remote_id)
|
||||
self.assertEqual(args[4], link_data)
|
||||
# idk how to test that related name works, because of the transaction
|
||||
|
||||
def test_update_work(self):
|
||||
"""update an existing edition"""
|
||||
datafile = pathlib.Path(__file__).parent.joinpath("../../data/bw_work.json")
|
||||
|
|
|
@ -231,11 +231,12 @@ class ReadingViews(TestCase):
|
|||
"finish_date": "2018-03-07",
|
||||
"book": self.book.id,
|
||||
"id": "",
|
||||
"user": self.local_user.id,
|
||||
},
|
||||
)
|
||||
request.user = self.local_user
|
||||
|
||||
views.create_readthrough(request)
|
||||
views.ReadThrough.as_view()(request)
|
||||
readthrough = models.ReadThrough.objects.get()
|
||||
self.assertEqual(readthrough.start_date.year, 2017)
|
||||
self.assertEqual(readthrough.start_date.month, 1)
|
||||
|
|
|
@ -41,10 +41,8 @@ class ReadThrough(TestCase):
|
|||
self.assertEqual(self.edition.readthrough_set.count(), 0)
|
||||
|
||||
self.client.post(
|
||||
"/reading-status/start/{}".format(self.edition.id),
|
||||
{
|
||||
"start_date": "2020-11-27",
|
||||
},
|
||||
f"/reading-status/start/{self.edition.id}",
|
||||
{"start_date": "2020-11-27"},
|
||||
)
|
||||
|
||||
readthroughs = self.edition.readthrough_set.all()
|
||||
|
@ -62,10 +60,8 @@ class ReadThrough(TestCase):
|
|||
self.assertEqual(self.edition.readthrough_set.count(), 0)
|
||||
|
||||
self.client.post(
|
||||
"/reading-status/start/{}".format(self.edition.id),
|
||||
{
|
||||
"start_date": "2020-11-27",
|
||||
},
|
||||
f"/reading-status/start/{self.edition.id}",
|
||||
{"start_date": "2020-11-27"},
|
||||
)
|
||||
|
||||
readthroughs = self.edition.readthrough_set.all()
|
||||
|
|
|
@ -168,6 +168,7 @@ urlpatterns = [
|
|||
views.LinkDomain.as_view(),
|
||||
name="settings-link-domain",
|
||||
),
|
||||
# pylint: disable=line-too-long
|
||||
re_path(
|
||||
r"^setting/link-domains/(?P<status>(pending|approved|blocked))/(?P<domain_id>\d+)/?$",
|
||||
views.LinkDomain.as_view(),
|
||||
|
@ -468,12 +469,19 @@ urlpatterns = [
|
|||
views.add_description,
|
||||
name="add-description",
|
||||
),
|
||||
re_path(rf"{BOOK_PATH}/filelink/?$", views.FileLink.as_view(), name="file-link"),
|
||||
re_path(
|
||||
rf"{BOOK_PATH}/filelink/(?P<link_id>\d+)/?$",
|
||||
views.FileLink.as_view(),
|
||||
rf"{BOOK_PATH}/filelink/?$", views.BookFileLinks.as_view(), name="file-link"
|
||||
),
|
||||
re_path(
|
||||
rf"{BOOK_PATH}/filelink/(?P<link_id>\d+)/delete/?$",
|
||||
views.BookFileLinks.as_view(),
|
||||
name="file-link",
|
||||
),
|
||||
re_path(
|
||||
rf"{BOOK_PATH}/filelink/add/?$",
|
||||
views.AddFileLink.as_view(),
|
||||
name="file-link-add",
|
||||
),
|
||||
re_path(r"^resolve-book/?$", views.resolve_book, name="resolve-book"),
|
||||
re_path(r"^switch-edition/?$", views.switch_edition, name="switch-edition"),
|
||||
re_path(
|
||||
|
@ -500,7 +508,11 @@ urlpatterns = [
|
|||
# reading progress
|
||||
re_path(r"^edit-readthrough/?$", views.edit_readthrough, name="edit-readthrough"),
|
||||
re_path(r"^delete-readthrough/?$", views.delete_readthrough),
|
||||
re_path(r"^create-readthrough/?$", views.create_readthrough),
|
||||
re_path(
|
||||
r"^create-readthrough/?$",
|
||||
views.ReadThrough.as_view(),
|
||||
name="create-readthrough",
|
||||
),
|
||||
re_path(r"^delete-progressupdate/?$", views.delete_progressupdate),
|
||||
# shelve actions
|
||||
re_path(
|
||||
|
|
11
bookwyrm/utils/cache.py
Normal file
11
bookwyrm/utils/cache.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
""" Custom handler for caching """
|
||||
from django.core.cache import cache
|
||||
|
||||
|
||||
def get_or_set(cache_key, function, *args, timeout=None):
|
||||
"""Django's built-in get_or_set isn't cutting it"""
|
||||
value = cache.get(cache_key)
|
||||
if value is None:
|
||||
value = function(*args)
|
||||
cache.set(cache_key, value, timeout=timeout)
|
||||
return value
|
|
@ -37,7 +37,7 @@ from .books.books import (
|
|||
from .books.books import update_book_from_remote
|
||||
from .books.edit_book import EditBook, ConfirmEditBook
|
||||
from .books.editions import Editions, switch_edition
|
||||
from .books.links import FileLink
|
||||
from .books.links import BookFileLinks, AddFileLink
|
||||
|
||||
# landing
|
||||
from .landing.about import about, privacy, conduct
|
||||
|
@ -94,7 +94,7 @@ from .list import Lists, SavedLists, List, Curate, UserLists
|
|||
from .list import save_list, unsave_list, delete_list, unsafe_embed_list
|
||||
from .notifications import Notifications
|
||||
from .outbox import Outbox
|
||||
from .reading import create_readthrough, delete_readthrough, delete_progressupdate
|
||||
from .reading import ReadThrough, delete_readthrough, delete_progressupdate
|
||||
from .reading import ReadingStatus
|
||||
from .report import Report
|
||||
from .rss_feed import RssFeed
|
||||
|
|
|
@ -16,7 +16,6 @@ from django.views.decorators.http import require_POST
|
|||
|
||||
from bookwyrm import emailing, forms, models
|
||||
from bookwyrm.settings import PAGE_LENGTH
|
||||
from bookwyrm.views import helpers
|
||||
|
||||
|
||||
# pylint: disable= no-self-use
|
||||
|
@ -174,7 +173,6 @@ class InviteRequest(View):
|
|||
data = {
|
||||
"request_form": form,
|
||||
"request_received": received,
|
||||
"books": helpers.get_landing_books(),
|
||||
}
|
||||
return TemplateResponse(request, "landing/landing.html", data)
|
||||
|
||||
|
|
|
@ -7,29 +7,39 @@ from django.views import View
|
|||
from django.utils.decorators import method_decorator
|
||||
|
||||
from bookwyrm import forms, models
|
||||
from bookwyrm.activitypub import ActivitypubResponse
|
||||
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
class BookFileLinks(View):
|
||||
"""View all links"""
|
||||
|
||||
def get(self, request, book_id):
|
||||
"""view links"""
|
||||
book = get_object_or_404(models.Edition, id=book_id)
|
||||
return TemplateResponse(request, "book/file_links/edit_links.html", {"book": book})
|
||||
|
||||
def post(self, request, book_id, link_id):
|
||||
"""delete link"""
|
||||
link = get_object_or_404(models.FileLink, id=link_id, book=book_id)
|
||||
link.delete()
|
||||
return self.get(request, book_id)
|
||||
|
||||
|
||||
@method_decorator(login_required, name="dispatch")
|
||||
@method_decorator(
|
||||
permission_required("bookwyrm.edit_book", raise_exception=True), name="dispatch"
|
||||
)
|
||||
class FileLink(View):
|
||||
class AddFileLink(View):
|
||||
"""a book! this is the stuff"""
|
||||
|
||||
def get(self, request, book_id=None, link_id=None):
|
||||
"""info about a book"""
|
||||
link = get_object_or_404(models.FileLink, id=link_id) if link_id else None
|
||||
if not book_id:
|
||||
return ActivitypubResponse(link.to_activity())
|
||||
|
||||
def get(self, request, book_id):
|
||||
"""Create link form"""
|
||||
book = get_object_or_404(models.Edition, id=book_id)
|
||||
data = {
|
||||
"file_link_form": forms.FileLinkForm(instance=link),
|
||||
"file_link_form": forms.FileLinkForm(),
|
||||
"book": book,
|
||||
}
|
||||
return TemplateResponse(request, "book/file_link_page.html", data)
|
||||
return TemplateResponse(request, "book/file_links/file_link_page.html", data)
|
||||
|
||||
@transaction.atomic
|
||||
def post(self, request, book_id, link_id=None):
|
||||
|
@ -39,7 +49,7 @@ class FileLink(View):
|
|||
form = forms.FileLinkForm(request.POST, instance=link)
|
||||
if not form.is_valid():
|
||||
data = {"file_link_form": form, "book": book}
|
||||
return TemplateResponse(request, "book/file_link_page.html", data)
|
||||
return TemplateResponse(request, "book/file_links/file_link_page.html", data)
|
||||
|
||||
link = form.save()
|
||||
book.file_links.add(link)
|
||||
|
|
|
@ -153,24 +153,6 @@ def is_blocked(viewer, user):
|
|||
return False
|
||||
|
||||
|
||||
def get_landing_books():
|
||||
"""list of books for the landing page"""
|
||||
|
||||
return list(
|
||||
set(
|
||||
models.Edition.objects.filter(
|
||||
review__published_date__isnull=False,
|
||||
review__deleted=False,
|
||||
review__user__local=True,
|
||||
review__privacy__in=["public", "unlisted"],
|
||||
)
|
||||
.exclude(cover__exact="")
|
||||
.distinct()
|
||||
.order_by("-review__published_date")[:6]
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def load_date_in_user_tz_as_utc(date_str: str, user: models.User) -> datetime:
|
||||
"""ensures that data is stored consistently in the UTC timezone"""
|
||||
if not date_str:
|
||||
|
|
|
@ -3,7 +3,6 @@ from django.template.response import TemplateResponse
|
|||
from django.views import View
|
||||
|
||||
from bookwyrm import forms
|
||||
from bookwyrm.views import helpers
|
||||
from bookwyrm.views.feed import Feed
|
||||
|
||||
|
||||
|
@ -28,6 +27,5 @@ class Landing(View):
|
|||
data = {
|
||||
"register_form": forms.RegisterForm(),
|
||||
"request_form": forms.InviteRequestForm(),
|
||||
"books": helpers.get_landing_books(),
|
||||
}
|
||||
return TemplateResponse(request, "landing/landing.html", data)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
""" the good stuff! the books! """
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.core.cache import cache
|
||||
from django.core.cache.utils import make_template_fragment_key
|
||||
from django.db import transaction
|
||||
from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseNotFound
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
|
@ -10,16 +9,16 @@ from django.utils.decorators import method_decorator
|
|||
from django.views import View
|
||||
from django.views.decorators.http import require_POST
|
||||
|
||||
from bookwyrm import models
|
||||
from bookwyrm import forms, models
|
||||
from bookwyrm.views.shelf.shelf_actions import unshelve
|
||||
from .status import CreateStatus
|
||||
from .helpers import get_edition, handle_reading_status, is_api_request
|
||||
from .helpers import load_date_in_user_tz_as_utc
|
||||
|
||||
|
||||
@method_decorator(login_required, name="dispatch")
|
||||
# pylint: disable=no-self-use
|
||||
# pylint: disable=too-many-return-statements
|
||||
@method_decorator(login_required, name="dispatch")
|
||||
class ReadingStatus(View):
|
||||
"""consider reading a book"""
|
||||
|
||||
|
@ -46,12 +45,10 @@ class ReadingStatus(View):
|
|||
if not identifier:
|
||||
return HttpResponseBadRequest()
|
||||
|
||||
# invalidate the template cache
|
||||
cache_keys = [
|
||||
make_template_fragment_key("shelve_button", [request.user.id, book_id]),
|
||||
make_template_fragment_key("suggested_books", [request.user.id]),
|
||||
]
|
||||
cache.delete_many(cache_keys)
|
||||
# invalidate related caches
|
||||
cache.delete(
|
||||
f"active_shelf-{request.user.id}-{book_id}",
|
||||
)
|
||||
|
||||
desired_shelf = get_object_or_404(
|
||||
models.Shelf, identifier=identifier, user=request.user
|
||||
|
@ -118,6 +115,45 @@ class ReadingStatus(View):
|
|||
return redirect(referer)
|
||||
|
||||
|
||||
@method_decorator(login_required, name="dispatch")
|
||||
class ReadThrough(View):
|
||||
"""Add new read dates"""
|
||||
|
||||
def get(self, request, book_id, readthrough_id=None):
|
||||
"""standalone form in case of errors"""
|
||||
book = get_object_or_404(models.Edition, id=book_id)
|
||||
form = forms.ReadThroughForm()
|
||||
data = {"form": form, "book": book}
|
||||
if readthrough_id:
|
||||
data["readthrough"] = get_object_or_404(
|
||||
models.ReadThrough, id=readthrough_id
|
||||
)
|
||||
return TemplateResponse(request, "readthrough/readthrough.html", data)
|
||||
|
||||
def post(self, request):
|
||||
"""can't use the form normally because the dates are too finnicky"""
|
||||
book_id = request.POST.get("book")
|
||||
normalized_post = request.POST.copy()
|
||||
|
||||
normalized_post["start_date"] = load_date_in_user_tz_as_utc(
|
||||
request.POST.get("start_date"), request.user
|
||||
)
|
||||
normalized_post["finish_date"] = load_date_in_user_tz_as_utc(
|
||||
request.POST.get("finish_date"), request.user
|
||||
)
|
||||
form = forms.ReadThroughForm(request.POST)
|
||||
if not form.is_valid():
|
||||
book = get_object_or_404(models.Edition, id=book_id)
|
||||
data = {"form": form, "book": book}
|
||||
if request.POST.get("id"):
|
||||
data["readthrough"] = get_object_or_404(
|
||||
models.ReadThrough, id=request.POST.get("id")
|
||||
)
|
||||
return TemplateResponse(request, "readthrough/readthrough.html", data)
|
||||
form.save()
|
||||
return redirect("book", book_id)
|
||||
|
||||
|
||||
@transaction.atomic
|
||||
def update_readthrough_on_shelve(
|
||||
user, annotated_book, status, start_date=None, finish_date=None
|
||||
|
@ -159,27 +195,6 @@ def delete_readthrough(request):
|
|||
return redirect(request.headers.get("Referer", "/"))
|
||||
|
||||
|
||||
@login_required
|
||||
@require_POST
|
||||
def create_readthrough(request):
|
||||
"""can't use the form because the dates are too finnicky"""
|
||||
book = get_object_or_404(models.Edition, id=request.POST.get("book"))
|
||||
|
||||
start_date = load_date_in_user_tz_as_utc(
|
||||
request.POST.get("start_date"), request.user
|
||||
)
|
||||
finish_date = load_date_in_user_tz_as_utc(
|
||||
request.POST.get("finish_date"), request.user
|
||||
)
|
||||
models.ReadThrough.objects.create(
|
||||
user=request.user,
|
||||
book=book,
|
||||
start_date=start_date,
|
||||
finish_date=finish_date,
|
||||
)
|
||||
return redirect("book", book.id)
|
||||
|
||||
|
||||
@login_required
|
||||
@require_POST
|
||||
def delete_progressupdate(request):
|
||||
|
|
|
@ -159,6 +159,7 @@ def update_progress(request, book_id): # pylint: disable=unused-argument
|
|||
@require_POST
|
||||
def edit_readthrough(request):
|
||||
"""can't use the form because the dates are too finnicky"""
|
||||
# TODO: remove this, it duplicates the code in the ReadThrough view
|
||||
readthrough = get_object_or_404(models.ReadThrough, id=request.POST.get("id"))
|
||||
readthrough.raise_not_editable(request.user)
|
||||
|
||||
|
|
|
@ -6,13 +6,18 @@ markers =
|
|||
integration: marks tests as requiring external resources (deselect with '-m "not integration"')
|
||||
|
||||
env =
|
||||
SECRET_KEY = beepbeep
|
||||
DEBUG = false
|
||||
USE_HTTPS=true
|
||||
USE_HTTPS = true
|
||||
DOMAIN = your.domain.here
|
||||
BOOKWYRM_DATABASE_BACKEND = postgres
|
||||
MEDIA_ROOT = images/
|
||||
CELERY_BROKER = ""
|
||||
REDIS_BROKER_PORT = 6379
|
||||
REDIS_BROKER_PASSWORD = beep
|
||||
REDIS_ACTIVITY_PORT = 6379
|
||||
REDIS_ACTIVITY_PASSWORD = beep
|
||||
USE_DUMMY_CACHE = true
|
||||
FLOWER_PORT = 8888
|
||||
EMAIL_HOST = "smtp.mailgun.org"
|
||||
EMAIL_PORT = 587
|
||||
|
@ -20,4 +25,3 @@ env =
|
|||
EMAIL_HOST_PASSWORD = ""
|
||||
EMAIL_USE_TLS = true
|
||||
ENABLE_PREVIEW_IMAGES = false
|
||||
USE_S3 = false
|
||||
|
|
Loading…
Reference in a new issue