Comparer les révisions
1 Révisions
develop
...
expose-ema
Auteur | SHA1 | Date |
---|---|---|
Antoine | f651ac0578 |
|
@ -1,3 +1,5 @@
|
|||
from django.contrib.auth.models import Permission
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib.messages import ERROR as ERROR_LEVEL
|
||||
from django.contrib.messages import SUCCESS as SUCCESS_LEVEL
|
||||
from django.contrib.messages import get_messages
|
||||
|
@ -132,3 +134,24 @@ class TestSubscriptionConfirmView:
|
|||
assert response.status_code == 200
|
||||
assert response.context['subscriber'] == self.subscriber
|
||||
assert not response.context['activated']
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestExposeEmailsAddress:
|
||||
def setup(self):
|
||||
self.subscriber = Subscriber.objects.create(email='test@no.lan')
|
||||
|
||||
def test_not_authorized(self, client):
|
||||
client.login(username='robbie', password='sho7sho7')
|
||||
response = client.get(reverse('newsletter:address'))
|
||||
assert response.status_code == 302
|
||||
|
||||
def test_authorized(self, client, user):
|
||||
content_type = ContentType.objects.get_for_model(Subscriber)
|
||||
permission = Permission.objects.get(
|
||||
content_type=content_type, codename='view_subscriber'
|
||||
)
|
||||
user.user_permissions.add(permission)
|
||||
client.login(username='robbie', password='sho7sho7')
|
||||
response = client.get(reverse('newsletter:address'))
|
||||
assert response.status_code == 200
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from django.urls import path
|
||||
|
||||
from .views import SubscribeView, SubscriptionConfirmView
|
||||
from .views import ExposeEmailsAddress, SubscribeView, SubscriptionConfirmView
|
||||
|
||||
app_name = 'newsletter'
|
||||
|
||||
|
@ -15,4 +15,9 @@ urlpatterns = [
|
|||
SubscriptionConfirmView.as_view(),
|
||||
name='subscription_confirm',
|
||||
),
|
||||
path(
|
||||
'address/',
|
||||
ExposeEmailsAddress.as_view(),
|
||||
name='address',
|
||||
),
|
||||
]
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||
from django.contrib.sites.shortcuts import get_current_site
|
||||
from django.core.mail import send_mail
|
||||
from django.template.loader import render_to_string
|
||||
|
@ -87,3 +88,17 @@ class SubscriptionConfirmView(TemplateView):
|
|||
return self.render_to_response(
|
||||
self.get_context_data(subscriber=subscriber, activated=activated)
|
||||
)
|
||||
|
||||
|
||||
class ExposeEmailsAddress(PermissionRequiredMixin, TemplateView):
|
||||
""" Expose la liste des adresses mail, en texte pour sympa """
|
||||
|
||||
permission_required = 'newsletter.view_subscriber'
|
||||
template_name = 'newsletter/address.html'
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
return self.render_to_response(
|
||||
self.get_context_data(
|
||||
address=Subscriber.objects.filter(activated=True)
|
||||
)
|
||||
)
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
{% for subscriber in address %}
|
||||
{{ subscriber.email|linebreaks }}
|
||||
{% endfor %}
|
Chargement…
Référencer dans un nouveau ticket