from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.views.generic import TemplateView, FormView, CreateView, ListView
from preinfo.forms import PreinfoBaseForm, PreinfoCreateForm, PreinfoEditForm
from preinfo.models import Preinfo

class EmployeePreinfoView(LoginRequiredMixin, UserPassesTestMixin, ListView):
    model = Preinfo
    template_name = 'employee/preinfo-list.html'
    context_object_name = 'objects'
    paginate_by = 30
    form_class = PreinfoEditForm
    base_template = 'employee-base.html'

    def test_func(self):
        return True # self.request.user.has_employee_perm('can_view_preinfo') or self.request.user.user_type == 'CA'

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['base_template'] = self.base_template
        return context