Skip to content

Commit a9f3d6c

Browse files
chg ! add enabled flag to program and office (#95)
1 parent 83cd80b commit a9f3d6c

File tree

8 files changed

+44
-9
lines changed

8 files changed

+44
-9
lines changed

src/country_workspace/admin/office.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
@admin.register(Office)
1313
class OfficeAdmin(SyncAdminMixin, BaseModelAdmin):
14-
list_display = ("name", "long_name", "slug", "code", "active", "kobo_country_code")
14+
list_display = ("name", "long_name", "slug", "code", "active", "enabled", "kobo_country_code")
1515
search_fields = ("name", "slug", "code")
16-
list_filter = ("active",)
16+
list_filter = ("active", "enabled")
1717
readonly_fields = ("hope_id", "slug")
1818
ordering = ("name",)
1919
sync_config = SyncConfig(model=Office, step=SyncStep.OFFICES, sync_handler=ContextProgramsSyncHandler())

src/country_workspace/admin/program.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class ProgramAdmin(SyncAdminMixin, BaseModelAdmin):
2424
"name",
2525
"sector",
2626
"status",
27+
"enabled",
2728
"beneficiary_group",
2829
"beneficiary_validator",
2930
"household_checker",
@@ -34,6 +35,7 @@ class ProgramAdmin(SyncAdminMixin, BaseModelAdmin):
3435
("country_office", AutoCompleteFilter),
3536
"status",
3637
"sector",
38+
"enabled",
3739
"beneficiary_group",
3840
"beneficiary_validator",
3941
"household_checker",
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Generated by Django 5.1.7 on 2025-05-13 13:04
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("country_workspace", "0013_country_iso_code3"),
9+
]
10+
11+
operations = [
12+
migrations.AddField(
13+
model_name="office",
14+
name="enabled",
15+
field=models.BooleanField(
16+
db_index=True, default=True, help_text="Is this office enabled in the workspace?"
17+
),
18+
),
19+
migrations.AddField(
20+
model_name="program",
21+
name="enabled",
22+
field=models.BooleanField(
23+
db_index=True, default=True, help_text="Is this program enabled in the workspace?"
24+
),
25+
),
26+
migrations.AlterField(
27+
model_name="office",
28+
name="active",
29+
field=models.BooleanField(
30+
db_index=True, default=False, help_text="Is this office active in the HOPE core?"
31+
),
32+
),
33+
]

src/country_workspace/models/office.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ class Office(BaseModel):
1111
long_name = models.CharField(max_length=100, blank=True, null=True, db_index=True)
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)
14-
active = models.BooleanField(default=False)
14+
active = models.BooleanField(default=False, db_index=True, help_text="Is this office active in the HOPE core?")
1515
kobo_country_code = models.CharField(max_length=3, blank=True, null=True)
16-
1716
extra_fields = models.JSONField(default=dict, blank=True, null=False)
17+
enabled = models.BooleanField(default=True, db_index=True, help_text="Is this office enabled in the workspace?")
1818

1919
def __str__(self) -> str:
2020
return str(self.name)

src/country_workspace/models/program.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ class Program(BaseModel):
5858
code = models.CharField(max_length=255, blank=True, null=True)
5959
status = models.CharField(max_length=10, choices=STATUS_CHOICE, db_index=True)
6060
sector = models.CharField(max_length=50, choices=SECTOR_CHOICE, db_index=True)
61-
6261
# Local Fields
6362
beneficiary_validator = StrategyField(
6463
registry=beneficiary_validator_registry,
@@ -90,6 +89,7 @@ class Program(BaseModel):
9089
household_columns = models.TextField(default="name\nid", help_text="Columns to display in the Admin table")
9190
individual_columns = models.TextField(default="name\nid", help_text="Columns to display in the Admin table")
9291
extra_fields = models.JSONField(default=dict, blank=True, null=False)
92+
enabled = models.BooleanField(default=True, db_index=True, help_text="Is this program enabled in the workspace?")
9393

9494
def __str__(self) -> str:
9595
return self.name

src/country_workspace/workspaces/admin/program.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def media(self) -> forms.Media:
114114
)
115115

116116
def get_queryset(self, request: HttpResponse) -> QuerySet[CountryProgram]:
117-
return CountryProgram.objects.filter(country_office=state.tenant)
117+
return CountryProgram.objects.filter(country_office=state.tenant, enabled=True)
118118

119119
def has_add_permission(self, request: HttpResponse) -> bool:
120120
return False

src/country_workspace/workspaces/backend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ def get_allowed_tenants(self, request: "HttpRequest|None" = None) -> "QuerySet[M
8484
request = request or state.request
8585
allowed_tenants: "QuerySet[Model] | None"
8686
if request.user.is_superuser:
87-
allowed_tenants = Office.objects.filter(active=True)
87+
allowed_tenants = Office.objects.filter(active=True, enabled=True)
8888
elif request.user.is_authenticated:
8989
allowed_tenants = (
90-
Office.objects.filter(userrole__user=request.user, active=True)
90+
Office.objects.filter(userrole__user=request.user, active=True, enabled=True)
9191
.filter(Q(userrole__expires=None) | Q(userrole__expires__gt=today()))
9292
.distinct()
9393
)

src/country_workspace/workspaces/forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,4 @@ def __init__(self, *args: "Any", **kwargs: "Any") -> None:
8585
self.request = kwargs.pop("request")
8686
super().__init__(*args, **kwargs)
8787
if state.tenant:
88-
self.fields["program"].queryset = state.tenant.programs.filter().order_by("name").all()
88+
self.fields["program"].queryset = state.tenant.programs.filter(enabled=True).order_by("name").all()

0 commit comments

Comments
 (0)