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