# generated by appcreator
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.urls import reverse, reverse_lazy
from django.views.generic.detail import DetailView
from django.views.generic.edit import DeleteView
from . filters import *
from . forms import *
from . tables import *
from . models import (
    FcCollection,
    FcResource
)
from browsing.browsing_utils import (
    GenericListView, BaseCreateView, BaseUpdateView, BaseDetailView
)


class FcCollectionListView(GenericListView):

    model = FcCollection
    filter_class = FcCollectionListFilter
    formhelper_class = FcCollectionFilterFormHelper
    table_class = FcCollectionTable
    init_columns = [
        'id',
        'fc_name',
    ]
    enable_merge = True


class FcCollectionDetailView(BaseDetailView):

    model = FcCollection
    template_name = 'filechecker/fc_collection_detail.html'


class FcCollectionCreate(BaseCreateView):

    model = FcCollection
    form_class = FcCollectionForm

    @method_decorator(login_required)
    def dispatch(self, *args, **kwargs):
        return super(FcCollectionCreate, self).dispatch(*args, **kwargs)


class FcCollectionUpdate(BaseUpdateView):

    model = FcCollection
    form_class = FcCollectionForm

    @method_decorator(login_required)
    def dispatch(self, *args, **kwargs):
        return super(FcCollectionUpdate, self).dispatch(*args, **kwargs)


class FcCollectionDelete(DeleteView):
    model = FcCollection
    template_name = 'webpage/confirm_delete.html'
    success_url = reverse_lazy('filechecker:fccollection_browse')

    @method_decorator(login_required)
    def dispatch(self, *args, **kwargs):
        return super(FcCollectionDelete, self).dispatch(*args, **kwargs)


class FcResourceListView(GenericListView):

    model = FcResource
    filter_class = FcResourceListFilter
    formhelper_class = FcResourceFilterFormHelper
    table_class = FcResourceTable
    init_columns = [
        'id',
        'fc_filename',
    ]
    enable_merge = True


class FcResourceDetailView(BaseDetailView):

    model = FcResource
    template_name = 'filechecker/fc_resource_detail.html'


class FcResourceCreate(BaseCreateView):

    model = FcResource
    form_class = FcResourceForm

    @method_decorator(login_required)
    def dispatch(self, *args, **kwargs):
        return super(FcResourceCreate, self).dispatch(*args, **kwargs)


class FcResourceUpdate(BaseUpdateView):

    model = FcResource
    form_class = FcResourceForm

    @method_decorator(login_required)
    def dispatch(self, *args, **kwargs):
        return super(FcResourceUpdate, self).dispatch(*args, **kwargs)


class FcResourceDelete(DeleteView):
    model = FcResource
    template_name = 'webpage/confirm_delete.html'
    success_url = reverse_lazy('filechecker:fcresource_browse')

    @method_decorator(login_required)
    def dispatch(self, *args, **kwargs):
        return super(FcResourceDelete, self).dispatch(*args, **kwargs)
