-
Notifications
You must be signed in to change notification settings - Fork 0
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 #1816 from laws-africa/outcome
Split order and outcome fields
- Loading branch information
Showing
15 changed files
with
260 additions
and
66 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
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,76 @@ | ||
# Generated by Django 3.2.21 on 2024-05-15 13:58 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("peachjam", "0130_backfill_citation_counts"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Outcome", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
( | ||
"name", | ||
models.CharField(max_length=1024, unique=True, verbose_name="name"), | ||
), | ||
( | ||
"name_en", | ||
models.CharField( | ||
max_length=1024, null=True, unique=True, verbose_name="name" | ||
), | ||
), | ||
( | ||
"name_fr", | ||
models.CharField( | ||
max_length=1024, null=True, unique=True, verbose_name="name" | ||
), | ||
), | ||
( | ||
"name_pt", | ||
models.CharField( | ||
max_length=1024, null=True, unique=True, verbose_name="name" | ||
), | ||
), | ||
( | ||
"name_sw", | ||
models.CharField( | ||
max_length=1024, null=True, unique=True, verbose_name="name" | ||
), | ||
), | ||
( | ||
"description", | ||
models.TextField(blank=True, verbose_name="description"), | ||
), | ||
], | ||
options={ | ||
"verbose_name": "outcome", | ||
"verbose_name_plural": "outcomes", | ||
"ordering": ["name"], | ||
}, | ||
), | ||
migrations.AddField( | ||
model_name="judgment", | ||
name="order", | ||
field=models.TextField(blank=True, null=True, verbose_name="order"), | ||
), | ||
migrations.AddField( | ||
model_name="judgment", | ||
name="outcomes", | ||
field=models.ManyToManyField( | ||
blank=True, related_name="judgments", to="peachjam.Outcome" | ||
), | ||
), | ||
] |
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,38 @@ | ||
# Generated by Django 3.2.21 on 2024-05-15 13:59 | ||
|
||
import os | ||
|
||
from django.db import migrations | ||
|
||
|
||
def forwards(apps, schema_editor): | ||
from django.conf import settings | ||
from django_elasticsearch_dsl.registries import registry | ||
|
||
if not settings.DEBUG and os.environ.get("ELASTICSEARCH_HOST"): | ||
for ix in registry.get_indices(): | ||
if not ix._mapping: | ||
continue | ||
print(f"Adding outcome mapping for {ix._name}") | ||
ix.connection.indices.put_mapping( | ||
index=ix._name, | ||
body={ | ||
"properties": { | ||
"outcome": ix._mapping["outcome"].to_dict(), | ||
"outcome_en": ix._mapping["outcome_en"].to_dict(), | ||
"outcome_sw": ix._mapping["outcome_sw"].to_dict(), | ||
"outcome_fr": ix._mapping["outcome_fr"].to_dict(), | ||
"outcome_pt": ix._mapping["outcome_pt"].to_dict(), | ||
"order": ix._mapping["order"].to_dict(), | ||
} | ||
}, | ||
) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("peachjam", "0131_rename_order_outcome"), | ||
] | ||
|
||
operations = [migrations.RunPython(forwards, migrations.RunPython.noop)] |
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,45 @@ | ||
# Generated by Django 3.2.21 on 2024-05-17 09:54 | ||
|
||
|
||
from django.db import migrations | ||
|
||
|
||
def forwards(apps, schema_editor): | ||
Outcome = apps.get_model("peachjam", "Outcome") | ||
OrderOutCome = apps.get_model("peachjam", "OrderOutCome") | ||
Judgment = apps.get_model("peachjam", "Judgment") | ||
|
||
for outcome in OrderOutCome.objects.all(): | ||
o = Outcome() | ||
o.name = outcome.name | ||
o.description = outcome.description | ||
if hasattr(outcome, "name_en"): | ||
o.name_en = outcome.name_en | ||
if hasattr(outcome, "name_fr"): | ||
o.name_fr = outcome.name_fr | ||
if hasattr(outcome, "name_pt"): | ||
o.name_pt = outcome.name_pt | ||
if hasattr(outcome, "name_sw"): | ||
o.name_sw = outcome.name_sw | ||
o.save() | ||
|
||
for judgment in ( | ||
Judgment.objects.filter(order_outcomes__isnull=False) | ||
.order_by("pk") | ||
.iterator(chunk_size=100) | ||
): | ||
j_outcomes = judgment.order_outcomes.all().values_list("name", flat=True) | ||
outcomes = Outcome.objects.filter(name__in=j_outcomes) | ||
if outcomes: | ||
judgment.outcomes.set(outcomes) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("peachjam", "0132_outcome_es_index"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(forwards, migrations.RunPython.noop), | ||
] |
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
Oops, something went wrong.