Skip to content

Commit dcbc1df

Browse files
authored
Merge pull request #725 from basedosdados/fix/hide_dict_count
fix: better counting without under_review and dictionaries
2 parents 14b969e + 671d21a commit dcbc1df

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

backend/apps/api/v1/models.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ def entities(self) -> list[dict]:
652652
def contains_open_data(self):
653653
"""Returns true if there are tables or columns with open coverages"""
654654
open_data = False
655-
tables = self.tables.all()
655+
tables = self.tables.exclude(status__slug="under_review").exclude(slug="dicionario").exclude(slug="dictionary").all()
656656
for table in tables:
657657
table_coverages = table.coverages.filter(is_closed=False)
658658
if table_coverages:
@@ -663,29 +663,29 @@ def contains_open_data(self):
663663
@property
664664
def contains_closed_data(self):
665665
"""Returns true if there are tables or columns with closed coverages, or if the uncompressed file size is above 1 GB"""
666-
for table in self.tables.all():
666+
for table in self.tables.exclude(status__slug="under_review").exclude(slug="dicionario").exclude(slug="dictionary").all():
667667
if table.contains_closed_data:
668668
return True
669669
return False
670670

671671
@property
672672
def contains_tables(self):
673673
"""Returns true if there are tables in the dataset"""
674-
return len(self.tables.all()) > 0
674+
return len(self.tables.exclude(status__slug="under_review").exclude(slug="dicionario").exclude(slug="dictionary").all()) > 0
675675

676676
@property
677677
def contains_raw_data_sources(self):
678678
"""Returns true if there are raw data sources in the dataset"""
679-
return len(self.raw_data_sources.all()) > 0
679+
return len(self.raw_data_sources.exclude(status__slug="under_review").all()) > 0
680680

681681
@property
682682
def contains_information_requests(self):
683683
"""Returns true if there are information requests in the dataset"""
684-
return len(self.information_requests.all()) > 0
684+
return len(self.information_requests.exclude(status__slug="under_review").all()) > 0
685685

686686
@property
687687
def n_tables(self):
688-
return len(self.tables.exclude(status__slug="under_review").all())
688+
return len(self.tables.exclude(status__slug="under_review").exclude(slug="dicionario").exclude(slug="dictionary").all())
689689

690690
@property
691691
def n_raw_data_sources(self):
@@ -697,18 +697,18 @@ def n_information_requests(self):
697697

698698
@property
699699
def first_table_id(self):
700-
if resource := self.tables.exclude(status__slug="under_review").order_by("order").first():
700+
if resource := self.tables.exclude(status__slug="under_review").exclude(slug="dicionario").exclude(slug="dictionary").order_by("order").first():
701701
return resource.pk
702702

703703
@property
704704
def first_open_table_id(self):
705-
for resource in self.tables.exclude(status__slug="under_review").order_by("order").all():
705+
for resource in self.tables.exclude(status__slug="under_review").exclude(slug="dicionario").exclude(slug="dictionary").order_by("order").all():
706706
if resource.contains_open_data:
707707
return resource.pk
708708

709709
@property
710710
def first_closed_table_id(self):
711-
for resource in self.tables.exclude(status__slug="under_review").order_by("order").all():
711+
for resource in self.tables.exclude(status__slug="under_review").exclude(slug="dicionario").exclude(slug="dictionary").order_by("order").all():
712712
if resource.contains_closed_data:
713713
return resource.pk
714714

@@ -735,23 +735,23 @@ def first_information_request_id(self):
735735
@property
736736
def table_last_updated_at(self):
737737
updates = [
738-
u.last_updated_at for u in self.tables.all()
738+
u.last_updated_at for u in self.tables.exclude(status__slug="under_review").exclude(slug="dicionario").exclude(slug="dictionary").all()
739739
if u.last_updated_at
740740
] # fmt: skip
741741
return max(updates) if updates else None
742742

743743
@property
744744
def raw_data_source_last_polled_at(self):
745745
polls = [
746-
u.last_polled_at for u in self.raw_data_sources.all()
746+
u.last_polled_at for u in self.raw_data_sources.exclude(status__slug="under_review").all()
747747
if u.last_polled_at
748748
] # fmt: skip
749749
return max(polls) if polls else None
750750

751751
@property
752752
def raw_data_source_last_updated_at(self):
753753
updates = [
754-
u.last_updated_at for u in self.raw_data_sources.all()
754+
u.last_updated_at for u in self.raw_data_sources.exclude(status__slug="under_review").all()
755755
if u.last_updated_at
756756
] # fmt: skip
757757
return max(updates) if updates else None

0 commit comments

Comments
 (0)