Exemplo n.º 1
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)

        context["current_kind"] = self.request.GET.get("kind")

        if not self.request.GET.get("q"):
            context["current_kind"] = context["current_kind"] or KIND.default()

        ngo = kwargs.get("ngo", context.get("ngo"))
        if not ngo:
            return context

        needs = ngo.needs.filter(resolved_on=None)
        if "need" in kwargs:
            needs = needs.exclude(pk=kwargs["need"].pk)
            context["current_need"] = kwargs["need"]

        for kind in KIND.to_list():
            kind_needs = needs.filter(kind=kind)
            needs_paginator = paginator.Paginator(kind_needs, NEEDS_PER_PAGE)
            page = self.request.GET.get(f"{kind}_page")

            # Catch invalid page numbers
            try:
                needs_page_obj = needs_paginator.page(page)
            except (paginator.PageNotAnInteger, paginator.EmptyPage):
                needs_page_obj = needs_paginator.page(1)

            context[f"{kind}_page_obj"] = needs_page_obj

        return context
Exemplo n.º 2
0
    def get_needs(self):
        filters = {
            "resolved_on": None,
        }

        kind = self.request.GET.get("kind")
        if not self.request.GET.get("q"):
            kind = kind or KIND.default()

        if kind:
            filters["kind"] = kind

        return NGONeed.objects.filter(**filters).order_by("created")
Exemplo n.º 3
0
    def get_needs(self):
        if hasattr(self, "needs"):
            return self.needs

        filters = {
            "resolved_on": None,
        }

        kind = self.request.GET.get("kind")
        if not self.request.GET.get("q"):
            kind = kind or KIND.default()

        if kind:
            filters["kind"] = kind

        self.needs = (NGONeed.objects.filter(**filters).order_by("ngo__name").
                      select_related("ngo").prefetch_related("resource_tags"))

        return self.needs
Exemplo n.º 4
0
    def get_needs(self):
        if hasattr(self, "needs"):
            return self.needs

        filters = {
            "resolved_on": None,
        }

        kind = self.request.GET.get("kind")
        if not self.request.GET.get("q"):
            kind = kind or KIND.default()

        if kind:
            filters["kind"] = kind

        self.needs = (NGONeed.objects.filter(**filters).order_by("ngo__name").
                      select_related("ngo").prefetch_related("resource_tags"))

        if kind and kind == KIND.MONEY:
            self.needs = self.needs.exclude(ngo__name=settings.RED_CROSS_NAME,
                                            kind=KIND.MONEY)

        return self.needs