Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: split tables by default #371

Merged
merged 2 commits into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions core/migrations/0043_alter_table_split.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.3 on 2021-09-23 09:44

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("core", "0042_alter_url_author"),
]

operations = [
migrations.AlterField(
model_name="table",
name="split",
field=models.BooleanField(default=True),
),
]
18 changes: 18 additions & 0 deletions core/migrations/0043_table_parent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.3 on 2021-09-24 10:23

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("core", "0042_alter_url_author"),
]

operations = [
migrations.AddField(
model_name="table",
name="parent",
field=models.CharField(blank=True, max_length=120, null=True),
),
]
3 changes: 2 additions & 1 deletion core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,12 @@ def __str__(self):
class Table(models.Model):
id = models.UUIDField(primary_key=True, editable=False, default=uuid.uuid4)
name = models.CharField(max_length=120)
split = models.BooleanField(default=False)
split = models.BooleanField(default=True)
include = models.BooleanField(default=True)
heading = models.CharField(max_length=31, blank=True, null=True)
array_tables = models.ManyToManyField("self", blank=True)
column_headings = models.JSONField(default=dict, encoder=DjangoJSONEncoder, blank=True, null=True)
parent = models.CharField(max_length=120, blank=True, null=True)

def __str__(self):
return f"{self.__class__.__name__} {self.id}"
Expand Down
4 changes: 2 additions & 2 deletions core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class ArrayTablesSerializer(serializers.ModelSerializer):
class Meta:
model = Table
fields = ("id", "name", "include", "heading")
fields = ("id", "name", "include", "heading", "parent")


class DataFileSerializer(serializers.ModelSerializer):
Expand All @@ -27,7 +27,7 @@ class TablesSerializer(serializers.ModelSerializer):
class Meta:
model = Table
read_only_fields = ("array_tables",)
fields = ("id", "name", "split", "array_tables", "include", "heading")
fields = ("id", "name", "split", "array_tables", "include", "heading", "parent")


class FlattenSerializer(serializers.ModelSerializer):
Expand Down
2 changes: 1 addition & 1 deletion core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def get_options_for_table(selections, exclude_tables_list, selection, tables, pa
selections[table.name]["only"] = only
if "repeat" in lite_table_config:
selections[table.name]["repeat"] = lite_table_config["repeat"]
if table.split:
if table.split and selection.kind != selection.OCDS_LITE:
get_options_for_table(selections, exclude_tables_list, selection, table.array_tables, table, analyzed_data)


Expand Down
4 changes: 3 additions & 1 deletion core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,9 @@ def _split_table(self, table, analyzed_tables, datasource, child_tables):
},
)
continue
child_table = Table.objects.create(name=child_table_key)
child_table = Table.objects.create(
name=child_table_key, parent=analyzed_tables[child_table_key].parent.name
)
table.array_tables.add(child_table)
preview_path = f"{datasource_dir}/{child_table_key}_combined.csv"
store_preview_csv(COLUMNS, PREVIEW_ROWS, analyzed_tables[child_table_key], preview_path)
Expand Down