wbmailing 1.43.1__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of wbmailing might be problematic. Click here for more details.
- wbmailing/__init__.py +1 -0
- wbmailing/admin.py +74 -0
- wbmailing/apps.py +14 -0
- wbmailing/backend.py +131 -0
- wbmailing/celery.py +0 -0
- wbmailing/dynamic_preferences_registry.py +35 -0
- wbmailing/factories.py +211 -0
- wbmailing/filters/__init__.py +8 -0
- wbmailing/filters/mailing_lists.py +84 -0
- wbmailing/filters/mails.py +74 -0
- wbmailing/locale/de/LC_MESSAGES/django.po +1110 -0
- wbmailing/management/__init__.py +22 -0
- wbmailing/migrations/0001_initial_squashed_squashed_0008_alter_mail_bcc_email_alter_mail_cc_email_and_more.py +649 -0
- wbmailing/migrations/0002_delete_mailingsettings.py +16 -0
- wbmailing/migrations/0003_alter_mailinglistsubscriberchangerequest_options.py +25 -0
- wbmailing/migrations/__init__.py +0 -0
- wbmailing/models/__init__.py +6 -0
- wbmailing/models/mailing_lists.py +386 -0
- wbmailing/models/mails.py +895 -0
- wbmailing/serializers/__init__.py +19 -0
- wbmailing/serializers/mailing_lists.py +209 -0
- wbmailing/serializers/mails.py +251 -0
- wbmailing/tasks.py +37 -0
- wbmailing/templates/email_base_template.html +291 -0
- wbmailing/templates/mailing/maintain_mail_subsciptions.html +7 -0
- wbmailing/templates/mailing/manage_mailing_list_subscriptions.html +26 -0
- wbmailing/templates/template.html +295 -0
- wbmailing/templates/test.html +294 -0
- wbmailing/templates/workbench.html +24 -0
- wbmailing/templatetags/__init__.py +0 -0
- wbmailing/templatetags/mailing_tags.py +22 -0
- wbmailing/tests/__init__.py +0 -0
- wbmailing/tests/conftest.py +30 -0
- wbmailing/tests/models/__init__.py +0 -0
- wbmailing/tests/models/test_mailing_lists.py +297 -0
- wbmailing/tests/models/test_mails.py +205 -0
- wbmailing/tests/signals.py +124 -0
- wbmailing/tests/test_serializers.py +28 -0
- wbmailing/tests/test_tasks.py +49 -0
- wbmailing/tests/test_viewsets.py +216 -0
- wbmailing/tests/tests.py +142 -0
- wbmailing/urls.py +90 -0
- wbmailing/viewsets/__init__.py +32 -0
- wbmailing/viewsets/analytics.py +110 -0
- wbmailing/viewsets/buttons/__init__.py +10 -0
- wbmailing/viewsets/buttons/mailing_lists.py +91 -0
- wbmailing/viewsets/buttons/mails.py +98 -0
- wbmailing/viewsets/display/__init__.py +16 -0
- wbmailing/viewsets/display/mailing_lists.py +175 -0
- wbmailing/viewsets/display/mails.py +318 -0
- wbmailing/viewsets/endpoints/__init__.py +8 -0
- wbmailing/viewsets/endpoints/mailing_lists.py +86 -0
- wbmailing/viewsets/endpoints/mails.py +51 -0
- wbmailing/viewsets/mailing_lists.py +320 -0
- wbmailing/viewsets/mails.py +425 -0
- wbmailing/viewsets/menu/__init__.py +5 -0
- wbmailing/viewsets/menu/mailing_lists.py +37 -0
- wbmailing/viewsets/menu/mails.py +25 -0
- wbmailing/viewsets/titles/__init__.py +17 -0
- wbmailing/viewsets/titles/mailing_lists.py +63 -0
- wbmailing/viewsets/titles/mails.py +55 -0
- wbmailing-1.43.1.dist-info/METADATA +5 -0
- wbmailing-1.43.1.dist-info/RECORD +64 -0
- wbmailing-1.43.1.dist-info/WHEEL +5 -0
wbmailing/tests/tests.py
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
from unittest.mock import patch
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
from django.contrib.admin import AdminSite
|
|
5
|
+
from django.core import mail
|
|
6
|
+
from django.forms.models import model_to_dict
|
|
7
|
+
from django.template import Context, Template
|
|
8
|
+
from rest_framework import status
|
|
9
|
+
from rest_framework.serializers import ValidationError
|
|
10
|
+
from rest_framework.test import APIRequestFactory
|
|
11
|
+
from wbcore.contrib.directory.factories import EmailContactFactory
|
|
12
|
+
from wbcore.test import GenerateTest, default_config
|
|
13
|
+
from wbcore.test.utils import get_kwargs, get_model_factory
|
|
14
|
+
from wbmailing.admin import MailAdmin, MassMailAdmin
|
|
15
|
+
from wbmailing.factories import ToEmailMailFactory
|
|
16
|
+
from wbmailing.models import Mail, MailingListSubscriberChangeRequest, MassMail
|
|
17
|
+
from wbmailing.models.mails import send_mail_as_task
|
|
18
|
+
from wbmailing.serializers import MailingListSubscriberChangeRequestModelSerializer
|
|
19
|
+
from wbmailing.templatetags.mailing_tags import strip, stripAndsplit
|
|
20
|
+
from wbmailing.viewsets import MailingListSubscriberChangeRequestModelViewSet
|
|
21
|
+
|
|
22
|
+
config = {}
|
|
23
|
+
for key, value in default_config.items():
|
|
24
|
+
config[key] = list(
|
|
25
|
+
filter(
|
|
26
|
+
lambda x: x.__module__.startswith("wbmailing")
|
|
27
|
+
and x.__name__
|
|
28
|
+
not in [
|
|
29
|
+
"ClientsBarChartViewSet",
|
|
30
|
+
"CountryBarChartViewSet",
|
|
31
|
+
"RegionBarChartViewSet",
|
|
32
|
+
"MailStatusBarChartViewSet",
|
|
33
|
+
"MailClickBarChartViewSet",
|
|
34
|
+
"AbstractRawDataChartViewSet",
|
|
35
|
+
],
|
|
36
|
+
value,
|
|
37
|
+
)
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@pytest.mark.django_db
|
|
42
|
+
@GenerateTest(config)
|
|
43
|
+
class TestProject:
|
|
44
|
+
pass
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@pytest.mark.django_db
|
|
48
|
+
class TestSpecificAdmin:
|
|
49
|
+
def test_send_test_mail(self, mass_mail_factory, user):
|
|
50
|
+
request = APIRequestFactory().get("")
|
|
51
|
+
request.user = user
|
|
52
|
+
EmailContactFactory(address=request.user.email)
|
|
53
|
+
mass_mail_factory()
|
|
54
|
+
qs = MassMail.objects.all()
|
|
55
|
+
mma = MassMailAdmin(MassMail, AdminSite())
|
|
56
|
+
nb_mail_send = len(mail.outbox)
|
|
57
|
+
mma.send_test_mail(request, qs)
|
|
58
|
+
assert len(mail.outbox) == nb_mail_send + 1
|
|
59
|
+
|
|
60
|
+
@patch("wbmailing.models.mails.send_mail_as_task.delay")
|
|
61
|
+
def test_MailAdmin(self, send_mail_as_task, user):
|
|
62
|
+
request = APIRequestFactory().get("")
|
|
63
|
+
request.user = user
|
|
64
|
+
ToEmailMailFactory()
|
|
65
|
+
qs = Mail.objects.all()
|
|
66
|
+
|
|
67
|
+
ma = MailAdmin(Mail, AdminSite())
|
|
68
|
+
ma.send_mails(request, qs)
|
|
69
|
+
send_mail_as_task.assert_called()
|
|
70
|
+
assert send_mail_as_task.call_count == 1
|
|
71
|
+
|
|
72
|
+
def test_send_mail_as_task(self):
|
|
73
|
+
obj = ToEmailMailFactory.create()
|
|
74
|
+
context = {}
|
|
75
|
+
if obj.to_email.count() == 1:
|
|
76
|
+
context = {"salutation": obj.to_email.first().entry.salutation}
|
|
77
|
+
rendered_subject = Template(obj.subject).render(Context(context))
|
|
78
|
+
msg = {
|
|
79
|
+
"subject": rendered_subject,
|
|
80
|
+
"body": obj.body,
|
|
81
|
+
"from_email": obj.from_email,
|
|
82
|
+
"to": list(obj.to_email.values_list("address", flat=True)),
|
|
83
|
+
"bcc": list(obj.bcc_email.values_list("address", flat=True)),
|
|
84
|
+
"cc": list(obj.cc_email.values_list("address", flat=True)),
|
|
85
|
+
"mail_id": obj.id,
|
|
86
|
+
}
|
|
87
|
+
if obj.mass_mail:
|
|
88
|
+
msg["mass_mail_id"] = obj.mass_mail.id
|
|
89
|
+
assert len(mail.outbox) == 0
|
|
90
|
+
send_mail_as_task(**msg)
|
|
91
|
+
assert len(mail.outbox) == 1
|
|
92
|
+
|
|
93
|
+
def test_stripAndsplit(self):
|
|
94
|
+
string = "diego loic is the best man"
|
|
95
|
+
result = stripAndsplit(string, " ")
|
|
96
|
+
assert len(result) == 6
|
|
97
|
+
|
|
98
|
+
def test_strip(self):
|
|
99
|
+
string = "diego/loic/is/the/best/man"
|
|
100
|
+
string = strip(string)
|
|
101
|
+
result = stripAndsplit(string, " ")
|
|
102
|
+
assert len(result) == 1
|
|
103
|
+
|
|
104
|
+
def test_validate_email_contact(self, mailing_list, mailing_list_subscriber_change_request_factory, user):
|
|
105
|
+
request = APIRequestFactory().post("")
|
|
106
|
+
request.user = user
|
|
107
|
+
request.parser_context = {}
|
|
108
|
+
request.data = {"crm_profile": request.user.profile.id}
|
|
109
|
+
serializer = MailingListSubscriberChangeRequestModelSerializer(
|
|
110
|
+
mailing_list_subscriber_change_request_factory(mailing_list=mailing_list), context={"request": request}
|
|
111
|
+
)
|
|
112
|
+
data = model_to_dict(mailing_list_subscriber_change_request_factory.build(mailing_list=mailing_list))
|
|
113
|
+
del data["email_contact"]
|
|
114
|
+
assert serializer.validate(data) # this is fine because the instance is still in the serializer
|
|
115
|
+
|
|
116
|
+
serializer = MailingListSubscriberChangeRequestModelSerializer(context={"request": request})
|
|
117
|
+
with pytest.raises((ValidationError)):
|
|
118
|
+
serializer.validate(data)
|
|
119
|
+
|
|
120
|
+
@pytest.mark.parametrize("mvs", [MailingListSubscriberChangeRequestModelViewSet])
|
|
121
|
+
def test_approveall(self, mvs, user):
|
|
122
|
+
request = APIRequestFactory().get("")
|
|
123
|
+
request.user = user
|
|
124
|
+
factory = get_model_factory(mvs().get_serializer_class().Meta.model)
|
|
125
|
+
for i in range(2):
|
|
126
|
+
obj = factory()
|
|
127
|
+
kwargs = get_kwargs(obj, mvs, request)
|
|
128
|
+
assert (
|
|
129
|
+
MailingListSubscriberChangeRequest.objects.filter(
|
|
130
|
+
status=MailingListSubscriberChangeRequest.Status.PENDING
|
|
131
|
+
).count()
|
|
132
|
+
== 2
|
|
133
|
+
)
|
|
134
|
+
response = mvs(kwargs=kwargs).approveall(request=request)
|
|
135
|
+
assert response.status_code == status.HTTP_200_OK
|
|
136
|
+
assert response.data
|
|
137
|
+
assert (
|
|
138
|
+
MailingListSubscriberChangeRequest.objects.filter(
|
|
139
|
+
status=MailingListSubscriberChangeRequest.Status.APPROVED
|
|
140
|
+
).count()
|
|
141
|
+
== 2
|
|
142
|
+
)
|
wbmailing/urls.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
from django.urls import include, path
|
|
2
|
+
from wbcore.routers import WBCoreRouter
|
|
3
|
+
from wbmailing import viewsets
|
|
4
|
+
|
|
5
|
+
router = WBCoreRouter()
|
|
6
|
+
router.register(r"mailinglist", viewsets.MailingListModelViewSet)
|
|
7
|
+
router.register(r"mailrepresentation", viewsets.MailRepresentationViewSet, basename="mailrepresentation")
|
|
8
|
+
router.register(
|
|
9
|
+
r"mailinglistrepresentation", viewsets.MailingListRepresentationViewSet, basename="mailinglistrepresentation"
|
|
10
|
+
)
|
|
11
|
+
router.register(
|
|
12
|
+
r"mailtemplaterepresentation", viewsets.MailTemplateRepresentationViewSet, basename="mailtemplaterepresentation"
|
|
13
|
+
)
|
|
14
|
+
router.register(r"massmailrepresentation", viewsets.MassMailRepresentationViewSet, basename="massmailrepresentation")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
router.register(r"massmail", viewsets.MassMailModelViewSet)
|
|
18
|
+
router.register(r"mailevent", viewsets.MailEventModelViewSet)
|
|
19
|
+
router.register(r"mail", viewsets.MailModelViewSet)
|
|
20
|
+
router.register(r"mailtemplate", viewsets.MailTemplateModelViewSet)
|
|
21
|
+
router.register(
|
|
22
|
+
r"mailinglistsubscriberchangerequest",
|
|
23
|
+
viewsets.MailingListSubscriberChangeRequestModelViewSet,
|
|
24
|
+
basename="mailinglistsubscriberchangerequest",
|
|
25
|
+
)
|
|
26
|
+
router.register(
|
|
27
|
+
"mailinglistemailcontact",
|
|
28
|
+
viewsets.MailingListEmailContactThroughModelModelViewSet,
|
|
29
|
+
basename="mailinglistemailcontact",
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
entry_router = WBCoreRouter()
|
|
33
|
+
entry_router.register(r"mailinglist", viewsets.MailingListEntryModelViewSet, basename="entry-mailinglist")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
entry_router.register(
|
|
37
|
+
r"mailinglistsubscriberchangerequest",
|
|
38
|
+
viewsets.MailingListSubscriberRequestEntryModelViewSet,
|
|
39
|
+
basename="entry-mailinglistsubscriberchangerequest",
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
mailinglist_router = WBCoreRouter()
|
|
43
|
+
mailinglist_router.register(
|
|
44
|
+
r"mailinglistsubscriberchangerequest",
|
|
45
|
+
viewsets.MailingListSubscriberRequestMailingListModelViewSet,
|
|
46
|
+
basename="mailing_list-mailinglistsubscriberchangerequest",
|
|
47
|
+
)
|
|
48
|
+
mailinglist_router.register(
|
|
49
|
+
r"email_contacts",
|
|
50
|
+
viewsets.EmailContactMailingListModelViewSet,
|
|
51
|
+
basename="mailing_list-email_contacts",
|
|
52
|
+
)
|
|
53
|
+
mailinglist_router.register(
|
|
54
|
+
r"maileventchart", viewsets.MailMailingListChartViewSet, basename="mailing_list-maileventchart"
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
mail_router = WBCoreRouter()
|
|
59
|
+
mail_router.register(r"mailevent", viewsets.MailEventMailModelViewSet, basename="mail-mailevent")
|
|
60
|
+
|
|
61
|
+
massmail_router = WBCoreRouter()
|
|
62
|
+
massmail_router.register(r"mailstatus", viewsets.MailStatusMassMailModelViewSet, basename="massmail-mailstatus")
|
|
63
|
+
massmail_router.register(
|
|
64
|
+
r"mailstatusbarchart", viewsets.MailStatusBarChartViewSet, basename="massmail-mailstatusbarchart"
|
|
65
|
+
)
|
|
66
|
+
massmail_router.register(
|
|
67
|
+
r"mailclickbarchart", viewsets.MailClickBarChartViewSet, basename="massmail-mailclickbarchart"
|
|
68
|
+
)
|
|
69
|
+
massmail_router.register(r"clientsbarchart", viewsets.ClientsBarChartViewSet, basename="massmail-clientsbarchart")
|
|
70
|
+
massmail_router.register(r"countrybarchart", viewsets.CountryBarChartViewSet, basename="massmail-countrybarchart")
|
|
71
|
+
massmail_router.register(r"regionbarchart", viewsets.RegionBarChartViewSet, basename="massmail-regionbarchart")
|
|
72
|
+
massmail_router.register("mailevent", viewsets.MailEventMassMailMailModelViewSet, basename="massmail-mailevent")
|
|
73
|
+
|
|
74
|
+
urlpatterns = [
|
|
75
|
+
path("", include(router.urls)),
|
|
76
|
+
path("entry/<int:entry_id>/", include(entry_router.urls)),
|
|
77
|
+
path("mailing_list/<int:mailing_list_id>/", include(mailinglist_router.urls)),
|
|
78
|
+
path("mail/<int:mail_id>/", include(mail_router.urls)),
|
|
79
|
+
path("massmail/<int:mass_mail_id>/", include(massmail_router.urls)),
|
|
80
|
+
path(
|
|
81
|
+
"manage_mailing_list_subscriptions/<int:email_contact_id>/",
|
|
82
|
+
viewsets.ManageMailingListSubscriptions.as_view(),
|
|
83
|
+
name="manage_mailing_list_subscriptions",
|
|
84
|
+
),
|
|
85
|
+
path(
|
|
86
|
+
"unsubscribe/<int:email_contact_id>/<int:mailing_list_id>/",
|
|
87
|
+
viewsets.UnsubscribeView.as_view(),
|
|
88
|
+
name="unsubscribe",
|
|
89
|
+
),
|
|
90
|
+
]
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from .analytics import (
|
|
2
|
+
ClientsBarChartViewSet,
|
|
3
|
+
CountryBarChartViewSet,
|
|
4
|
+
MailClickBarChartViewSet,
|
|
5
|
+
MailStatusBarChartViewSet,
|
|
6
|
+
RegionBarChartViewSet,
|
|
7
|
+
)
|
|
8
|
+
from .mailing_lists import (
|
|
9
|
+
EmailContactMailingListModelViewSet,
|
|
10
|
+
MailingListEmailContactThroughModelModelViewSet,
|
|
11
|
+
MailingListEntryModelViewSet,
|
|
12
|
+
MailingListModelViewSet,
|
|
13
|
+
MailingListRepresentationViewSet,
|
|
14
|
+
MailingListSubscriberChangeRequestModelViewSet,
|
|
15
|
+
MailingListSubscriberRequestEntryModelViewSet,
|
|
16
|
+
MailingListSubscriberRequestMailingListModelViewSet,
|
|
17
|
+
ManageMailingListSubscriptions,
|
|
18
|
+
UnsubscribeView,
|
|
19
|
+
)
|
|
20
|
+
from .mails import (
|
|
21
|
+
MailEventModelViewSet,
|
|
22
|
+
MailEventMailModelViewSet,
|
|
23
|
+
MailEventMassMailMailModelViewSet,
|
|
24
|
+
MailMailingListChartViewSet,
|
|
25
|
+
MailModelViewSet,
|
|
26
|
+
MailRepresentationViewSet,
|
|
27
|
+
MailStatusMassMailModelViewSet,
|
|
28
|
+
MailTemplateModelViewSet,
|
|
29
|
+
MailTemplateRepresentationViewSet,
|
|
30
|
+
MassMailModelViewSet,
|
|
31
|
+
MassMailRepresentationViewSet,
|
|
32
|
+
)
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
from typing import TYPE_CHECKING
|
|
2
|
+
|
|
3
|
+
import pandas as pd
|
|
4
|
+
import plotly.express as px
|
|
5
|
+
import plotly.graph_objects as go
|
|
6
|
+
from django.db.models import QuerySet
|
|
7
|
+
from wbcore import viewsets
|
|
8
|
+
from wbmailing.models import Mail, MailEvent
|
|
9
|
+
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
from plotly.graph_objs._figure import Figure
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class MailStatusBarChartViewSet(viewsets.ChartViewSet):
|
|
15
|
+
IDENTIFIER = "wbmailing:mailstatus-barchart"
|
|
16
|
+
queryset = MailEvent.objects.all()
|
|
17
|
+
|
|
18
|
+
def get_queryset(self) -> QuerySet[Mail]:
|
|
19
|
+
mass_mail_id = self.kwargs["mass_mail_id"]
|
|
20
|
+
|
|
21
|
+
return super().get_queryset().filter(mail__mass_mail_id=mass_mail_id)
|
|
22
|
+
|
|
23
|
+
def get_plotly(self, queryset: QuerySet[Mail]) -> "Figure":
|
|
24
|
+
df = pd.DataFrame(queryset.values("event_type"))
|
|
25
|
+
df["count"] = 1
|
|
26
|
+
|
|
27
|
+
df = df.groupby(["event_type"])["count"].count().reset_index().sort_values(by="count")
|
|
28
|
+
fig = px.bar(df, x="count", y="event_type", orientation="h")
|
|
29
|
+
fig.update_layout(
|
|
30
|
+
yaxis={"showticklabels": True, "title": None},
|
|
31
|
+
xaxis={"title": "Number"},
|
|
32
|
+
title={"text": "Mail Status", "x": 0.5},
|
|
33
|
+
)
|
|
34
|
+
return fig
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class MailClickBarChartViewSet(viewsets.ChartViewSet):
|
|
38
|
+
IDENTIFIER = "wbmailing:mailclick-barchart"
|
|
39
|
+
queryset = MailEvent.objects.all()
|
|
40
|
+
|
|
41
|
+
def get_queryset(self) -> QuerySet[MailEvent]:
|
|
42
|
+
mass_mail_id = self.kwargs["mass_mail_id"]
|
|
43
|
+
|
|
44
|
+
return super().get_queryset().filter(mail__mass_mail_id=mass_mail_id, event_type=MailEvent.EventType.CLICKED)
|
|
45
|
+
|
|
46
|
+
def get_plotly(self, queryset: QuerySet[MailEvent]) -> "Figure":
|
|
47
|
+
df = pd.DataFrame(queryset.values("click_url"))
|
|
48
|
+
df["count"] = 1
|
|
49
|
+
df = df.groupby(["click_url"])["count"].count().reset_index().sort_values(by="count")
|
|
50
|
+
fig = go.Figure(layout=dict(template="plotly")) # noqa THis is necessary to prevent some racing condition
|
|
51
|
+
fig = px.bar(df, x="count", y="click_url", text="click_url", orientation="h")
|
|
52
|
+
fig.update_layout(
|
|
53
|
+
yaxis={"visible": False, "showticklabels": False},
|
|
54
|
+
xaxis={"title": "Number of clicks"},
|
|
55
|
+
title={"text": "Clicked URLs", "x": 0.5},
|
|
56
|
+
)
|
|
57
|
+
return fig
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class AbstractRawDataChartViewSet(viewsets.ChartViewSet):
|
|
61
|
+
queryset = MailEvent.objects.all()
|
|
62
|
+
ANALYTICS_PROPERTY: str
|
|
63
|
+
|
|
64
|
+
def get_queryset(self) -> QuerySet[MailEvent]:
|
|
65
|
+
mass_mail_id = self.kwargs["mass_mail_id"]
|
|
66
|
+
|
|
67
|
+
return super().get_queryset().filter(mail__mass_mail_id=mass_mail_id, event_type=MailEvent.EventType.OPENED)
|
|
68
|
+
|
|
69
|
+
def get_plotly(self, queryset: QuerySet[MailEvent]) -> "Figure":
|
|
70
|
+
df = pd.DataFrame(queryset.values(self.ANALYTICS_PROPERTY))
|
|
71
|
+
df["count"] = 1
|
|
72
|
+
df = df.groupby(self.ANALYTICS_PROPERTY)["count"].count().reset_index().sort_values(by="count")
|
|
73
|
+
fig = go.Figure()
|
|
74
|
+
if not df.empty:
|
|
75
|
+
fig = px.bar(df, x=self.ANALYTICS_PROPERTY, y="count")
|
|
76
|
+
fig.update_layout(
|
|
77
|
+
xaxis={"showticklabels": True, "title": None},
|
|
78
|
+
yaxis={"showticklabels": True, "title": "Number"},
|
|
79
|
+
)
|
|
80
|
+
return fig
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class ClientsBarChartViewSet(AbstractRawDataChartViewSet):
|
|
84
|
+
IDENTIFIER = "wbmailing:client-barchart"
|
|
85
|
+
ANALYTICS_PROPERTY = "raw_data__Client__Name"
|
|
86
|
+
|
|
87
|
+
def get_plotly(self, queryset: QuerySet[MailEvent]) -> "Figure":
|
|
88
|
+
fig = super().get_plotly(queryset)
|
|
89
|
+
fig.update_layout(title={"text": "Platforms", "x": 0.5})
|
|
90
|
+
return fig
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class CountryBarChartViewSet(AbstractRawDataChartViewSet):
|
|
94
|
+
IDENTIFIER = "wbmailing:country-barchart"
|
|
95
|
+
ANALYTICS_PROPERTY = "raw_data__Geo__Country"
|
|
96
|
+
|
|
97
|
+
def get_plotly(self, queryset: QuerySet[MailEvent]) -> "Figure":
|
|
98
|
+
fig = super().get_plotly(queryset)
|
|
99
|
+
fig.update_layout(title={"text": "Countries", "x": 0.5})
|
|
100
|
+
return fig
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class RegionBarChartViewSet(AbstractRawDataChartViewSet):
|
|
104
|
+
IDENTIFIER = "wbmailing:region-barchart"
|
|
105
|
+
ANALYTICS_PROPERTY = "raw_data__Geo__Region"
|
|
106
|
+
|
|
107
|
+
def get_plotly(self, queryset: QuerySet[MailEvent]) -> "Figure":
|
|
108
|
+
fig = super().get_plotly(queryset)
|
|
109
|
+
fig.update_layout(title={"text": "Regions", "x": 0.5})
|
|
110
|
+
return fig
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from .mailing_lists import (
|
|
2
|
+
MailingListButtonConfig,
|
|
3
|
+
MailingListEmailContactThroughModelButtonConfig,
|
|
4
|
+
MailingListSubcriptionRequestButtonConfig,
|
|
5
|
+
)
|
|
6
|
+
from .mails import (
|
|
7
|
+
MailButtonConfig,
|
|
8
|
+
MailStatusMassMailButtonConfig,
|
|
9
|
+
MassMailButtonConfig,
|
|
10
|
+
)
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
from django.dispatch import receiver
|
|
2
|
+
from django.utils.translation import gettext as _
|
|
3
|
+
from rest_framework.reverse import reverse
|
|
4
|
+
from wbcore.contrib.directory.viewsets import (
|
|
5
|
+
CompanyModelViewSet,
|
|
6
|
+
EntryModelViewSet,
|
|
7
|
+
PersonModelViewSet,
|
|
8
|
+
)
|
|
9
|
+
from wbcore.contrib.icons import WBIcon
|
|
10
|
+
from wbcore.enums import RequestType
|
|
11
|
+
from wbcore.metadata.configs import buttons as bt
|
|
12
|
+
from wbcore.metadata.configs.buttons.view_config import ButtonViewConfig
|
|
13
|
+
from wbcore.signals.instance_buttons import add_instance_button
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class MailingListSubcriptionRequestButtonConfig(ButtonViewConfig):
|
|
17
|
+
def get_custom_buttons(self):
|
|
18
|
+
if not hasattr(self.view.kwargs, "pk"):
|
|
19
|
+
user = self.request.user
|
|
20
|
+
if user.is_superuser or user.has_perm("wbmailing.administrate_mailinglistsubscriberchangerequest"):
|
|
21
|
+
return {
|
|
22
|
+
bt.ActionButton(
|
|
23
|
+
method=RequestType.GET,
|
|
24
|
+
identifiers=("wbmailing:mailinglistsubscriberchangerequest",),
|
|
25
|
+
endpoint=reverse(
|
|
26
|
+
"wbmailing:mailinglistsubscriberchangerequest-approveall", args=[], request=self.request
|
|
27
|
+
),
|
|
28
|
+
label=_("Approve All"),
|
|
29
|
+
description_fields=_(
|
|
30
|
+
"""
|
|
31
|
+
<p>Do you really want to approve all pending subscriptions requests?</p>
|
|
32
|
+
"""
|
|
33
|
+
),
|
|
34
|
+
action_label=_("Approving all pending subscription requests"),
|
|
35
|
+
title=_("Approve all pending subscription requests"),
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
return {}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class MailingListButtonConfig(ButtonViewConfig):
|
|
42
|
+
def get_custom_instance_buttons(self):
|
|
43
|
+
return {
|
|
44
|
+
bt.WidgetButton(key="mailevent_chart", label=_("Mail Penetration"), icon=WBIcon.FEEDBACK.icon),
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
def get_custom_list_instance_buttons(self):
|
|
48
|
+
return self.get_custom_instance_buttons()
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class MailingListEmailContactThroughModelButtonConfig(ButtonViewConfig):
|
|
52
|
+
def get_custom_list_instance_buttons(self):
|
|
53
|
+
return {
|
|
54
|
+
bt.WidgetButton(key="requests", label="Changes Request History", icon=WBIcon.DATA_LIST.icon),
|
|
55
|
+
bt.ActionButton(
|
|
56
|
+
method=RequestType.PATCH,
|
|
57
|
+
identifiers=("directory:email_contacts",),
|
|
58
|
+
key="delete_from_mailinglist",
|
|
59
|
+
label=_("Delete"),
|
|
60
|
+
icon=WBIcon.DELETE.icon,
|
|
61
|
+
description_fields=_(
|
|
62
|
+
"<p> Are you sure you want to delete {{_entry.computed_str}} from this mailinglist? Check with your compliance team if you are not sure</p>"
|
|
63
|
+
),
|
|
64
|
+
title=_("Delete"),
|
|
65
|
+
action_label=_("Deletion"),
|
|
66
|
+
),
|
|
67
|
+
bt.ActionButton(
|
|
68
|
+
method=RequestType.PATCH,
|
|
69
|
+
identifiers=("directory:email_contacts",),
|
|
70
|
+
key="unsubscribe",
|
|
71
|
+
label=_("Unsubscribe"),
|
|
72
|
+
icon=WBIcon.UNDO.icon,
|
|
73
|
+
description_fields=_(
|
|
74
|
+
"<p> Are you sure you want to unsubscribe {{_entry.computed_str}} from this mailinglist? Until the entry exists, the user won't be able to resubscribe</p>"
|
|
75
|
+
),
|
|
76
|
+
title=_("Unsubscribe"),
|
|
77
|
+
action_label=_("Unsubscribing"),
|
|
78
|
+
),
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@receiver(add_instance_button, sender=PersonModelViewSet)
|
|
83
|
+
@receiver(add_instance_button, sender=EntryModelViewSet)
|
|
84
|
+
@receiver(add_instance_button, sender=CompanyModelViewSet)
|
|
85
|
+
def crm_adding_instance_buttons_ep(sender, many, *args, **kwargs):
|
|
86
|
+
if not many:
|
|
87
|
+
return bt.DropDownButton(
|
|
88
|
+
label=_("Mailing"),
|
|
89
|
+
icon=WBIcon.UNFOLD.icon,
|
|
90
|
+
buttons=(bt.WidgetButton(key="mailinglist", label=_("Mailing"), icon=WBIcon.MAIL.icon),),
|
|
91
|
+
)
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
from django.utils.translation import gettext as _
|
|
2
|
+
from django.utils.translation import gettext_lazy
|
|
3
|
+
from rest_framework.reverse import reverse
|
|
4
|
+
from wbcore import serializers as wb_serializers
|
|
5
|
+
from wbcore.contrib.icons import WBIcon
|
|
6
|
+
from wbcore.enums import RequestType
|
|
7
|
+
from wbcore.metadata.configs import buttons as bt
|
|
8
|
+
from wbcore.metadata.configs.buttons.view_config import ButtonViewConfig
|
|
9
|
+
from wbcore.metadata.configs.display.instance_display.shortcuts import (
|
|
10
|
+
create_simple_display,
|
|
11
|
+
)
|
|
12
|
+
from wbmailing.models import MassMail
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class MassMailButtonConfig(ButtonViewConfig):
|
|
16
|
+
def get_custom_instance_buttons(self):
|
|
17
|
+
class SendTestMailActionButtonSerializer(wb_serializers.Serializer):
|
|
18
|
+
to_test_email = wb_serializers.CharField(label=gettext_lazy("Send To"), default=self.request.user.email)
|
|
19
|
+
|
|
20
|
+
class Meta:
|
|
21
|
+
fields = ["to_test_email"]
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
bt.ActionButton(
|
|
25
|
+
method=RequestType.PATCH,
|
|
26
|
+
identifiers=("wbmailing:entry-mailinglist",),
|
|
27
|
+
action_label=_("Sending test mail"),
|
|
28
|
+
key="send_test_mail",
|
|
29
|
+
description_fields=_("<p>Are you sure you want to send a test mail?</p>"),
|
|
30
|
+
serializer=SendTestMailActionButtonSerializer,
|
|
31
|
+
icon=WBIcon.CHART_SWITCHES.icon,
|
|
32
|
+
title=_("Test Mail"),
|
|
33
|
+
label=_("Test Mail"),
|
|
34
|
+
instance_display=create_simple_display([["to_test_email"]]),
|
|
35
|
+
),
|
|
36
|
+
bt.WidgetButton(key="mails", label=_("Mails' Status"), icon=WBIcon.MAIL_OPEN.icon),
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class MailButtonConfig(ButtonViewConfig):
|
|
41
|
+
def get_custom_instance_buttons(self):
|
|
42
|
+
title = gettext_lazy("Resend Mail")
|
|
43
|
+
action_label = gettext_lazy("Resending mail")
|
|
44
|
+
description = gettext_lazy("<p>Are you sure you want to resend the mail?</p>")
|
|
45
|
+
icon = WBIcon.REPLACE.icon
|
|
46
|
+
try:
|
|
47
|
+
mail = self.view.get_object()
|
|
48
|
+
if not mail.events.exists():
|
|
49
|
+
title = gettext_lazy("Send Mail")
|
|
50
|
+
action_label = gettext_lazy("Sending mail")
|
|
51
|
+
description = gettext_lazy("<p>Are you sure you want to send the mail?</p>")
|
|
52
|
+
icon = WBIcon.SEND.icon
|
|
53
|
+
except AssertionError:
|
|
54
|
+
pass
|
|
55
|
+
return {
|
|
56
|
+
bt.ActionButton(
|
|
57
|
+
method=RequestType.PATCH,
|
|
58
|
+
identifiers=("wbmailing:mail",),
|
|
59
|
+
action_label=action_label,
|
|
60
|
+
key="resend_mail",
|
|
61
|
+
description_fields=description,
|
|
62
|
+
icon=icon,
|
|
63
|
+
title=title,
|
|
64
|
+
label=title,
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
def get_custom_list_instance_buttons(self):
|
|
69
|
+
return self.get_custom_instance_buttons()
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class MailStatusMassMailButtonConfig(ButtonViewConfig):
|
|
73
|
+
def get_custom_buttons(self):
|
|
74
|
+
if not self.view.kwargs.get("pk", None) and (mass_mail_id := self.view.kwargs.get("mass_mail_id", None)):
|
|
75
|
+
mass_mail = MassMail.objects.get(id=mass_mail_id)
|
|
76
|
+
if mass_mail.status == MassMail.Status.SENT:
|
|
77
|
+
return {
|
|
78
|
+
bt.ActionButton(
|
|
79
|
+
method=RequestType.PATCH,
|
|
80
|
+
identifiers=("wbmailing:massmail",),
|
|
81
|
+
endpoint=reverse(
|
|
82
|
+
"wbmailing:massmail-mailstatus-resendbouncedmails",
|
|
83
|
+
args=[mass_mail_id],
|
|
84
|
+
request=self.request,
|
|
85
|
+
),
|
|
86
|
+
label=_("Resend Bounced Emails"),
|
|
87
|
+
description_fields=_(
|
|
88
|
+
"""
|
|
89
|
+
<p>Do not abuse this function! Doing so will likely degrade your mailing reputation.</p>
|
|
90
|
+
<p>If you are sure, please confirm</>
|
|
91
|
+
<p>
|
|
92
|
+
"""
|
|
93
|
+
),
|
|
94
|
+
action_label=_("Resending bounced emails"),
|
|
95
|
+
title=_("Resend Bounced Emails"),
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
return set()
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from .mailing_lists import (
|
|
2
|
+
EmailContactMailingListDisplayConfig,
|
|
3
|
+
MailingListDisplayConfig,
|
|
4
|
+
MailingListEntryCompanyDisplayConfig,
|
|
5
|
+
MailingListEntryDisplayConfig,
|
|
6
|
+
MailingListSubscriberChangeRequestDisplayConfig,
|
|
7
|
+
MailingListSubscriberRequestEntryDisplayConfig,
|
|
8
|
+
MailingListSubscriberRequestMailingListDisplayConfig,
|
|
9
|
+
)
|
|
10
|
+
from .mails import (
|
|
11
|
+
MailDisplayConfig,
|
|
12
|
+
MailEventDisplayConfig,
|
|
13
|
+
MailStatusMassMailDisplayConfig,
|
|
14
|
+
MailTemplateDisplayConfig,
|
|
15
|
+
MassMailDisplayConfig,
|
|
16
|
+
)
|