From 67096e825634c58245abcc69876301553e9a85fd Mon Sep 17 00:00:00 2001 From: Joseph Muller Date: Mon, 9 Dec 2024 16:19:23 +0000 Subject: [PATCH] chore #3168 Clean up old prints in testing --- src/core/logic.py | 2 +- .../commands/send_publication_notifications.py | 11 +++++++---- src/cron/management/commands/send_reminders.py | 7 +++++-- src/utils/install.py | 5 ++++- src/utils/management/commands/install_plugins.py | 7 +++++-- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/core/logic.py b/src/core/logic.py index 98268f3ae4..24ae68cbd7 100755 --- a/src/core/logic.py +++ b/src/core/logic.py @@ -868,7 +868,7 @@ def check_for_bad_login_attempts(request): time = timezone.now() - timedelta(minutes=10) attempts = models.LoginAttempt.objects.filter(user_agent=user_agent, ip_address=ip_address, timestamp__gte=time) - print(time, attempts.count()) + logger.info(time, attempts.count()) return attempts.count() diff --git a/src/cron/management/commands/send_publication_notifications.py b/src/cron/management/commands/send_publication_notifications.py index 3969b4f976..b9d3977d8c 100644 --- a/src/cron/management/commands/send_publication_notifications.py +++ b/src/cron/management/commands/send_publication_notifications.py @@ -8,6 +8,9 @@ from journal import models as journal_models from submission import models as submission_models from utils import notify_helpers, setting_handler, render_template +from utils.logger import get_logger + +logger = get_logger(__name__) def create_fake_request(journal): @@ -47,12 +50,12 @@ def handle(self, *args, **options): setting_name='send_reader_notifications', journal=journal, ).value: - print('Sending notification for {}'.format(journal.name)) + logger.info('Sending notification for {}'.format(journal.name)) readers = journal.users_with_role('reader') bcc_list = [reader.email for reader in readers] if bcc_list: - print("Sending notifications to {}".format( + logger.info("Sending notifications to {}".format( ", ".join(bcc_list) )) @@ -98,8 +101,8 @@ def handle(self, *args, **options): } ) else: - print("No articles were published today.") + logger.info("No articles were published today.") else: - print('Reader publication notifications are not enabled for {}'.format(journal.name)) + logger.info('Reader publication notifications are not enabled for {}'.format(journal.name)) diff --git a/src/cron/management/commands/send_reminders.py b/src/cron/management/commands/send_reminders.py index 112d3c45bf..c2c36fcf81 100755 --- a/src/cron/management/commands/send_reminders.py +++ b/src/cron/management/commands/send_reminders.py @@ -2,6 +2,9 @@ from cron import models from journal import models as journal_models +from utils.logger import get_logger + +logger = get_logger(__name__) class Command(BaseCommand): @@ -19,12 +22,12 @@ def handle(self, *args, **options): journals = journal_models.Journal.objects.all() for journal in journals: - print("Processing reminders for journal {0}: {1}".format(journal.pk, journal.name)) + logger.info("Processing reminders for journal {0}: {1}".format(journal.pk, journal.name)) reminders = models.Reminder.objects.filter(journal=journal) for reminder in reminders: - print("Reminder {0}, target date: {1}".format(reminder, reminder.target_date())) + logger.info("Reminder {0}, target date: {1}".format(reminder, reminder.target_date())) if action == 'test': reminder.send_reminder(test=True) else: diff --git a/src/utils/install.py b/src/utils/install.py index 0ced46e651..4ec8575c26 100755 --- a/src/utils/install.py +++ b/src/utils/install.py @@ -13,9 +13,12 @@ from journal import models from press import models as press_models from utils import setting_handler +from utils.logger import get_logger from submission import models as submission_models from cms import models as cms_models +logger = get_logger(__name__) + def update_settings(journal_object=None, management_command=False, overwrite_with_defaults=False, @@ -83,7 +86,7 @@ def update_settings(journal_object=None, management_command=False, setting.editable_by.add(*roles) if management_command: - print('Parsed setting {0}'.format(item['setting'].get('name'))) + logger.info('Parsed setting {0}'.format(item['setting'].get('name'))) def load_permissions(file_path='utils/install/journal_defaults.json'): diff --git a/src/utils/management/commands/install_plugins.py b/src/utils/management/commands/install_plugins.py index 7a8725e987..11789f14b6 100755 --- a/src/utils/management/commands/install_plugins.py +++ b/src/utils/management/commands/install_plugins.py @@ -3,9 +3,12 @@ from django.core.management.base import BaseCommand from core import plugin_loader +from utils.logger import get_logger from importlib import import_module +logger = get_logger(__name__) + class Command(BaseCommand): """A management command to check for and install new plugins.""" @@ -40,13 +43,13 @@ def handle(self, *args, **options): ) for plugin in plugin_dirs: - print('Checking plugin {0}'.format(plugin)) + logger.debug('Checking plugin {0}'.format(plugin)) plugin_module_name = "plugins.{0}.plugin_settings".format(plugin) plugin_settings = import_module(plugin_module_name) plugin_settings.install() for plugin in homepage_dirs: - print('Checking plugin {0}'.format(plugin)) + logger.debug('Checking plugin {0}'.format(plugin)) plugin_module_name = "core.homepage_elements.{0}.plugin_settings".format(plugin) plugin_settings = import_module(plugin_module_name) plugin_settings.install()