-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10181 from archesproject/10176-default-value-file…
…-list Add `defaultValue` to file-widget default config
- Loading branch information
Showing
2 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
arches/app/models/migrations/10150_add_default_value_file_list.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Generated by Django 4.2.4 on 2023-10-23 13:50 | ||
|
||
from django.db import migrations | ||
|
||
from arches.app.models.graph import Graph | ||
|
||
|
||
def using_custom_file_widgets(apps, schema_editor): | ||
CardXNodeXWidget = apps.get_model("models", "CardXNodeXWidget") | ||
return ( | ||
CardXNodeXWidget.objects.filter(widget_id="10000000-0000-0000-0000-000000000019").values_list("node__graph", flat=True).distinct() | ||
) | ||
|
||
|
||
def publish_graph(apps, schema_editor): | ||
for graph in Graph.objects.filter(pk__in=using_custom_file_widgets(apps, schema_editor)): | ||
graph.publish(user=None) | ||
|
||
|
||
def unpublish_graph(apps, schema_editor): | ||
for graph in Graph.objects.filter(pk__in=using_custom_file_widgets(apps, schema_editor)): | ||
graph.unpublish() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("models", "10149_add_workflow_name_to_workflow_history"), | ||
] | ||
|
||
operations = [ | ||
# Changes to cards_x_nodes_x_widgets have no effect without republishing graph. | ||
migrations.RunPython(unpublish_graph, publish_graph), | ||
migrations.RunSQL( | ||
sql=""" | ||
UPDATE widgets | ||
SET defaultconfig = jsonb_set(defaultconfig, '{defaultValue}', '[]') | ||
WHERE name = 'file-widget'; | ||
UPDATE cards_x_nodes_x_widgets | ||
SET config = jsonb_set(config, '{defaultValue}', '[]') | ||
WHERE widgetid = '10000000-0000-0000-0000-000000000019'; | ||
""", | ||
reverse_sql=""" | ||
UPDATE widgets | ||
SET defaultconfig = defaultconfig - 'defaultValue' | ||
WHERE name = 'file-widget'; | ||
UPDATE cards_x_nodes_x_widgets | ||
SET config = config - 'defaultValue' | ||
WHERE widgetid = '10000000-0000-0000-0000-000000000019'; | ||
""", | ||
), | ||
migrations.RunPython(publish_graph, unpublish_graph), | ||
] |