-
Notifications
You must be signed in to change notification settings - Fork 1
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 #701 from basedosdados/feat/observation_level_order
feat: observation_level.order
- Loading branch information
Showing
10 changed files
with
288 additions
and
28 deletions.
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
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
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
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,8 @@ | ||
from django import forms | ||
|
||
class ReorderObservationLevelsForm(forms.Form): | ||
ordered_entities = forms.CharField( | ||
required=False, | ||
widget=forms.Textarea(attrs={"rows": 10, "cols": 40}), | ||
help_text="Enter entity names one per line in desired order", | ||
) |
18 changes: 18 additions & 0 deletions
18
backend/apps/api/v1/migrations/0046_observationlevel_order.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,18 @@ | ||
# -*- coding: utf-8 -*- | ||
from django.db import migrations, models | ||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("v1", "0045_add_measurement_categories_and_units"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="observationlevel", | ||
name="order", | ||
field=models.PositiveIntegerField( | ||
db_index=True, default=0, editable=False, verbose_name="order" | ||
), | ||
preserve_default=False, | ||
), | ||
] |
42 changes: 42 additions & 0 deletions
42
backend/apps/api/v1/migrations/0047_initialize_observation_level_order.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,42 @@ | ||
from django.db import migrations | ||
|
||
def initialize_observation_level_order(apps, schema_editor): | ||
ObservationLevel = apps.get_model('v1', 'ObservationLevel') | ||
|
||
# Group by each possible parent type and set order | ||
for table_id in ObservationLevel.objects.values_list('table_id', flat=True).distinct(): | ||
if table_id: | ||
for i, ol in enumerate(ObservationLevel.objects.filter(table_id=table_id)): | ||
ol.order = i | ||
ol.save() | ||
|
||
for rds_id in ObservationLevel.objects.values_list('raw_data_source_id', flat=True).distinct(): | ||
if rds_id: | ||
for i, ol in enumerate(ObservationLevel.objects.filter(raw_data_source_id=rds_id)): | ||
ol.order = i | ||
ol.save() | ||
|
||
for ir_id in ObservationLevel.objects.values_list('information_request_id', flat=True).distinct(): | ||
if ir_id: | ||
for i, ol in enumerate(ObservationLevel.objects.filter(information_request_id=ir_id)): | ||
ol.order = i | ||
ol.save() | ||
|
||
for analysis_id in ObservationLevel.objects.values_list('analysis_id', flat=True).distinct(): | ||
if analysis_id: | ||
for i, ol in enumerate(ObservationLevel.objects.filter(analysis_id=analysis_id)): | ||
ol.order = i | ||
ol.save() | ||
|
||
def reverse_migration(apps, schema_editor): | ||
ObservationLevel = apps.get_model('v1', 'ObservationLevel') | ||
ObservationLevel.objects.all().update(order=0) | ||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
('v1', '0046_observationlevel_order'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(initialize_observation_level_order, reverse_migration), | ||
] |
20 changes: 20 additions & 0 deletions
20
backend/apps/api/v1/migrations/0048_alter_observationlevel_options_and_more.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,20 @@ | ||
# Generated by Django 4.2.16 on 2024-11-04 03:54 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('v1', '0047_initialize_observation_level_order'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterModelOptions( | ||
name='observationlevel', | ||
options={'ordering': ['order'], 'verbose_name': 'Observation Level', 'verbose_name_plural': 'Observation Levels'}, | ||
), | ||
] |
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
Oops, something went wrong.