Skip to content

Commit 8a68417

Browse files
Add country iso code to office
1 parent b0612cf commit 8a68417

File tree

11 files changed

+65
-15
lines changed

11 files changed

+65
-15
lines changed

src/country_workspace/admin/office.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
@admin.register(Office)
1212
class OfficeAdmin(BaseModelAdmin):
13-
list_display = ("name", "long_name", "slug", "code", "active")
13+
list_display = ("name", "long_name", "slug", "code", "active", "country_iso_code")
1414
search_fields = ("name", "slug", "code")
1515
list_filter = ("active",)
1616
readonly_fields = ("hope_id", "slug")

src/country_workspace/config/fragments/app.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
TENANT_TENANT_MODEL = "country_workspace.Office"
77
TENANT_HQ = "= HQ ="
8+
TENANT_HQ_COUNTRY = "AFG"
89

910
AURORA_API_TOKEN = env("AURORA_API_TOKEN")
1011
AURORA_API_URL = env("AURORA_API_URL")

src/country_workspace/contrib/hope/sync/office.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def sync_offices(stdout: TextIOBase | None = None) -> dict[str, int]:
2525
"code": record["code"],
2626
"active": record["active"],
2727
"long_name": record["long_name"],
28+
# TODO: sync country iso code
2829
},
2930
)
3031
totals["add" if created else "upd"] += 1

src/country_workspace/contrib/kobo/forms.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33

44
class ImportKoboForm(forms.Form):
55
batch_name = forms.CharField(required=False, help_text="Label for this batch")
6-
country_code = forms.CharField(
7-
required=False,
8-
help_text="Country ISO code",
9-
min_length=3,
10-
max_length=3,
11-
)
126
individual_records_field = forms.CharField(
137
required=False,
148
initial="individual_questions",

src/country_workspace/management/commands/demo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def handle(self, *args: Any, **options: Any) -> None:
4242
settings.TENANT_HQ,
4343
),
4444
name=settings.TENANT_HQ,
45+
country_iso_code=settings.TENANT_HQ_COUNTRY,
4546
)
4647

4748
analysts, __ = Group.objects.get_or_create(name=settings.ANALYST_GROUP_NAME)

src/country_workspace/management/commands/upgrade.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ def handle(self, *args: Any, **options: Any) -> None: # noqa
170170
settings.TENANT_HQ,
171171
),
172172
name=settings.TENANT_HQ,
173+
country_iso_code=settings.TENANT_HQ_COUNTRY,
173174
)
174175
call_command("upgradescripts", ["apply"])
175176
echo("Upgrade completed", style_func=self.style.SUCCESS)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Generated by Django 5.1.7 on 2025-03-18 12:26
2+
from django.apps.registry import Apps
3+
from django.db import migrations, models
4+
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
5+
6+
7+
def migrate_data(apps: Apps, _: BaseDatabaseSchemaEditor) -> None:
8+
office_model = apps.get_model("country_workspace", "Office")
9+
for obj in office_model.objects.filter(country_iso_code=None):
10+
obj.country_iso_code = "AFG"
11+
obj.save()
12+
13+
14+
class Migration(migrations.Migration):
15+
dependencies = [
16+
("country_workspace", "0005_alter_asyncjob_file"),
17+
]
18+
19+
operations = [
20+
migrations.AddField(
21+
model_name="office",
22+
name="country_iso_code",
23+
field=models.CharField(max_length=3, null=True),
24+
),
25+
migrations.RunPython(migrate_data, reverse_code=migrations.RunPython.noop),
26+
migrations.AlterField(
27+
model_name="office",
28+
name="country_iso_code",
29+
field=models.CharField(max_length=3),
30+
),
31+
]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Generated by Django 5.1.7 on 2025-03-18 12:26
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("country_workspace", "0006_office_country_iso_code"),
9+
]
10+
11+
operations = [
12+
migrations.AlterField(
13+
model_name="program",
14+
name="individual_columns",
15+
field=models.TextField(default="name\nid", help_text="Columns to display i the Admin table"),
16+
),
17+
]

src/country_workspace/models/office.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class Office(BaseModel):
1212
code = models.CharField(max_length=100, blank=True, null=True, db_index=True, unique=True)
1313
slug = models.SlugField(max_length=100, blank=True, null=True, db_index=True, unique=True)
1414
active = models.BooleanField(default=False)
15+
country_iso_code = models.CharField(max_length=3, blank=False, null=False)
1516

1617
extra_fields = models.JSONField(default=dict, blank=True, null=False)
1718

src/country_workspace/workspaces/admin/program.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def import_kobo(self, request: HttpRequest, program: "CountryProgram") -> Import
317317
owner=request.user,
318318
config={
319319
"batch_name": form.cleaned_data["batch_name"] or BATCH_NAME_DEFAULT,
320-
"country_code": form.cleaned_data["country_code"],
320+
"country_code": program.country_office.country_iso_code,
321321
"individual_records_field": form.cleaned_data["individual_records_field"],
322322
},
323323
)

0 commit comments

Comments
 (0)