# Path: core/views.py
# class HomePageView(TemplateView):
# 
#     template_name = "home.html"
# 
#     def get_context_data(self, **kwargs):
#         context = super(HomePageView, self).get_context_data(**kwargs)
#         return context
# 
# class DashboardView(TemplateView):
# 
#     template_name = "dashboard.html"
# 
#     def get_context_data(self, **kwargs):
#         context = super(DashboardView, self).get_context_data(**kwargs)
# 
#         pending_reviews = Review.objects.filter(customer=self.request.user.userprofile.customer).filter(
#             Q(reviewers=self.request.user.userprofile) | Q(public=True)).exclude(
#             Q(answer__userprofile=self.request.user.userprofile) & Q(quiz__single_attempt=True)
#         )
# 
#         reports = []
#         reviews = Review.objects.filter(customer=self.request.user.userprofile.customer).filter(
#             userprofile=self.request.user.userprofile).order_by('-created_on')[:4]
#         if reviews:
#             sittings = [i.sitting for i in reviews]
#             current_sitting = max(set(sittings), key=sittings.count)
#             reviews = Review.objects.filter(customer=self.request.user.userprofile.customer).filter(
#                 userprofile=self.request.user.userprofile).filter(
#                 sitting=current_sitting).order_by('-created_on')[:3]
#             for review in reviews:
#                 report = user_review_report(review)
#                 reports.append(report)
# 
#         context['pending_reviews'] = pending_reviews
#         context['reports'] = reports
#         return context
# 
# class GenericMessageView(AdminMixin, FormView):
#     template_name = 'core/generic-message.html'
#     form_class = GenericMessage
#     success_url = '/dashboard/'
# 
#     def form_valid(self, form):
#         form.send_email(self.request.user.userprofile.customer)
#         return super(GenericMessageView, self).form_valid(form)


from django.conf.urls import include, url
from django.contrib import admin
from django.contrib.auth.decorators import login_required
from django.conf import settings
from core.views import HomePageView, DashboardView, GenericMessageView



urlpatterns = [
    url(r'^$', HomePageView.as_view(), name='home'),
    url(r'^dashboard/$', login_required(DashboardView.as_view()), name='dashboard'),
    url(r'^send-message/$', login_required(GenericMessageView.as_view()), name='generic-message'),

    url(r'^admin/', include(admin.site.urls)),
    url(r'^accounts/', include('allauth.urls')),

    url(r'^q/', include('questions.urls', namespace='questions')),
    url(r'^reviews/', include('reviews.urls', namespace='reviews')),

# Path: core/views.py
# class HomePageView(TemplateView):
# 
#     template_name = "home.html"
# 
#     def get_context_data(self, **kwargs):
#         context = super(HomePageView, self).get_context_data(**kwargs)
#         return context
# 
# class DashboardView(TemplateView):
# 
#     template_name = "dashboard.html"
# 
#     def get_context_data(self, **kwargs):
#         context = super(DashboardView, self).get_context_data(**kwargs)
# 
#         pending_reviews = Review.objects.filter(customer=self.request.user.userprofile.customer).filter(
#             Q(reviewers=self.request.user.userprofile) | Q(public=True)).exclude(
#             Q(answer__userprofile=self.request.user.userprofile) & Q(quiz__single_attempt=True)
#         )
# 
#         reports = []
#         reviews = Review.objects.filter(customer=self.request.user.userprofile.customer).filter(
#             userprofile=self.request.user.userprofile).order_by('-created_on')[:4]
#         if reviews:
#             sittings = [i.sitting for i in reviews]
#             current_sitting = max(set(sittings), key=sittings.count)
#             reviews = Review.objects.filter(customer=self.request.user.userprofile.customer).filter(
#                 userprofile=self.request.user.userprofile).filter(
#                 sitting=current_sitting).order_by('-created_on')[:3]
#             for review in reviews:
#                 report = user_review_report(review)
#                 reports.append(report)
# 
#         context['pending_reviews'] = pending_reviews
#         context['reports'] = reports
#         return context
# 
# class GenericMessageView(AdminMixin, FormView):
#     template_name = 'core/generic-message.html'
#     form_class = GenericMessage
#     success_url = '/dashboard/'
# 
#     def form_valid(self, form):
#         form.send_email(self.request.user.userprofile.customer)
#         return super(GenericMessageView, self).form_valid(form)


# Path: template/urls.py
from django.conf.urls import include, url
from django.contrib import admin
from django.contrib.auth.decorators import login_required
from django.conf import settings
from core.views import HomePageView, DashboardView, GenericMessageView




urlpatterns = [
    url(r'^$', HomePageView.as_view(), name='home'),
    url(r'^dashboard/$', login_required(DashboardView.as_view()), name='dashboard'),
    url(r'^send-message/$', login_required(GenericMessageView.as_view()), name='generic-message'),

    url(r'^admin/', include(admin.site.urls)),
    url(r'^accounts/', include('allauth.urls')),

    url(r'^q/', include('questions.urls', namespace='questions')),
    url(r'^reviews/', include('reviews.urls', namespace='reviews')),

    url(r'^reports/', include('reports.urls', namespace='reports')),