Ejemplo n.º 1
0
    def get_context_data(self, **kwargs):

        # add pagination to context

        # call supper
        context = super().get_context_data(**kwargs)

        # query all calls
        queryset = self.get_queryset()

        # get current page
        page = self.request.GET.get('page', 1)
        page_size = self.request.GET.get('page_size', 25)
        page_sizes = [25, 50, 100]

        # paginate
        paginator = Paginator(queryset, page_size)
        try:
            page_list = paginator.page(page)
        except PageNotAnInteger:
            page_list = paginator.page(1)
        except EmptyPage:
            page_list = paginator.page(paginator.num_pages)

        context['page_list'] = page_list
        context['page_links'] = get_page_links(self.request, page_list)
        context['page_size_links'] = get_page_size_links(
            self.request, page_list, page_sizes)
        context['page_size'] = int(page_size)

        return context
Ejemplo n.º 2
0
    def get_context_data(self, **kwargs):

        # add paginated updates to context

        # call supper
        context = super().get_context_data(**kwargs)

        # query
        updates_query = self.object.ambulanceupdate_set.order_by('-timestamp')

        # get current page
        page = self.request.GET.get('page', 1)
        page_size = self.request.GET.get('page_size', 250)
        page_sizes = [250, 500, 1000]

        # paginate
        paginator = Paginator(updates_query, page_size)
        try:
            updates = paginator.page(page)
        except PageNotAnInteger:
            updates = paginator.page(1)
        except EmptyPage:
            updates = paginator.page(paginator.num_pages)

        context['updates'] = updates
        context['page_links'] = get_page_links(self.request, updates)
        context['page_size_links'] = get_page_size_links(self.request, updates, page_sizes)
        context['page_size'] = int(page_size)

        # add ambulance_status
        context['ambulance_status'] = {m.name: m.value
                                       for m in AmbulanceStatus}
        context['map_provider'] = {'provider': settings.MAP_PROVIDER, 'access_token': settings.MAP_PROVIDER_TOKEN}

        return context
Ejemplo n.º 3
0
    def get_context_data(self, **kwargs):

        # add paginated offline clients to context

        # call supper
        context = super().get_context_data(**kwargs)

        # query
        not_online_query = Client.objects.exclude(status=ClientStatus.O.name).order_by('-updated_on')

        # get current page
        page = self.request.GET.get('page', 1)
        page_size = self.request.GET.get('page_size', 25)
        page_sizes = [25, 50, 100]

        # paginate
        paginator = Paginator(not_online_query, page_size)
        try:
            not_online = paginator.page(page)
        except PageNotAnInteger:
            not_online = paginator.page(1)
        except EmptyPage:
            not_online = paginator.page(paginator.num_pages)

        context['not_online'] = not_online
        context['page_links'] = get_page_links(self.request, not_online)
        context['page_size_links'] = get_page_size_links(self.request, not_online, page_sizes)
        context['page_size'] = int(page_size)

        return context
Ejemplo n.º 4
0
    def get_context_data(self, **kwargs):

        # add paginated ended calls to context

        # call supper
        context = super().get_context_data(**kwargs)

        # query all calls
        queryset = self.get_queryset()

        # filter
        context['pending_list'] = queryset.filter(status=CallStatus.P.name).order_by('pending_at')
        context['started_list'] = queryset.filter(status=CallStatus.S.name).order_by('-started_at')

        # query ended and paginate
        ended_calls_query = queryset.filter(status=CallStatus.E.name).order_by('-ended_at')

        # get current page
        page = self.request.GET.get('page', 1)
        page_size = self.request.GET.get('page_size', 25)
        page_sizes = [25, 50, 100]

        # paginate
        paginator = Paginator(ended_calls_query, page_size)
        try:
            ended_calls = paginator.page(page)
        except PageNotAnInteger:
            ended_calls = paginator.page(1)
        except EmptyPage:
            ended_calls = paginator.page(paginator.num_pages)

        context['ended_list'] = ended_calls
        context['page_links'] = get_page_links(self.request, ended_calls)
        context['page_size_links'] = get_page_size_links(self.request, ended_calls, page_sizes)
        context['page_size'] = int(page_size)

        return context
Ejemplo n.º 5
0
    def get_context_data(self, **kwargs):

        # add paginated ended calls to context
        
        # call supper
        context = super().get_context_data(**kwargs)
        
        # query all calls
        queryset = self.get_queryset()
        
        # filter
        context['base_list'] = queryset.filter(type=LocationType.b.name).order_by('name')
        context['aed_list'] = queryset.filter(type=LocationType.a.name).order_by('name')

        # query ended and paginate
        incident_query = queryset.filter(type=LocationType.i.name).order_by('-updated_on')

        # get current page
        page = self.request.GET.get('page', 1)
        page_size = self.request.GET.get('page_size', 25)
        page_sizes = [25, 50, 100]

        # paginate
        paginator = Paginator(incident_query, page_size)
        try:
            incident = paginator.page(page)
        except PageNotAnInteger:
            incident = paginator.page(1)
        except EmptyPage:
            incident = paginator.page(paginator.num_pages)

        context['incident_list'] = incident
        context['page_links'] = get_page_links(self.request, incident)
        context['page_size_links'] = get_page_size_links(self.request, incident, page_sizes)
        context['page_size'] = int(page_size)

        return context