From 0c49be210568030b8272a7dae83bcefc6ab05df0 Mon Sep 17 00:00:00 2001 From: Sesostris Vieira Date: Wed, 24 Jul 2024 09:15:48 -0300 Subject: [PATCH] =?UTF-8?q?Corre=C3=A7=C3=A3o=20de=20bugs.=20Gertiq=20#191?= =?UTF-8?q?173?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sigi/apps/home/views.py | 12 ++++++------ sigi/apps/utils/templatetags/sigi_tags.py | 20 ++++++++++++-------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/sigi/apps/home/views.py b/sigi/apps/home/views.py index e50eab1..db36011 100644 --- a/sigi/apps/home/views.py +++ b/sigi/apps/home/views.py @@ -119,6 +119,7 @@ class HomeView(LoginRequiredMixin, TemplateView): template_name = "home/public_site/index.html" def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) user = self.request.user casa_id = self.request.GET.get( "id", self.request.session.get("casa_id", None) @@ -136,18 +137,17 @@ class HomeView(LoginRequiredMixin, TemplateView): casa = None if casa: self.request.session["casa_id"] = casa.id - ocorrencias = casa.ocorrencia_set.filter( + context["ocorrencias"] = casa.ocorrencia_set.filter( status__in=[ Ocorrencia.STATUS_ABERTO, Ocorrencia.STATUS_REABERTO, ] + )[:5] + context["servicos"] = casa.servico_set.filter( + data_desativacao=None ) - servicos = casa.servico_set.filter(data_desativacao=None) - context = super().get_context_data(**kwargs) context["casas"] = casas.values() context["casa"] = casa - context["ocorrencias"] = ocorrencias[:5] - context["servicos"] = servicos return context @@ -1253,7 +1253,7 @@ def busca_informacoes_camara(tipos=["CM"], label_tipo=_("Câmaras Municipais")): df = ( pd.DataFrame.from_dict(dataset, orient="index") - .replace(np.NaN, 0) + .replace(np.nan, 0) .convert_dtypes() ) diff --git a/sigi/apps/utils/templatetags/sigi_tags.py b/sigi/apps/utils/templatetags/sigi_tags.py index 5bdb000..95b1c07 100644 --- a/sigi/apps/utils/templatetags/sigi_tags.py +++ b/sigi/apps/utils/templatetags/sigi_tags.py @@ -40,14 +40,18 @@ def multiply(value, arg): @register.filter def valueof(obj, attr_name): - if hasattr(obj, attr_name): - return getattr(obj, attr_name) - if attr_name in obj: - return obj[attr_name] - if isinstance(obj, models.Model): - for part in attr_name.split("__"): - obj = getattr(obj, part) - return str(obj) + try: + if hasattr(obj, attr_name): + return getattr(obj, attr_name) + if isinstance(obj, models.Model): + for part in attr_name.split("__"): + obj = getattr(obj, part) + return str(obj) + if attr_name in obj: + return obj[attr_name] + except: + pass + return None @register.filter