|
| 1 | +from django.db import migrations |
| 2 | + |
| 3 | + |
| 4 | +USER_WIDGET_ID = "d3a09f3e-5b1c-4a2d-8e6f-7c9b0a1d2e3f" |
| 5 | + |
| 6 | + |
| 7 | +class Migration(migrations.Migration): |
| 8 | + |
| 9 | + dependencies = [ |
| 10 | + ("models", "12586_tile_cardinality_check"), |
| 11 | + ] |
| 12 | + |
| 13 | + def forward(apps, schema_editor): |
| 14 | + DDataType = apps.get_model("models", "DDataType") |
| 15 | + Widget = apps.get_model("models", "Widget") |
| 16 | + |
| 17 | + widget = Widget( |
| 18 | + widgetid=USER_WIDGET_ID, |
| 19 | + name="external-domain", |
| 20 | + component="views/components/widgets/external-domain", |
| 21 | + helptext=None, |
| 22 | + datatype="auth-user", |
| 23 | + defaultconfig={ |
| 24 | + "defaultValue": None, |
| 25 | + "i18n_properties": ["placeholder"], |
| 26 | + "placeholder": "Select a user", |
| 27 | + "width": "100%", |
| 28 | + "uneditable": False, |
| 29 | + }, |
| 30 | + ) |
| 31 | + datatype = DDataType( |
| 32 | + datatype="auth-user", |
| 33 | + iconclass="fa fa-user", |
| 34 | + # UserDataType lives in arches/app/datatypes/core/user.py. |
| 35 | + # The module importer resolves "core.user.py" → |
| 36 | + # arches.app.datatypes.core.user when searching the datatypes dir. |
| 37 | + modulename="core.user.py", |
| 38 | + classname="UserDataType", |
| 39 | + defaultconfig=None, |
| 40 | + configcomponent="views/components/datatypes/external-domain", |
| 41 | + configname="external-domain-datatype-config", |
| 42 | + isgeometric=False, |
| 43 | + defaultwidget=widget, |
| 44 | + issearchable=True, |
| 45 | + ) |
| 46 | + widget.save() |
| 47 | + datatype.save() |
| 48 | + |
| 49 | + def reverse(apps, schema_editor): |
| 50 | + DDataType = apps.get_model("models", "DDataType") |
| 51 | + Widget = apps.get_model("models", "Widget") |
| 52 | + DDataType.objects.filter(datatype="auth-user").delete() |
| 53 | + Widget.objects.filter(widgetid=USER_WIDGET_ID).delete() |
| 54 | + |
| 55 | + operations = [ |
| 56 | + migrations.RunPython(forward, reverse), |
| 57 | + ] |
0 commit comments