From 7ae0db7f4ae3edffdd5d54e25d3fb5fe9339e590 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Thu, 5 May 2022 13:29:07 -0700 Subject: [PATCH 1/6] Ignore VariableDoesNotExist errors in debug logging They're so noisy as to make debug logging useless otherwise --- bookwyrm/settings.py | 4 ++++ bookwyrm/utils/log.py | 12 ++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 bookwyrm/utils/log.py diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index e16c576e1..236413fe8 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -147,6 +147,9 @@ LOGGING = { "require_debug_true": { "()": "django.utils.log.RequireDebugTrue", }, + "ignore_missing_variable": { + "()": "bookwyrm.utils.log.IgnoreVariableDoesNotExist", + }, }, "handlers": { # Overrides the default handler to make it log to console @@ -154,6 +157,7 @@ LOGGING = { # console if DEBUG=False) "console": { "level": LOG_LEVEL, + "filters": ["ignore_missing_variable"], "class": "logging.StreamHandler", }, # This is copied as-is from the default logger, and is diff --git a/bookwyrm/utils/log.py b/bookwyrm/utils/log.py new file mode 100644 index 000000000..8ad86895c --- /dev/null +++ b/bookwyrm/utils/log.py @@ -0,0 +1,12 @@ +import logging + + +class IgnoreVariableDoesNotExist(logging.Filter): + def filter(self, record): + if(record.exc_info): + (errType, errValue, _) = record.exc_info + while errValue: + if type(errValue).__name__ == 'VariableDoesNotExist': + return False + errValue = errValue.__context__ + return True From 7014786fe03a73c7c8fe525aaad19384aa05c159 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Sun, 5 Jun 2022 13:41:00 -0700 Subject: [PATCH 2/6] Run formatters --- bookwyrm/utils/log.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bookwyrm/utils/log.py b/bookwyrm/utils/log.py index 8ad86895c..4ea24d81d 100644 --- a/bookwyrm/utils/log.py +++ b/bookwyrm/utils/log.py @@ -3,10 +3,10 @@ import logging class IgnoreVariableDoesNotExist(logging.Filter): def filter(self, record): - if(record.exc_info): + if record.exc_info: (errType, errValue, _) = record.exc_info while errValue: - if type(errValue).__name__ == 'VariableDoesNotExist': + if type(errValue).__name__ == "VariableDoesNotExist": return False errValue = errValue.__context__ return True From c9adb7ff129bdb75fcbe97c896347cfb889683a0 Mon Sep 17 00:00:00 2001 From: Ell Bradshaw Date: Mon, 14 Nov 2022 00:48:59 -0800 Subject: [PATCH 3/6] Linting fixes --- bookwyrm/utils/log.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/bookwyrm/utils/log.py b/bookwyrm/utils/log.py index 4ea24d81d..70f32ef03 100644 --- a/bookwyrm/utils/log.py +++ b/bookwyrm/utils/log.py @@ -1,12 +1,20 @@ +""" Logging utilities """ import logging class IgnoreVariableDoesNotExist(logging.Filter): + """ + Filter to ignore VariableDoesNotExist errors + + We intentionally pass nonexistent variables to templates a lot, so + these errors are not useful to us. + """ + def filter(self, record): if record.exc_info: - (errType, errValue, _) = record.exc_info - while errValue: - if type(errValue).__name__ == "VariableDoesNotExist": + (_, err_value, _) = record.exc_info + while err_value: + if type(err_value).__name__ == "VariableDoesNotExist": return False - errValue = errValue.__context__ - return True + err_value = err_value.__context__ + return True From e655f5c2f399563afbd37906d2adf52d7484d979 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 14 Nov 2022 16:06:40 -0800 Subject: [PATCH 4/6] Fixes typo in url regex --- bookwyrm/urls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 7af123016..a1e0ef844 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -297,7 +297,7 @@ urlpatterns = [ name="settings-imports", ), re_path( - r"^settings/imports/(?P\d+)/complete?$", + r"^settings/imports/(?P\d+)/complete/?$", views.ImportList.as_view(), name="settings-imports-complete", ), From 5b358094ab1a09ed4b7821bc118ffb6af6a2b187 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 14 Nov 2022 18:03:36 -0800 Subject: [PATCH 5/6] Fixes report emails always claiming to be about links --- bookwyrm/emailing.py | 1 + bookwyrm/templates/email/moderation_report/html_content.html | 2 +- bookwyrm/templates/email/moderation_report/text_content.html | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bookwyrm/emailing.py b/bookwyrm/emailing.py index e767d5374..80aacf7f4 100644 --- a/bookwyrm/emailing.py +++ b/bookwyrm/emailing.py @@ -48,6 +48,7 @@ def moderation_report_email(report): if report.user: data["reportee"] = report.user.localname or report.user.username data["report_link"] = report.remote_id + data["link_domain"] = report.links.exists() for admin in models.User.objects.filter( groups__name__in=["admin", "moderator"] diff --git a/bookwyrm/templates/email/moderation_report/html_content.html b/bookwyrm/templates/email/moderation_report/html_content.html index 3828ff70c..0e604ebf8 100644 --- a/bookwyrm/templates/email/moderation_report/html_content.html +++ b/bookwyrm/templates/email/moderation_report/html_content.html @@ -3,7 +3,7 @@ {% block content %}

-{% if report_link %} +{% if link_domain %} {% blocktrans trimmed %} @{{ reporter }} has flagged a link domain for moderation. diff --git a/bookwyrm/templates/email/moderation_report/text_content.html b/bookwyrm/templates/email/moderation_report/text_content.html index 764a3c72a..351ab58ed 100644 --- a/bookwyrm/templates/email/moderation_report/text_content.html +++ b/bookwyrm/templates/email/moderation_report/text_content.html @@ -2,7 +2,7 @@ {% load i18n %} {% block content %} -{% if report_link %} +{% if link_domain %} {% blocktrans trimmed %} @{{ reporter }} has flagged a link domain for moderation. {% endblocktrans %} From dbe74f63885441498acd633b4d5b11ba48f1b2db Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 14 Nov 2022 18:18:27 -0800 Subject: [PATCH 6/6] Uses the same snippet for the footer across different templates --- bookwyrm/templates/layout.html | 48 +------------------ .../snippets/{2fa_footer.html => footer.html} | 0 .../two_factor_auth/two_factor_login.html | 2 +- .../two_factor_auth/two_factor_prompt.html | 2 +- 4 files changed, 3 insertions(+), 49 deletions(-) rename bookwyrm/templates/snippets/{2fa_footer.html => footer.html} (100%) diff --git a/bookwyrm/templates/layout.html b/bookwyrm/templates/layout.html index 9e954411e..e58f65edd 100644 --- a/bookwyrm/templates/layout.html +++ b/bookwyrm/templates/layout.html @@ -192,53 +192,7 @@

- +{% include 'snippets/footer.html' %} {% endblock %}