diff --git a/src/nalodeni/forms.py b/src/nalodeni/forms.py index 1bd5dd2..20a2f4c 100644 --- a/src/nalodeni/forms.py +++ b/src/nalodeni/forms.py @@ -231,3 +231,5 @@ class Euro2019InterestForm(ModelForm): raise ValidationError(_('Prosím, potvrďte souhlas se zpracováním osobních údajů.'), code='invalid') return data +class CustomRecipientsForm(forms.Form): + recipients = forms.CharField(widget=forms.Textarea) diff --git a/src/nalodeni/news.py b/src/nalodeni/news.py index 4aa9120..e0883f6 100644 --- a/src/nalodeni/news.py +++ b/src/nalodeni/news.py @@ -147,6 +147,7 @@ def list_show(request, lid): if (request.user == obj.managed_by or 'sso_news_manage' in site_perms): actions.add('nwsl_edit') + actions.add('nwsl_send_custom') if (request.user in obj.sent_by.all() or request.user == obj.managed_by or 'sso_news_manage' in site_perms): actions.add('nwsl_details') @@ -314,10 +315,43 @@ def msg_edit(request, lid, mid=None): return render(request, template, context) +@ensure_csrf_cookie +@login_required(login_url="/prihlaseni") +def msg_send_custom(request, id): + + custom_recip=set() + + if request.method == "POST": + form = forms.CustomRecipientsForm(request.POST) + if form.is_valid(): + all_ok = True + for addr in form.cleaned_data['recipients'].replace("\n",",").split(","): + addr = addr.strip() + try: + validate_email(addr) + custom_recip.update([addr,]) # add list, string is also a list !!! + except ValidationError: + messages.error(request, "Email '%s' není ve správném tvaru." % (addr)) + all_ok=False + if all_ok: + return msg_send(request, id, True, custom_recip) + else: + messages.error(request, "Je třeba opravit vadné adresy.") + + else: + form = forms.CustomRecipientsForm() + + template = 'news/msg_send_custom.html' + context = { + 'form' : form, + } + + return render(request, template, context) + @ensure_csrf_cookie @login_required(login_url="/prihlaseni") -def msg_send(request, id, realSend=False): +def msg_send(request, id, realSend=False, custom_recip=set()): """ Odeslani newsletteru. """ @@ -354,6 +388,10 @@ def msg_send(request, id, realSend=False): update_sent_ts = True use_public_to_email = True recip_users = obj.news.get_recip_users() + elif recipients_wanted == "custom": + update_send_ts = False + use_public_to_email = True + recip_users = [ request.user ] else: recip_users = [ request.user ] else: @@ -383,6 +421,11 @@ def msg_send(request, id, realSend=False): except ValidationError: messages.error(request, "Email '%s' uživatele %s není ve správném tvaru." % (eml, rcp.username)) + # add custom recipients + recipients_email += list(custom_recip) + # do it unique + recipients_email = list(set(recipients_email)) + template = 'news/msg_to_email.html' context = { 'msg' : obj, @@ -400,7 +443,7 @@ def msg_send(request, id, realSend=False): import quopri for recip_part in chunks(recipients_email, 500): - # process by part, MailGun API hsa a limit of 1000 messages + # process by part, MailGun API has a limit of 1000 messages mailgun_backend = get_connection('anymail.backends.mailgun.EmailBackend') diff --git a/src/nalodeni/templates/news/list_show.html b/src/nalodeni/templates/news/list_show.html index dc6fe94..a94e789 100644 --- a/src/nalodeni/templates/news/list_show.html +++ b/src/nalodeni/templates/news/list_show.html @@ -53,6 +53,9 @@ Náhled Testovací email {% endif%} + {% if 'nwsl_send_custom' in actions %} + Odeslat + {% endif%} {% endfor %} diff --git a/src/nalodeni/templates/news/msg_send_custom.html b/src/nalodeni/templates/news/msg_send_custom.html new file mode 100644 index 0000000..af44443 --- /dev/null +++ b/src/nalodeni/templates/news/msg_send_custom.html @@ -0,0 +1,35 @@ +{% extends 'pirati_cz.html' %} + +{%block body%} +
+
+
+
+
+

Odeslání zprávy na vlastní seznam emailů

+
+

Adresy příjemců zadávejte po jedné na řádek.

+
+ {%csrf_token%} + {{form}} +
+ +
+
+
+
+
+
+ +
+
+
+
+   +
+
+
+
+ + +{%endblock%} diff --git a/src/nalodeni/urls.py b/src/nalodeni/urls.py index 93e3ea8..68ca470 100644 --- a/src/nalodeni/urls.py +++ b/src/nalodeni/urls.py @@ -58,6 +58,7 @@ urlpatterns = [ url(r'^news/msg/(?P[0-9]+)/preview/$', news.msg_preview, name="news_msg_preview"), url(r'^news/msg/(?P[0-9]+)/send/$', news.msg_send, name="news_msg_send", kwargs={'realSend':True}), + url(r'^news/msg/(?P[0-9]+)/send_custom/$', news.msg_send_custom, name="news_msg_send_custom"), ]