Merge branch 'main' into question_invite_correct

This commit is contained in:
OragePika, aka "FANS DON'T CARE 2022-03-13 13:14:23 +01:00 committed by GitHub
commit 974c569fc1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 230 additions and 119 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

@ -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

@ -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

@ -58,7 +58,7 @@
</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

1
bw-dev
View file

@ -225,6 +225,7 @@ case "$CMD" in
*)
set +x # No need to echo echo
echo "Unrecognised command. Try:"
echo " setup"
echo " up [container]"
echo " service_ports_web"
echo " initdb"

89
complete_bwdev.fish Normal file
View file

@ -0,0 +1,89 @@
# bw-dev auto-completions for fish-shell.
# copy this to ~./.config/fish/completions/ with the name `bw-dev.fish`
# this will only work if renamed to `bw-dev.fish`.
set -l commands up \
service_ports_web \
initdb \
resetdb \
makemigrations \
migrate \
bash \
shell \
dbshell \
restart_celery \
pytest \
collectstatic \
makemessages \
compilemessages \
update_locales \
build \
clean \
black \
prettier \
stylelint \
formatters \
compilescss \
collectstatic_watch \
populate_streams \
populate_lists_streams \
populate_suggestions \
generate_thumbnails \
generate_preview_images \
copy_media_to_s3 \
set_cors_to_s3 \
setup \
admin_code \
runweb
function __bw_complete -a cmds cmd desc
complete -f -c bw-dev -n "not __fish_seen_subcommand_from $cmds" -a $cmd -d $desc
end
__bw_complete "$commands" "up" "bring one or all service(s) up"
__bw_complete "$commands" "service_ports_web" "run command on the web container with its portsenabled and mapped"
__bw_complete "$commands" "initdb" "initialize database"
__bw_complete "$commands" "resetdb" "!! WARNING !! reset database"
__bw_complete "$commands" "makemigrations" "create new migrations"
__bw_complete "$commands" "migrate" "perform all migrations"
__bw_complete "$commands" "bash" "open up bash within the web container"
__bw_complete "$commands" "shell" "open the Python shell within the web container"
__bw_complete "$commands" "dbshell" "open the database shell within the web container"
__bw_complete "$commands" "restart_celery" "restart the celery container"
__bw_complete "$commands" "pytest" "run unit tests"
__bw_complete "$commands" "collectstatic" "copy changed static files into the installation"
__bw_complete "$commands" "makemessages" "extract all localizable messages from the code"
__bw_complete "$commands" "compilemessages" "compile .po localization files to .mo"
__bw_complete "$commands" "update_locales" "run makemessages and compilemessages for the en_US and additional locales"
__bw_complete "$commands" "build" "build the containers"
__bw_complete "$commands" "clean" "bring the cluster down and remove all containers"
__bw_complete "$commands" "black" "run Python code formatting tool"
__bw_complete "$commands" "prettier" "run JavaScript code formatting tool"
__bw_complete "$commands" "stylelint" "run SCSS linting tool"
__bw_complete "$commands" "formatters" "run multiple formatter tools"
__bw_complete "$commands" "compilescss" "compile the SCSS layouts to CSS"
__bw_complete "$commands" "populate_streams" "populate the main streams"
__bw_complete "$commands" "populate_lists_streams" "populate streams for book lists"
__bw_complete "$commands" "populate_suggestions" "populate book suggestions"
__bw_complete "$commands" "generate_thumbnails" "generate book thumbnails"
__bw_complete "$commands" "generate_preview_images" "generate book preview images"
__bw_complete "$commands" "collectstatic_watch" "watch filesystem and copy changed static files"
__bw_complete "$commands" "copy_media_to_s3" "run the `s3 cp` command to copy media to a bucket on S3"
__bw_complete "$commands" "sync_media_to_s3" "run the `s3 sync` command to sync media with a bucket on S3"
__bw_complete "$commands" "set_cors_to_s3" "push a CORS configuration defined in .json to s3"
__bw_complete "$commands" "setup" "perform first-time setup"
__bw_complete "$commands" "admin_code" "get the admin code"
__bw_complete "$commands" "runweb" "run a command on the web container"
function __bw_complete_subcommand -a cmd
complete -f -c bw-dev -n "__fish_seen_subcommand_from $cmd" $argv[2..-1]
end
__bw_complete_subcommand "up" -a "(docker-compose config --service)"
__bw_complete_subcommand "pytest" -a "bookwyrm/tests/**.py"
__bw_complete_subcommand "populate_streams" -a "--stream=" -d "pick a single stream to populate"
__bw_complete_subcommand "populate_streams" -l stream -a "home local books"
__bw_complete_subcommand "generate_preview_images" -a "--all"\
-d "Generates images for ALL types: site, users and books. Can use a lot of computing power."
__bw_complete_subcommand "set_cors_to_s3" -a "**.json"