# Path: courriers/views.py
# class NewsletterListView(AJAXResponseMixin, ListView):
#     model = Newsletter
#     context_object_name = "newsletters"
#     template_name = "courriers/newsletter_list.html"
#     paginate_by = PAGINATE_BY
# 
#     def dispatch(self, *args, **kwargs):
#         return super(NewsletterListView, self).dispatch(*args, **kwargs)
# 
#     @cached_property
#     def newsletter_list(self):
#         return get_object_or_404(
#             NewsletterList.objects.all(), slug=self.kwargs.get("slug")
#         )
# 
#     def get_queryset(self):
#         lang = translation.get_language()
#         qs = self.newsletter_list.newsletters.status_online()
#         if lang:
#             qs = qs.filter(newsletter_segment__lang=lang)
#         qs = qs.order_by("-published_at")
#         return qs
# 
#     def get_context_data(self, **kwargs):
#         context = super(NewsletterListView, self).get_context_data(**kwargs)
#         context["newsletter_list"] = self.newsletter_list
#         return context
# 
# class NewsletterDetailView(AJAXResponseMixin, DetailView):
#     model = Newsletter
#     context_object_name = "newsletter"
#     template_name = "courriers/newsletter_detail.html"
# 
#     def get_queryset(self):
#         return self.model.objects.status_online()
# 
#     def get_context_data(self, **kwargs):
#         context = super(NewsletterDetailView, self).get_context_data(**kwargs)
# 
#         context["newsletter_list"] = self.object.newsletter_list
# 
#         return context
# 
# class NewsletterListSubscribeView(BaseNewsletterListFormView):
#     template_name = "courriers/newsletter_list_subscribe_form.html"
#     form_class = SubscriptionForm
# 
#     def get_success_url(self):
#         return reverse("newsletter_list_subscribe_done")
# 
# class NewsletterRawDetailView(AJAXResponseMixin, DetailView):
#     model = Newsletter
#     template_name = "courriers/newsletter_raw_detail.html"
# 
#     def get_context_data(self, **kwargs):
#         context = super(NewsletterRawDetailView, self).get_context_data(**kwargs)
# 
#         context["items"] = self.object.items.all()
# 
#         for item in context["items"]:
#             item.newsletter = self.object
# 
#         return context
# 
# class NewsletterListUnsubscribeView(BaseNewsletterListFormView):
#     template_name = "courriers/newsletter_list_unsubscribe.html"
# 
#     def get_form_class(self):
#         return UnsubscribeForm
# 
#     def get_initial(self):
#         initial = super(NewsletterListUnsubscribeView, self).get_initial()
#         email = self.request.GET.get("email", None)
# 
#         if email:
#             initial["email"] = email
# 
#         return initial.copy()
# 
#     def get_success_url(self):
#         if self.object:
#             return reverse(
#                 "newsletter_list_unsubscribe_done", kwargs={"slug": self.object.slug}
#             )
# 
#         return reverse("newsletter_list_unsubscribe_done")
# 
# class NewsletterListSubscribeDoneView(AJAXResponseMixin, TemplateView):
#     template_name = "courriers/newsletter_list_subscribe_done.html"
#     model = NewsletterList
#     context_object_name = "newsletter_list"
# 
# class NewsletterListUnsubscribeDoneView(AJAXResponseMixin, TemplateView):
#     template_name = "courriers/newsletter_list_unsubscribe_done.html"
#     model = NewsletterList
#     context_object_name = "newsletter_list"
# 
#     def get_context_data(self, **kwargs):
#         context = super(NewsletterListUnsubscribeDoneView, self).get_context_data(
#             **kwargs
#         )
# 
#         slug = self.kwargs.get("slug", None)
# 
#         if slug:
#             context[self.context_object_name] = get_object_or_404(self.model, slug=slug)
# 
#         return context


from django.conf.urls import url
from .views import (
    NewsletterListView,
    NewsletterDetailView,
    NewsletterListSubscribeView,
    NewsletterRawDetailView,
    NewsletterListUnsubscribeView,
    NewsletterListSubscribeDoneView,
    NewsletterListUnsubscribeDoneView,
)



urlpatterns = [
    url(
        r"^(?P<pk>(\d+))/detail/$",
        NewsletterDetailView.as_view(),
        name="newsletter_detail",
    ),
    url(
        r"^(?P<slug>(\w+))/subscribe/$",
        NewsletterListSubscribeView.as_view(),
        name="newsletter_list_subscribe",
    ),
    url(
        r"^(?P<pk>(\d+))/raw/$",
        NewsletterRawDetailView.as_view(),
        name="newsletter_raw_detail",
    ),
    url(
        r"^(?:(?P<slug>(\w+))/)?unsubscribe/$",

# Path: courriers/views.py
# class NewsletterListView(AJAXResponseMixin, ListView):
#     model = Newsletter
#     context_object_name = "newsletters"
#     template_name = "courriers/newsletter_list.html"
#     paginate_by = PAGINATE_BY
# 
#     def dispatch(self, *args, **kwargs):
#         return super(NewsletterListView, self).dispatch(*args, **kwargs)
# 
#     @cached_property
#     def newsletter_list(self):
#         return get_object_or_404(
#             NewsletterList.objects.all(), slug=self.kwargs.get("slug")
#         )
# 
#     def get_queryset(self):
#         lang = translation.get_language()
#         qs = self.newsletter_list.newsletters.status_online()
#         if lang:
#             qs = qs.filter(newsletter_segment__lang=lang)
#         qs = qs.order_by("-published_at")
#         return qs
# 
#     def get_context_data(self, **kwargs):
#         context = super(NewsletterListView, self).get_context_data(**kwargs)
#         context["newsletter_list"] = self.newsletter_list
#         return context
# 
# class NewsletterDetailView(AJAXResponseMixin, DetailView):
#     model = Newsletter
#     context_object_name = "newsletter"
#     template_name = "courriers/newsletter_detail.html"
# 
#     def get_queryset(self):
#         return self.model.objects.status_online()
# 
#     def get_context_data(self, **kwargs):
#         context = super(NewsletterDetailView, self).get_context_data(**kwargs)
# 
#         context["newsletter_list"] = self.object.newsletter_list
# 
#         return context
# 
# class NewsletterListSubscribeView(BaseNewsletterListFormView):
#     template_name = "courriers/newsletter_list_subscribe_form.html"
#     form_class = SubscriptionForm
# 
#     def get_success_url(self):
#         return reverse("newsletter_list_subscribe_done")
# 
# class NewsletterRawDetailView(AJAXResponseMixin, DetailView):
#     model = Newsletter
#     template_name = "courriers/newsletter_raw_detail.html"
# 
#     def get_context_data(self, **kwargs):
#         context = super(NewsletterRawDetailView, self).get_context_data(**kwargs)
# 
#         context["items"] = self.object.items.all()
# 
#         for item in context["items"]:
#             item.newsletter = self.object
# 
#         return context
# 
# class NewsletterListUnsubscribeView(BaseNewsletterListFormView):
#     template_name = "courriers/newsletter_list_unsubscribe.html"
# 
#     def get_form_class(self):
#         return UnsubscribeForm
# 
#     def get_initial(self):
#         initial = super(NewsletterListUnsubscribeView, self).get_initial()
#         email = self.request.GET.get("email", None)
# 
#         if email:
#             initial["email"] = email
# 
#         return initial.copy()
# 
#     def get_success_url(self):
#         if self.object:
#             return reverse(
#                 "newsletter_list_unsubscribe_done", kwargs={"slug": self.object.slug}
#             )
# 
#         return reverse("newsletter_list_unsubscribe_done")
# 
# class NewsletterListSubscribeDoneView(AJAXResponseMixin, TemplateView):
#     template_name = "courriers/newsletter_list_subscribe_done.html"
#     model = NewsletterList
#     context_object_name = "newsletter_list"
# 
# class NewsletterListUnsubscribeDoneView(AJAXResponseMixin, TemplateView):
#     template_name = "courriers/newsletter_list_unsubscribe_done.html"
#     model = NewsletterList
#     context_object_name = "newsletter_list"
# 
#     def get_context_data(self, **kwargs):
#         context = super(NewsletterListUnsubscribeDoneView, self).get_context_data(
#             **kwargs
#         )
# 
#         slug = self.kwargs.get("slug", None)
# 
#         if slug:
#             context[self.context_object_name] = get_object_or_404(self.model, slug=slug)
# 
#         return context


# Path: courriers/urls.py
from django.conf.urls import url
from .views import (
    NewsletterListView,
    NewsletterDetailView,
    NewsletterListSubscribeView,
    NewsletterRawDetailView,
    NewsletterListUnsubscribeView,
    NewsletterListSubscribeDoneView,
    NewsletterListUnsubscribeDoneView,
)




urlpatterns = [
    url(
        r"^(?P<pk>(\d+))/detail/$",
        NewsletterDetailView.as_view(),
        name="newsletter_detail",
    ),
    url(
        r"^(?P<slug>(\w+))/subscribe/$",
        NewsletterListSubscribeView.as_view(),
        name="newsletter_list_subscribe",
    ),
    url(
        r"^(?P<pk>(\d+))/raw/$",
        NewsletterRawDetailView.as_view(),
        name="newsletter_raw_detail",
    ),
    url(
        r"^(?:(?P<slug>(\w+))/)?unsubscribe/$",

        NewsletterListUnsubscribeView.as_view(),