From 335a8884110e959868208a9075b390d453716b69 Mon Sep 17 00:00:00 2001 From: nsandler1 Date: Sun, 11 Dec 2022 15:44:49 -0500 Subject: [PATCH] change when messages are sent --- home/utils.py | 16 +++++++--------- home/views/professor.py | 2 +- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/home/utils.py b/home/utils.py index 4f185c5a..a1b905e5 100644 --- a/home/utils.py +++ b/home/utils.py @@ -8,6 +8,7 @@ from datetime import datetime from django.urls import reverse +from django.template.defaultfilters import pluralize from discord_webhook import DiscordWebhook from discord_webhook.webhook import DiscordEmbed @@ -204,22 +205,19 @@ def recompute_ttl_cache(): value = (0, *values) _ttl_cache[key] = value -def send_updates_webhook(request, *, include_professors=True, include_reviews=True): +def send_updates_webhook(request): # avoid circular imports from home.models import Professor, Review if not WEBHOOK_URL_UPDATE: return - title = "" num_professors = Professor.pending.count() num_reviews = Review.pending.count() - if include_professors: - title += f"{num_professors} unverified professor(s)" - if include_professors and include_reviews: - title += " and " - if include_reviews: - title += f"{num_reviews} unverified review(s)" + title = f"{num_reviews} unverified review{pluralize(num_reviews)}" + + if num_professors: + title += f" and {num_professors} unverified professor{pluralize(num_professors)}" webhook = DiscordWebhook(url=WEBHOOK_URL_UPDATE) embed = DiscordEmbed(title=title, description="\n", @@ -227,7 +225,7 @@ def send_updates_webhook(request, *, include_professors=True, include_reviews=Tr webhook.add_embed(embed) - if (num_reviews + num_professors) % WEBHOOK_FREQUENCY != 0: + if num_reviews % WEBHOOK_FREQUENCY != 0: return webhook.execute() diff --git a/home/views/professor.py b/home/views/professor.py index 5797df00..25888e62 100644 --- a/home/views/professor.py +++ b/home/views/professor.py @@ -102,7 +102,7 @@ def post(self, request, slug): new_review = Review(**review_data) new_review.save() - send_updates_webhook(request, include_professors=False) + send_updates_webhook(request) form = ProfessorFormReview(user, professor) context = {