<filename>apps/entity/views/company/listing.py
"""
Lists all companies, or filters/searches and lists the resulting companies.
"""

from django.core.paginator import Paginator
from django.shortcuts import render
from django.views import View

from apps.entity.models.company import Company
from apps.user.models import Consultant
from apps.entity.models import Member
from apps.entity.filters import CompanyFilter


class Listing(View):
    """
    Lists all companies
    """

    def get(self, request):

        try:
            search_term = request.GET.get('search')

            # get all results from companies & consultants
            companies = Company.search_companies(search_term)

        except KeyError:
            # get all companies and consultants
            companies = Company.search_companies(None)

        company_filter = CompanyFilter(request.GET, queryset=companies)
        results = company_filter.qs

        paginator = Paginator(results, 8)
        page = request.GET.get('page')
        show_businesses = paginator.get_page(page)

        return render(request, 'companies.html', {
            'company': Member.get_user_company(request.user),
            'show_sidepane': True,
            'companies': show_businesses,
            'page': page,
            'filter': company_filter,
        })

<filename>apps/entity/views/company/listing.py
"""
Lists all companies, or filters/searches and lists the resulting companies.
"""

from django.core.paginator import Paginator
from django.shortcuts import render
from django.views import View

from apps.entity.models.company import Company
from apps.user.models import Consultant
from apps.entity.models import Member
from apps.entity.filters import CompanyFilter


class Listing(View):
    """
    Lists all companies
    """

    def get(self, request):

        try:
            search_term = request.GET.get('search')

            # get all results from companies & consultants
            companies = Company.search_companies(search_term)

        except KeyError:
            # get all companies and consultants
            companies = Company.search_companies(None)

        company_filter = CompanyFilter(request.GET, queryset=companies)
        results = company_filter.qs

        paginator = Paginator(results, 8)
        page = request.GET.get('page')
        show_businesses = paginator.get_page(page)

        return render(request, 'companies.html', {
            'company': Member.get_user_company(request.user),
            'show_sidepane': True,
            'companies': show_businesses,
            'page': page,
            'filter': company_filter,
        })

Lists all companies, or filters/searches and lists the resulting companies. Lists all companies # get all results from companies & consultants # get all companies and consultants