from django.views.generic import TemplateView
from django.contrib import messages
from django.utils.decorators import method_decorator
from django.utils.html import escape
from django.db.models import Q
from django.urls import reverse
from django.shortcuts import render, redirect, get_object_or_404
from django.http import HttpResponseForbidden

from django_datatables_view.base_datatable_view import BaseDatatableView

from memorial_park_mgmnt_app import models, forms
from utils import utils


@method_decorator(utils.branch_required(utils.is_auth_and_has_branch),
                  name='dispatch')
class ContractListView(TemplateView):
    template_name = 'contract/list.html'

    def get(self, request):
        return render(request, self.template_name)


@method_decorator(utils.branch_required(utils.is_auth_and_has_branch),
                  name='dispatch')
class ContractJson(BaseDatatableView):
    model = models.Contract
    columns = ['number', 'date', 'name', 'lot']
    order_columns = [
        'number', 'date', ['client__last_name', 'client__first_name'],
from django.views.generic import TemplateView
from django.contrib import messages
from django.utils.decorators import method_decorator
from django.db.models import Q
from django.urls import reverse
from django.shortcuts import render, redirect, get_object_or_404
from django.http import HttpResponseForbidden

from django_datatables_view.base_datatable_view import BaseDatatableView

from memorial_park_mgmnt_app import models, forms
from utils import utils


@method_decorator(utils.branch_required(utils.is_auth_and_has_branch), name='dispatch')
class AgentListView(TemplateView):
    template_name = 'agent/list.html'

    def get(self, request):
        return render(request, self.template_name)


@method_decorator(utils.branch_required(utils.is_auth_and_has_branch), name='dispatch')
class AgentJson(BaseDatatableView):
    model = models.Agent
    columns = ['name', 'main_address', 'contact_number']
    order_columns = [['last_name', 'first_name', 'middle_name'], None, '']

    def get_initial_queryset(self):
        return models.Agent.objects.all()