diff --git a/TWLight/emails/tasks.py b/TWLight/emails/tasks.py index 1634d22cbf..6dd1a6ec47 100644 --- a/TWLight/emails/tasks.py +++ b/TWLight/emails/tasks.py @@ -80,6 +80,9 @@ class CoordinatorReminderNotification(template_mail.TemplateMail): class UserRenewalNotice(template_mail.TemplateMail): name = "user_renewal_notice" +class SuggestionNotification(template_mail.TemplateMail): + name = "suggestion_notification" + @receiver(Reminder.coordinator_reminder) def send_coordinator_reminder_emails(sender, **kwargs): @@ -530,3 +533,30 @@ def contact_us_emails(sender, **kwargs): logger.info("Email constructed.") email.send() logger.info("Email queued.") + +def send_suggestion_notification(instance): + """ + When a suggested collections becomes available, users who upvoted + the suggestion should be notified + """ + base_url = get_current_site(None).domain + path = reverse_lazy("users:my_library") + link = "https://{base}{path}".format(base=base_url, path=path) + + email = SuggestionNotification() + + if instance.editor: + email.send( + instance.user.email, + { + "user": instance.user.editor.wp_username, + "lang": instance.user.userprofile.lang, + "partner": instance.partner, + "link": link, + }, + ) + else: + logger.error( + "Tried to send an email to an editor that doesn't " + "exist, perhaps because their account is deleted." + ) diff --git a/TWLight/emails/templates/emails/suggestion_notification-body-html.html b/TWLight/emails/templates/emails/suggestion_notification-body-html.html new file mode 100644 index 0000000000..16bfe280f7 --- /dev/null +++ b/TWLight/emails/templates/emails/suggestion_notification-body-html.html @@ -0,0 +1,13 @@ +{% load i18n %} + + +{% comment %}Translators: This is the subject of an email sent to users when a collection suggestion they have upvoted is now available.{% endcomment %} +{% blocktranslate trimmed %} +

Hi,

+

This is an automated notice to let you know that a Wikipedia Library suggestion you upvoted, {{ partner }}, is now available!

+

You can now [apply for access to / access] {{ partner }} at {{ link }}.

+

If you have any issues or questions please contact us at wikipedialibrary@wikimedia.org

+

The Wikipedia Library team

+{% endblocktranslate %} + + diff --git a/TWLight/emails/templates/emails/suggestion_notification-body-text.html b/TWLight/emails/templates/emails/suggestion_notification-body-text.html new file mode 100644 index 0000000000..16ec5c8660 --- /dev/null +++ b/TWLight/emails/templates/emails/suggestion_notification-body-text.html @@ -0,0 +1,13 @@ +{% load i18n %} +{% comment %}Translators: This is the subject of an email sent to users when a collection suggestion they have upvoted is now available.{% endcomment %} +{% blocktranslate trimmed %} +Hi, + +This is an automated notice to let you know that a Wikipedia Library suggestion you upvoted, {{ partner }}, is now available! + +You can now [apply for access to / access] {{ partner }} at {{ link }}. + +If you have any issues or questions please contact us at wikipedialibrary@wikimedia.org + +The Wikipedia Library team +{% endblocktranslate %} diff --git a/TWLight/emails/templates/emails/suggestion_notification-subject.html b/TWLight/emails/templates/emails/suggestion_notification-subject.html new file mode 100644 index 0000000000..463d0a4cbd --- /dev/null +++ b/TWLight/emails/templates/emails/suggestion_notification-subject.html @@ -0,0 +1,4 @@ +{% load i18n %} + +{% comment %}Translators: This is the subject of an email sent to users when a collection suggestion they have upvoted is now available.{% endcomment %} +{% trans 'A suggested collection you upvoted is now available!' %} diff --git a/TWLight/resources/factories.py b/TWLight/resources/factories.py index 684d1895fc..6e3fedb81e 100644 --- a/TWLight/resources/factories.py +++ b/TWLight/resources/factories.py @@ -23,7 +23,7 @@ class Meta: model = Suggestion strategy = factory.CREATE_STRATEGY - suggested_company_name = factory.Faker("pystr", max_chars=40) + suggested_company_name = factory.Faker("pystr", max_chars=80) company_url = factory.Faker("url", locale=random.choice(settings.FAKER_LOCALES)) diff --git a/TWLight/resources/forms.py b/TWLight/resources/forms.py index 50cde18f47..9e67db368f 100644 --- a/TWLight/resources/forms.py +++ b/TWLight/resources/forms.py @@ -2,12 +2,15 @@ from django.utils.translation import gettext_lazy as _ from TWLight.resources.models import Suggestion +from dal import autocomplete + from crispy_forms.helper import FormHelper -from crispy_forms.layout import Submit, Layout +from crispy_forms.layout import Submit, Layout, Row, Column +from .models import Partner class SuggestionForm(forms.Form): - suggested_company_name = forms.CharField(max_length=40) + suggested_company_name = forms.CharField(max_length=80) description = forms.CharField(widget=forms.Textarea, max_length=500) company_url = forms.URLField(initial="http://") next = forms.CharField(widget=forms.HiddenInput, max_length=40) @@ -18,6 +21,11 @@ def __init__(self, *args, **kwargs): self.fields["suggested_company_name"].label = _("Name of the potential partner") # Translators: This labels a textfield where users can enter the description of the potential partner they'll suggest self.fields["description"].label = _("Description") + self.fields["description"].widget = forms.Textarea( + attrs={ + "placeholder": "You may use any language here. However, it is not translatable via TranslateWiki." + } + ) # Translators: This labels a textfield where users can enter the website URL of the potential partner they'll suggest self.fields["company_url"].label = _("Website") # @TODO: This sort of gets repeated in PartnerSuggestionView. @@ -54,3 +62,35 @@ def __init__(self, *args, **kwargs): "secondary_suggestions", Submit("submit", "Submit", css_class="twl-btn"), ) + +class NotifySuggestionUpvotersForm(forms.Form): + # @TODO: currently the form is not rendering correctly, + # this class set up needs to be looked at and reviewed + class Meta: + model = Partner + fields = ["company_name"] + widgets = { + "partner": autocomplete.ModelSelect2( + url="partner:company_name_autocomplete", + attrs={"data-placeholder": "Partner"}, + ), + } + # partner = forms.CharField(max_length=80) + # partner = autocomplete.ModelSelect2() + + def __init__(self, user=None, *args, **kwargs): + super().__init__(*args, **kwargs) + + # self.fields["company_name"].queryset = Partner.objects.all().order_by( + # "company_name" + # ) + + # Translators: Label of the field where coordinators can enter the name of a partner + # self.fields["company_name"].label = _("Partner name") + + # self.helper.layout = Layout( + # Row( + # Column("partner", css_class="col-lg-6 px-sm-3 col-sm-8 mx-sm-1"), + # css_class="form-group my-1", + # ), + # ) diff --git a/TWLight/resources/migrations/0085_alter_suggestion_suggested_company_name.py b/TWLight/resources/migrations/0085_alter_suggestion_suggested_company_name.py new file mode 100644 index 0000000000..474cdbba83 --- /dev/null +++ b/TWLight/resources/migrations/0085_alter_suggestion_suggested_company_name.py @@ -0,0 +1,20 @@ +# Generated by Django 3.2.19 on 2023-05-19 08:49 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("resources", "0084_phabricatortask"), + ] + + operations = [ + migrations.AlterField( + model_name="suggestion", + name="suggested_company_name", + field=models.CharField( + help_text="Potential partner's name (e.g. McFarland).", max_length=80 + ), + ), + ] diff --git a/TWLight/resources/models.py b/TWLight/resources/models.py index 4f2647a8e9..44133968aa 100644 --- a/TWLight/resources/models.py +++ b/TWLight/resources/models.py @@ -582,7 +582,7 @@ class Meta: ordering = ["suggested_company_name"] suggested_company_name = models.CharField( - max_length=40, help_text="Potential partner's name (e.g. McFarland)." + max_length=80, help_text="Potential partner's name (e.g. McFarland)." ) description = models.TextField( diff --git a/TWLight/resources/templates/resources/suggest.html b/TWLight/resources/templates/resources/suggest.html index 1f9b5b6688..3c786cb895 100644 --- a/TWLight/resources/templates/resources/suggest.html +++ b/TWLight/resources/templates/resources/suggest.html @@ -5,10 +5,6 @@ {% load static %} {% load twlight_perms %} -{% block head_javascript %} - -{% endblock head_javascript %} - {% block content %} {% include "header_partial_b4.html" %} {% include "message_partial.html" %} @@ -106,6 +102,26 @@ {{ each_suggestion.upvoted_users.count }} + {% if user.is_staff %} + + + + {% comment %}Translators: This is the text that appears in the button after a user has clicked upvote (already endorsed). {% endcomment %} + {% trans 'Notify upvoters' %} + + + + + {% endif %} {% endif %} @@ -158,6 +174,16 @@ var upvoteURL = this_.attr("data-href"); $.get(upvoteURL); }); + $('.notify').click(function(e){ + e.preventDefault(); + + var suggestionId = this.dataset.suggestionid; + console.log('$(this).dataset', this.dataset); + console.log('suggestionId', suggestionId); + $('#notify-suggestion-' + suggestionId).modal( + { show: true } + ); + });