Skip to content

Commit 8c27485

Browse files
Make country iso code optional, don't import Kobo data if counytry iso code is not set
1 parent 27841a4 commit 8c27485

File tree

6 files changed

+8
-22
lines changed

6 files changed

+8
-22
lines changed

src/country_workspace/config/fragments/app.py

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

66
TENANT_TENANT_MODEL = "country_workspace.Office"
77
TENANT_HQ = "= HQ ="
8-
TENANT_HQ_COUNTRY = "AFG"
98

109
AURORA_API_TOKEN = env("AURORA_API_TOKEN")
1110
AURORA_API_URL = env("AURORA_API_URL")

src/country_workspace/contrib/kobo/forms.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ class ImportKoboForm(forms.Form):
1313
help_text="Which field contains individual records",
1414
)
1515

16-
def __init__(self, *args: Any, country_iso_code: str, **kwargs: Any) -> None:
16+
def __init__(self, *args: Any, country_iso_code: str | None, **kwargs: Any) -> None:
1717
super().__init__(*args, **kwargs)
18-
client = make_client(country_iso_code)
19-
self.fields["project_id"].choices = [(asset.uid, asset.name) for asset in client.assets]
18+
if country_iso_code:
19+
client = make_client(country_iso_code)
20+
self.fields["project_id"].choices = [(asset.uid, asset.name) for asset in client.assets]
21+
else:
22+
self.cleaned_data = {} # type: ignore
23+
self.add_error(None, "Please set country iso code for office to use Kobo import")

src/country_workspace/management/commands/demo.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ 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,
4645
)
4746

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

src/country_workspace/management/commands/upgrade.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ 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,
174173
)
175174
call_command("upgradescripts", ["apply"])
176175
echo("Upgrade completed", style_func=self.style.SUCCESS)
Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
# Generated by Django 5.1.7 on 2025-03-18 12:26
2-
from django.apps.registry import Apps
32
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()
123

134

145
class Migration(migrations.Migration):
@@ -22,10 +13,4 @@ class Migration(migrations.Migration):
2213
name="country_iso_code",
2314
field=models.CharField(max_length=3, null=True),
2415
),
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-
),
3116
]

src/country_workspace/models/office.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +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)
15+
country_iso_code = models.CharField(max_length=3, blank=True, null=True)
1616

1717
extra_fields = models.JSONField(default=dict, blank=True, null=False)
1818

0 commit comments

Comments
 (0)