# Path: main/views.py
# class LoginRequiredMixin(object):
#     @method_decorator(login_required)
#     def dispatch(self, request, *args, **kwargs):
#         return super(LoginRequiredMixin, self).dispatch(request, *args, **kwargs)
# 
# Path: channels/forms.py
# class ChannelForm(ModelForm):
# 
#     class Meta:
#         model = Channel
#         fields = ["name"]


from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from models import Channel
from django.db import IntegrityError
from django.core.urlresolvers import reverse
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseBadRequest
from django.views.generic import TemplateView, CreateView, DetailView
from main.views import LoginRequiredMixin
from channels.forms import ChannelForm


class ChannelDetailView(DetailView):
    #A view for when users look for a single Channel
    model = Channel #Tells the DetailView to use the Channel model
    template_name = "view_channel.html" 
    context_object = "channel" #Sets the name in the template context

    #Sets the field to use for lookups; in this case the name field
    slug_field = "name"


class ChannelListView(LoginRequiredMixin, TemplateView):
    #A view for when users look at all channels
    template_name = "channels.html"



# Path: main/views.py
# class LoginRequiredMixin(object):
#     @method_decorator(login_required)
#     def dispatch(self, request, *args, **kwargs):
#         return super(LoginRequiredMixin, self).dispatch(request, *args, **kwargs)
# 
# Path: channels/forms.py
# class ChannelForm(ModelForm):
# 
#     class Meta:
#         model = Channel
#         fields = ["name"]


# Path: channels/views.py
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from models import Channel
from django.db import IntegrityError
from django.core.urlresolvers import reverse
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseBadRequest
from django.views.generic import TemplateView, CreateView, DetailView
from main.views import LoginRequiredMixin
from channels.forms import ChannelForm



class ChannelDetailView(DetailView):
    #A view for when users look for a single Channel
    model = Channel #Tells the DetailView to use the Channel model
    template_name = "view_channel.html" 
    context_object = "channel" #Sets the name in the template context

    #Sets the field to use for lookups; in this case the name field
    slug_field = "name"


class ChannelListView(LoginRequiredMixin, TemplateView):
    #A view for when users look at all channels
    template_name = "channels.html"



class ChannelCreateView(LoginRequiredMixin, CreateView):