fixing errors from checks

This commit is contained in:
Orage Pika
2022-03-13 13:31:38 +01:00
54 changed files with 4055 additions and 3027 deletions

View File

@ -19,11 +19,11 @@ def download_file(url, destination):
with open(destination, "b+w") as outfile:
outfile.write(stream.read())
except (urllib.error.HTTPError, urllib.error.URLError):
logger.error("Failed to download file %s", url)
logger.info("Failed to download file %s", url)
except OSError:
logger.error("Couldn't open font file %s for writing", destination)
logger.info("Couldn't open font file %s for writing", destination)
except: # pylint: disable=bare-except
logger.exception("Unknown error in file download")
logger.info("Unknown error in file download")
class BookwyrmConfig(AppConfig):

View File

@ -131,7 +131,7 @@ class AbstractConnector(AbstractMinimalConnector):
try:
work_data = self.get_work_from_edition_data(data)
except (KeyError, ConnectorException) as err:
logger.exception(err)
logger.info(err)
work_data = data
if not work_data or not edition_data:
@ -270,7 +270,7 @@ def get_data(url, params=None, timeout=10):
timeout=timeout,
)
except RequestException as err:
logger.exception(err)
logger.info(err)
raise ConnectorException(err)
if not resp.ok:
@ -278,7 +278,7 @@ def get_data(url, params=None, timeout=10):
try:
data = resp.json()
except ValueError as err:
logger.exception(err)
logger.info(err)
raise ConnectorException(err)
return data
@ -296,7 +296,7 @@ def get_image(url, timeout=10):
timeout=timeout,
)
except RequestException as err:
logger.exception(err)
logger.info(err)
return None, None
if not resp.ok:
@ -305,7 +305,7 @@ def get_image(url, timeout=10):
image_content = ContentFile(resp.content)
extension = imghdr.what(None, image_content.read())
if not extension:
logger.exception("File requested was not an image: %s", url)
logger.info("File requested was not an image: %s", url)
return None, None
return image_content, extension

View File

@ -39,7 +39,7 @@ def search(query, min_confidence=0.1, return_first=False):
try:
result_set = connector.isbn_search(isbn)
except Exception as err: # pylint: disable=broad-except
logger.exception(err)
logger.info(err)
# if this fails, we can still try regular search
# if no isbn search results, we fallback to generic search
@ -48,7 +48,7 @@ def search(query, min_confidence=0.1, return_first=False):
result_set = connector.search(query, min_confidence=min_confidence)
except Exception as err: # pylint: disable=broad-except
# we don't want *any* error to crash the whole search page
logger.exception(err)
logger.info(err)
continue
if return_first and result_set:

View File

@ -0,0 +1,31 @@
# Generated by Django 3.2.12 on 2022-03-12 10:16
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("bookwyrm", "0144_alter_announcement_display_type"),
]
operations = [
migrations.AddField(
model_name="inviterequest",
name="answer",
field=models.TextField(default="Foundation by Isaac Azimov", max_length=50),
preserve_default=False,
),
migrations.AddField(
model_name="sitesettings",
name="invite_question_text",
field=models.CharField(
blank=True, default="What is your favourite book?", max_length=255
),
),
migrations.AddField(
model_name="sitesettings",
name="invite_request_question",
field=models.BooleanField(default=False),
),
]

View File

@ -52,6 +52,8 @@ class SiteSettings(models.Model):
require_confirm_email = models.BooleanField(default=True)
invite_question_text = models.CharField(
max_length=255,
blank=True,
default="What is your favourite book?",
max_length=255,
# null=False if invite_request_question is False else True,
@ -109,7 +111,11 @@ class SiteSettings(models.Model):
"""if require_confirm_email is disabled, make sure no users are pending"""
if not self.require_confirm_email:
User.objects.filter(is_active=False, deactivation_reason="pending").update(
is_active=True, deactivation_reason=None)
is_active=True, deactivation_reason=None
)
"""if invite_request_question is enabled, make sure invite_question_text is not empty"""
if not self.invite_question_text:
self.invite_question_text = "What is your favourite book?"
super().save(*args, **kwargs)

View File

@ -19,8 +19,10 @@
{% endblock %}
{% block modal-footer %}
<button class="button is-primary" type="submit">{% trans "Confirm" %}</button>
<button type="button" class="button" data-modal-close>{% trans "Cancel" %}</button>
<div class="buttons is-right is-flex-grow-1">
<button type="button" class="button" data-modal-close>{% trans "Cancel" %}</button>
<button class="button is-primary" type="submit">{% trans "Confirm" %}</button>
</div>
{% endblock %}
{% block modal-form-close %}</form>{% endblock %}

View File

@ -28,8 +28,10 @@
{% endblock %}
{% block modal-footer %}
<button class="button is-primary" type="submit">{% trans "Add" %}</button>
<button type="button" class="button" data-modal-close>{% trans "Cancel" %}</button>
<div class="buttons is-right is-flex-grow-1">
<button class="button is-primary" type="submit">{% trans "Add" %}</button>
<button type="button" class="button" data-modal-close>{% trans "Cancel" %}</button>
</div>
{% endblock %}
{% block modal-form-close %}</form>{% endblock %}

View File

@ -55,8 +55,10 @@
{% endblock %}
{% block modal-footer %}
<button class="button is-primary" type="submit">{% trans "Save" %}</button>
<button type="button" class="button" data-modal-close>{% trans "Cancel" %}</button>
<div class="buttons is-right is-flex-grow-1">
<button type="button" class="button" data-modal-close>{% trans "Cancel" %}</button>
<button class="button is-primary" type="submit">{% trans "Save" %}</button>
</div>
{% endblock %}
{% block modal-form-close %}</form>{% endblock %}

View File

@ -17,13 +17,13 @@ Is that where you'd like to go?
{% block modal-footer %}
<a href="{{ link.url }}" target="_blank" rel="noopener noreferrer" class="button is-primary">{% trans "Continue" %}</a>
<button type="button" class="button" data-modal-close>{% trans "Cancel" %}</button>
{% if request.user.is_authenticated %}
<div class="has-text-right is-flex-grow-1">
<div class="is-flex-grow-1">
<a href="{% url 'report-link' link.added_by.id link.id %}">{% trans "Report spam" %}</a>
</div>
<button type="button" class="button" data-modal-close>{% trans "Cancel" %}</button>
<a href="{{ link.url }}" target="_blank" rel="noopener noreferrer" class="button is-primary">{% trans "Continue" %}</a>
{% endif %}
{% endblock %}

View File

@ -19,8 +19,10 @@
{% endblock %}
{% block modal-footer %}
<button class="button is-primary" type="submit">{% trans "Confirm" %}</button>
<button type="button" class="button" data-modal-close>{% trans "Cancel" %}</button>
<div class="buttons is-right is-flex-grow-1">
<button type="button" class="button" data-modal-close>{% trans "Cancel" %}</button>
<button class="button is-primary" type="submit">{% trans "Confirm" %}</button>
</div>
{% endblock %}
{% block modal-form-close %}</form>{% endblock %}

View File

@ -2,7 +2,7 @@
{% load i18n %}
{% block header %}
{% trans "Create Group" %}
{% trans "Create group" %}
{% endblock %}
{% block form %}

View File

@ -8,13 +8,15 @@
{% endblock %}
{% block modal-footer %}
<form name="delete-group-{{ group.id }}" action="{% url 'delete-group' group.id %}" method="POST">
<form name="delete-group-{{ group.id }}" action="{% url 'delete-group' group.id %}" method="POST" class="is-flex-grow-1">
{% csrf_token %}
<input type="hidden" name="id" value="{{ group.id }}">
<button class="button is-danger" type="submit">
{% trans "Delete" %}
</button>
<button type="button" class="button" data-modal-close>{% trans "Cancel" %}</button>
<div class="buttons is-right is-flex-grow-1">
<button type="button" class="button" data-modal-close>{% trans "Cancel" %}</button>
<button class="button is-danger" type="submit">
{% trans "Delete" %}
</button>
</div>
</form>
{% endblock %}

View File

@ -16,18 +16,21 @@
</div>
<div class="is-flex">
{% if group.id %}
<div class="is-flex-grow-1">
<div>
<button type="button" data-modal-open="delete_group" class="button is-danger">
{% trans "Delete group" %}
</button>
</div>
{% endif %}
<div class="field has-addons">
<div class="control">
{% include 'snippets/privacy_select_no_followers.html' with current=group.privacy %}
</div>
<div class="control">
<button type="submit" class="button is-primary">{% trans "Save" %}</button>
<div class="is-flex is-flex-grow-1 is-justify-content-flex-end">
<div class="field has-addons">
<div class="control">
{% include 'snippets/privacy_select_no_followers.html' with current=group.privacy %}
</div>
<div class="control">
<button type="submit" class="button is-primary">{% trans "Save" %}</button>
</div>
</div>
</div>
</div>

View File

@ -32,14 +32,16 @@
{% endblock %}
{% block modal-footer %}
<button type="submit" class="button is-link">
{% if list.curation == 'open' or request.user == list.user or list.group|is_member:request.user %}
{% trans "Add" %}
{% else %}
{% trans "Suggest" %}
{% endif %}
</button>
<button type="button" class="button" data-modal-close>{% trans "Cancel" %}</button>
<div class="buttons is-right is-flex-grow-1">
<button type="button" class="button" data-modal-close>{% trans "Cancel" %}</button>
<button type="submit" class="button is-link">
{% if list.curation == 'open' or request.user == list.user or list.group|is_member:request.user %}
{% trans "Add" %}
{% else %}
{% trans "Suggest" %}
{% endif %}
</button>
</div>
{% endblock %}
{% block modal-form-close %}</form>{% endblock %}

View File

@ -8,15 +8,17 @@
{% endblock %}
{% block modal-footer %}
<form name="delete-list-{{ list.id }}" action="{% url 'delete-list' list.id %}" method="POST">
<form name="delete-list-{{ list.id }}" action="{% url 'delete-list' list.id %}" method="POST" class="is-flex-grow-1">
{% csrf_token %}
<input type="hidden" name="id" value="{{ list.id }}">
<button class="button is-danger" type="submit">
{% trans "Delete" %}
</button>
<button type="button" class="button" data-modal-close>
{% trans "Cancel" %}
</button>
<div class="buttons is-right is-flex-grow-1">
<button type="button" class="button" data-modal-close>
{% trans "Cancel" %}
</button>
<button class="button is-danger" type="submit">
{% trans "Delete" %}
</button>
</div>
</form>
{% endblock %}

View File

@ -114,7 +114,7 @@
</fieldset>
</div>
</div>
<div class="is-flex">
<div class="is-flex is-justify-content-end">
{% if list.id %}
<div class="is-flex-grow-1">
<button type="button" data-modal-open="delete_list" class="button is-danger">

View File

@ -117,7 +117,7 @@
<summary>
<span role="heading" aria-level="3">
{% trans "Add notes" %}
<span class="details-close icon icon-plus" aria-hidden="true"></span>
<span class="details-close icon icon-x" aria-hidden="true"></span>
</span>
</summary>
{% include "lists/edit_item_form.html" with book=item.book %}

View File

@ -14,12 +14,20 @@
{% endblock %}
{% block modal-footer %}
<form name="delete-readthrough-{{ readthrough.id }}" action="/delete-readthrough" method="POST">
<form
name="delete-readthrough-{{ readthrough.id }}"
action="/delete-readthrough"
method="POST"
class="is-flex-grow-1"
>
{% csrf_token %}
<input type="hidden" name="id" value="{{ readthrough.id }}">
<button class="button is-danger" type="submit">
{% trans "Delete" %}
</button>
<button type="button" class="button" data-modal-close>{% trans "Cancel" %}</button>
<div class="buttons is-right">
<button type="button" class="button" data-modal-close>{% trans "Cancel" %}</button>
<button class="button is-danger" type="submit">
{% trans "Delete" %}
</button>
</div>
</form>
{% endblock %}

View File

@ -69,8 +69,10 @@
{% endblock %}
{% block modal-footer %}
<button class="button is-primary" type="submit">{% trans "Save" %}</button>
<button type="button" class="button" data-modal-close>{% trans "Cancel" %}</button>
<div class="buttons is-right is-flex-grow-1">
<button type="button" class="button" data-modal-close>{% trans "Cancel" %}</button>
<button class="button is-primary" type="submit">{% trans "Save" %}</button>
</div>
{% endblock %}
{% block modal-form-close %}

View File

@ -40,7 +40,9 @@
{% include 'snippets/table-sort-header.html' with field="invite__invitees__created_date" sort=sort text=text %}
</th>
<th>{% trans "Email" %}</th>
<th>{% trans "Answer" %}</th>
{% if site.invite_request_question %}
<th>{% trans "Answer" %}</th>
{% endif %}
<th>
{% trans "Status" as text %}
{% include 'snippets/table-sort-header.html' with field="invite__times_used" sort=sort text=text %}
@ -55,7 +57,9 @@
<td>{{ req.created_date | naturaltime }}</td>
<td>{{ req.invite.invitees.first.created_date | naturaltime }}</td>
<td>{{ req.email }}</td>
<td>{{ req.answer }}</td>
{% if site.invite_request_question %}
<td>{{ req.answer }}</td>
{% endif %}
<td>
{% if req.invite.times_used %}
{% trans "Accepted" %}

View File

@ -18,8 +18,10 @@
{% endblock %}
{% block modal-footer %}
<button type="submit" class="button is-primary">{% trans "Set" %}</button>
<button type="button" class="button" data-modal-close>{% trans "Cancel" %}</button>
<div class="buttons is-right is-flex-grow-1">
<button type="button" class="button" data-modal-close>{% trans "Cancel" %}</button>
<button type="submit" class="button is-primary">{% trans "Set" %}</button>
</div>
{% endblock %}
{% block modal-form-close %}</form>{% endblock %}

View File

@ -2,7 +2,7 @@
{% load i18n %}
{% block header %}
{% trans "Create Shelf" %}
{% trans "Create shelf" %}
{% endblock %}
{% block form %}

View File

@ -17,7 +17,7 @@
<label class="label" for="id_description_{{ uuid }}">{% trans "Description:" %}</label>
<textarea name="description" cols="40" rows="5" maxlength="500" class="textarea" id="id_description_{{ uuid }}">{{ form.description.value|default:'' }}</textarea>
</div>
<div class="field has-addons">
<div class="field has-addons is-justify-content-end">
<div class="control">
{% include 'snippets/privacy_select.html' with current=privacy %}
</div>

View File

@ -1,22 +1,33 @@
{% load i18n %}
<div
class="field{% if not reply_parent.content_warning and not draft.content_warning %} is-hidden{% endif %}"
id="spoilers_{{ uuid }}{{ local_uuid }}"
>
<label
class="label"
for="id_content_warning_{{ uuid }}{{ local_uuid }}"
>
{% trans "Content warning:" %}
</label>
<input
type="text"
name="content_warning"
maxlength="255"
class="input"
id="id_content_warning_{{ uuid }}{{ local_uuid }}"
placeholder="{% trans 'Spoilers ahead!' %}"
value="{% firstof draft.content_warning reply_parent.content_warning '' %}"
{% if not draft %}data-cache-draft="id_content_warning_{{ book.id }}_{{ type }}"{% endif %}
<div class="field is-relative">
<details
{% if reply_parent.content_warning or draft.content_warning %}open{% endif %}
>
<summary class="is-flex">
<span class="icon icon-warning is-size-5 mr-1" aria-hidden="true"></span>
<span>
{% trans "Include spoiler alert" %}
</span>
<span class="details-close icon icon-x" aria-hidden="true"></span>
</summary>
<label
class="label"
for="id_content_warning_{{ uuid }}{{ local_uuid }}"
>
{% trans "Spoilers/content warnings:" %}
</label>
<div class="control">
<input
type="text"
name="content_warning"
maxlength="255"
class="input"
id="id_content_warning_{{ uuid }}{{ local_uuid }}"
placeholder="{% trans 'Spoilers ahead!' %}"
value="{% firstof draft.content_warning reply_parent.content_warning '' %}"
{% if not draft %}data-cache-draft="id_content_warning_{{ book.id }}_{{ type }}"{% endif %}
>
</div>
</details>
</div>

View File

@ -1,17 +0,0 @@
{% load i18n %}
<div class="control">
<input
type="checkbox"
class="is-hidden"
name="sensitive"
id="id_show_spoilers_{{ uuid }}{{ local_uuid }}"
{% if draft.content_warning or status.content_warning %}checked{% endif %}
aria-hidden="true"
{% if not draft %}data-cache-draft="id_sensitive_{{ book.id }}_{{ type }}{{ reply_parent.id }}"{% endif %}
>
{% trans "Include spoiler alert" as button_text %}
{% firstof draft.content_warning status.content_warning as pressed %}
{% firstof local_uuid '' as local_uuid %}
{% include 'snippets/toggle/toggle_button.html' with text=button_text icon="warning is-size-4" controls_text="spoilers" controls_uid=uuid|add:local_uuid focus="id_content_warning" checkbox="id_show_spoilers" class="toggle-button" pressed=pressed %}
</div>

View File

@ -37,8 +37,6 @@ reply_parent: the Status object this post will be in reply to, if applicable
{% endif %}
{% endblock %}
{% include "snippets/create_status/content_warning_field.html" %}
{# fields that go between the content warnings and the content field (ie, quote) #}
{% block pre_content_additions %}{% endblock %}
@ -55,6 +53,8 @@ reply_parent: the Status object this post will be in reply to, if applicable
{# additional fields that go after the content block (ie, progress) #}
{% block post_content_additions %}{% endblock %}
{% include "snippets/create_status/content_warning_field.html" %}
{% block options_block %}
{# cw, post privacy, and submit button #}
{% include "snippets/create_status/post_options_block.html" %}

View File

@ -1,8 +1,6 @@
{% load i18n %}
<div class="columns mt-1">
<div class="field has-addons column">
{% include "snippets/create_status/content_warning_toggle.html" %}
<div class="control">
<div class="field has-addons is-justify-content-end">
<div class="control">
{% if type == 'direct' %}
<input type="hidden" name="privacy" value="direct">
<button type="button" class="button" aria-label="Privacy" disabled>{% trans "Private" %}</button>
@ -13,13 +11,11 @@
{% include 'snippets/privacy_select.html' with current=reply_parent.privacy %}
{% endif %}
{% endif %}
</div>
</div>
<div class="column is-narrow control">
<div class="control">
<button class="button is-link" type="submit">
<span class="icon icon-spinner" aria-hidden="true"></span>
<span>{% trans "Post" %}</span>
</button>
</div>
</div>

View File

@ -53,12 +53,12 @@
id="id_password_register"
aria-describedby="desc_password_register"
>
{% include 'snippets/form_errors.html' with errors_list=register_form.password.errors id="desc_password_register" %}
</div>
</div>
<div class="field is-grouped">
<div class="field">
<div class="control">
<button class="button is-primary" type="submit">
{% trans "Sign Up" %}

View File

@ -48,10 +48,10 @@
{% block modal-footer %}
<button class="button is-success" type="submit">{% trans "Submit" %}</button>
<button type="button" class="button" data-modal-close>{% trans "Cancel" %}</button>
<div class="buttons is-right is-flex-grow-1">
<button type="button" class="button" data-modal-close>{% trans "Cancel" %}</button>
<button class="button is-success" type="submit">{% trans "Submit" %}</button>
</div>
{% endblock %}
{% block modal-form-close %}</form>{% endblock %}

View File

@ -58,8 +58,12 @@ class Editions(View):
)
paginated = Paginator(editions, PAGE_LENGTH)
page = paginated.get_page(request.GET.get("page"))
data = {
"editions": paginated.get_page(request.GET.get("page")),
"editions": page,
"page_range": paginated.get_elided_page_range(
page.number, on_each_side=2, on_ends=1
),
"work": work,
"languages": languages,
"formats": set(

View File

@ -85,9 +85,7 @@ class CreateStatus(View):
if hasattr(status, "quote"):
status.raw_quote = status.quote
if not status.sensitive and status.content_warning:
# the cw text field remains populated when you click "remove"
status.content_warning = None
status.sensitive = status.content_warning not in [None, ""]
status.save(broadcast=False)
# inspect the text for user tags