diff --git a/backend/apps/api/v1/admin.py b/backend/apps/api/v1/admin.py index 693fd77c..a440a65a 100644 --- a/backend/apps/api/v1/admin.py +++ b/backend/apps/api/v1/admin.py @@ -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", diff --git a/backend/apps/api/v1/migrations/0051_add_new_field_dataset.py b/backend/apps/api/v1/migrations/0051_add_new_field_dataset.py new file mode 100644 index 00000000..0fcd2b45 --- /dev/null +++ b/backend/apps/api/v1/migrations/0051_add_new_field_dataset.py @@ -0,0 +1,19 @@ +# Generated by Django 4.2.16 on 2024-11-13 16:59 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('v1', '0050_table_is_deprecated'), + ] + + operations = [ + migrations.AddField( + model_name='dataset', + name='usage_guide', + field=models.TextField(blank=True, null=True, default='', max_length=255 , verbose_name='Guia de Uso') + ), + ] + diff --git a/backend/apps/api/v1/migrations/0051_add_textfield_all_models.py b/backend/apps/api/v1/migrations/0051_add_textfield_all_models.py deleted file mode 100644 index 68484ac9..00000000 --- a/backend/apps/api/v1/migrations/0051_add_textfield_all_models.py +++ /dev/null @@ -1,21 +0,0 @@ -# Generated by Django 4.2.16 on 2024-11-12 15:34 - -from django.db import migrations, models - -def add_new_field_to_all_tables(apps, schema_editor): - for model in apps.get_models(): - schema_editor.add_field( - model, - name='url_links', - field=models.TextField(max_length=255, default='', blank=True) - ) - -class Migration(migrations.Migration): - - dependencies = [ - ('v1', '0050_table_is_deprecated'), - ] - - operations = [ - migrations.RunPython(add_new_field_to_all_tables), - ] diff --git a/backend/apps/api/v1/migrations/0052_remove_dataset_is_closed.py b/backend/apps/api/v1/migrations/0052_remove_dataset_is_closed.py new file mode 100644 index 00000000..e47b283f --- /dev/null +++ b/backend/apps/api/v1/migrations/0052_remove_dataset_is_closed.py @@ -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', + ), + ] diff --git a/backend/apps/api/v1/models.py b/backend/apps/api/v1/models.py index c3233ddf..01a3f0d7 100644 --- a/backend/apps/api/v1/models.py +++ b/backend/apps/api/v1/models.py @@ -538,13 +538,11 @@ 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", ) + usage_guide = models.TextField(blank=True, null=True, default='', max_length=255 , verbose_name='Guia de Uso') graphql_nested_filter_fields_whitelist = ["id", "slug"] @@ -658,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