Skip to content

Commit

Permalink
Merge pull request #705 from basedosdados/feat/closed_resources
Browse files Browse the repository at this point in the history
feat: contains closed resources
  • Loading branch information
rdahis authored Nov 25, 2024
2 parents 5b67528 + 6ab795b commit 5335bd1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions backend/apps/api/v1/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ class DatasetAdmin(OrderedInlineModelAdminMixin, TabbedTranslationAdmin):
"contains_tables",
"contains_raw_data_sources",
"contains_information_requests",
"contains_closed_data",
"page_views",
"created_at",
"updated_at",
Expand Down
17 changes: 17 additions & 0 deletions backend/apps/api/v1/migrations/0052_remove_dataset_is_closed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.16 on 2024-11-07 12:24

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('v1', '0051_add_new_field_dataset'),
]

operations = [
migrations.RemoveField(
model_name='dataset',
name='is_closed',
),
]
13 changes: 9 additions & 4 deletions backend/apps/api/v1/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,9 +538,6 @@ class Dataset(BaseModel):
)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
is_closed = models.BooleanField(
default=False, help_text="Dataset is for BD Pro subscribers only"
)
page_views = models.BigIntegerField(
default=0,
help_text="Number of page views by Google Analytics",
Expand Down Expand Up @@ -659,18 +656,26 @@ def contains_open_data(self):

@property
def contains_closed_data(self):
"""Returns true if there are tables or columns with closed coverages"""
"""Returns true if there are tables or columns with closed coverages, or if the uncompressed file size is above 1 GB"""
closed_data = False
tables = self.tables.all()
for table in tables:
# Check for closed coverages
table_coverages = table.coverages.filter(is_closed=True)
if table_coverages:
closed_data = True
break

# Check for closed columns
for column in table.columns.all():
if column.is_closed: # in the future it will be column.coverages
closed_data = True
break

# Check if uncompressed file size is above 1 GB
if table.uncompressed_file_size and table.uncompressed_file_size > 1000000000:
closed_data = True
break

return closed_data

Expand Down

0 comments on commit 5335bd1

Please sign in to comment.