Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚧 [WIP] T211141: send suggestion notice #1166

Open
wants to merge 9 commits into
base: suggestion-improvements
Choose a base branch
from
30 changes: 30 additions & 0 deletions TWLight/emails/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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."
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% load i18n %}
<html>
<body>
{% 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 %}
<p>Hi,</p>
<p>This is an automated notice to let you know that a Wikipedia Library suggestion you upvoted, {{ partner }}, is now available!</p>
<p>You can now [apply for access to / access] {{ partner }} at {{ link }}.</p>
<p>If you have any issues or questions please contact us at wikipedialibrary@wikimedia.org</p>
<p>The Wikipedia Library team</p>
{% endblocktranslate %}
</body>
</html>
Original file line number Diff line number Diff line change
@@ -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 %}
Original file line number Diff line number Diff line change
@@ -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!' %}
2 changes: 1 addition & 1 deletion TWLight/resources/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))


Expand Down
44 changes: 42 additions & 2 deletions TWLight/resources/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand Down Expand Up @@ -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",
# ),
# )
Original file line number Diff line number Diff line change
@@ -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
),
),
]
2 changes: 1 addition & 1 deletion TWLight/resources/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
34 changes: 30 additions & 4 deletions TWLight/resources/templates/resources/suggest.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
{% load static %}
{% load twlight_perms %}

{% block head_javascript %}
<script type="text/javascript" language="javascript" src="{% static "js/jquery-3.5.1.min.js" %}"></script>
{% endblock head_javascript %}

{% block content %}
{% include "header_partial_b4.html" %}
{% include "message_partial.html" %}
Expand Down Expand Up @@ -106,6 +102,26 @@
{{ each_suggestion.upvoted_users.count }}
</span>
</a>
{% if user.is_staff %}
<!-- TODO: invoke send_suggestion_notification -->
<a class="btn notify" data-suggestionId="{{ each_suggestion.id }}"
href="">
<span class="utext">
{% comment %}Translators: This is the text that appears in the button after a user has clicked upvote (already endorsed). {% endcomment %}
{% trans 'Notify upvoters' %}
</span>
</a>

<div id="notify-suggestion-{{ each_suggestion.id }}" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
TEST
<!-- TODO: review NotifySuggestionUpvotersForm to render form correctly here -->
{% crispy notify_upvoters_form %}
</div>
</div>
</div>
{% endif %}
</div>
{% endif %}
</div>
Expand Down Expand Up @@ -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 }
);
});
</script>
<script>
function viewUpvoters(e,suggestion,box){}
Expand Down
6 changes: 6 additions & 0 deletions TWLight/resources/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.conf.urls import url
from .filters import PartnerFilter
from .models import Partner

from . import views

Expand All @@ -16,4 +17,9 @@
name="toggle_waitlist",
),
url(r"^(?P<pk>\d+)/users/$", views.PartnerUsers.as_view(), name="users"),
url(
r"^partner/autocomplete/$",
views.PartnerAutocompleteView.as_view(model=Partner),
name="partner_autocomplete",
)
]
12 changes: 11 additions & 1 deletion TWLight/resources/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from django_filters.views import FilterView
from django.shortcuts import get_object_or_404

from dal import autocomplete

from TWLight.applications.helpers import count_valid_authorizations
from TWLight.applications.models import Application
from TWLight.users.groups import get_coordinators
Expand All @@ -24,7 +26,7 @@
from TWLight.users.helpers.editor_data import editor_bundle_eligible

from .filters import MainPartnerFilter, MergeSuggestionFilter
from .forms import SuggestionForm, SuggestionMergeForm
from .forms import SuggestionForm, SuggestionMergeForm, NotifySuggestionUpvotersForm
from .helpers import get_partner_description, get_tag_names, get_median
from .models import Partner, Suggestion
from urllib.parse import urlparse
Expand Down Expand Up @@ -487,6 +489,8 @@ def get_context_data(self, **kwargs):
else:
context["user_is_coordinator"] = False

context["notify_upvoters_form"] = NotifySuggestionUpvotersForm(user=self.request.user)

return context

def form_valid(self, form):
Expand Down Expand Up @@ -639,3 +643,9 @@ def form_valid(self, form):
"Some Error Occured",
)
raise PermissionDenied

class PartnerAutocompleteView(autocomplete.Select2QuerySetView):
def get_queryset(self):
partners = Partner.objects.all()

return partners
Binary file modified locale/ar/LC_MESSAGES/django.mo
Binary file not shown.
Loading