Skip to content

Commit 286bd0e

Browse files
chg ! labels according to beneficiary group
1 parent 69a13ba commit 286bd0e

File tree

16 files changed

+122
-56
lines changed

16 files changed

+122
-56
lines changed

src/country_workspace/admin/beneficiary_group.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,5 @@ class BeneficiaryGroupAdmin(BaseModelAdmin):
2020
def has_add_permission(self, request: HttpRequest) -> bool:
2121
return False
2222

23-
def has_delete_permission(self, request: HttpRequest, obj: BeneficiaryGroup = None) -> bool:
24-
return False
25-
2623
def has_change_permission(self, request: HttpRequest, obj: BeneficiaryGroup = None) -> bool:
2724
return False

src/country_workspace/admin/program.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ class ProgramAdmin(BaseModelAdmin):
2020
list_display = (
2121
"name",
2222
"sector",
23-
"beneficiary_group",
2423
"status",
2524
"active",
25+
"beneficiary_group",
2626
"beneficiary_validator",
2727
"household_checker",
2828
"individual_checker",

src/country_workspace/management/commands/demo.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def handle(self, *args: Any, **options: Any) -> None:
5252
sys.path.append(str(test_utils_dir.absolute()))
5353

5454
import vcr
55-
from testutils.factories import BatchFactory, HouseholdFactory
55+
from testutils.factories import BatchFactory, HouseholdFactory, IndividualFactory
5656
from vcr.record_mode import RecordMode
5757

5858
from country_workspace.contrib.hope.sync.office import sync_all
@@ -86,4 +86,7 @@ def handle(self, *args: Any, **options: Any) -> None:
8686
for co in Office.objects.filter(active=True):
8787
for p in co.programs.filter():
8888
b = BatchFactory(country_office=co, name=f"Batch {p}", program=p)
89-
HouseholdFactory.create_batch(10, batch=b)
89+
if p.beneficiary_group.master_detail:
90+
HouseholdFactory.create_batch(10, batch=b)
91+
else:
92+
IndividualFactory.create_batch(10, batch=b, household=None)

src/country_workspace/workspaces/admin/hh_ind.py

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,24 @@ class BeneficiaryBaseAdmin(AdminAutoCompleteSearchMixin, SelectedProgramMixin, W
5959
actions.bulk_update_export,
6060
actions.calculate_checksum,
6161
]
62-
title = None
63-
title_plural = None
6462
list_per_page = 20
6563

64+
@property
65+
def title_group(self) -> str | None:
66+
return self._get_title_label("group_label")
67+
68+
@property
69+
def title_group_plural(self) -> str | None:
70+
return self._get_title_label("group_label_plural")
71+
72+
@property
73+
def title_member(self) -> str | None:
74+
return self._get_title_label("member_label")
75+
76+
@property
77+
def title_member_plural(self) -> str | None:
78+
return self._get_title_label("member_label_plural")
79+
6680
def has_validate_permission(self, request: HttpRequest) -> bool:
6781
return request.user.has_perm("country_workspace.validate_beneficiary")
6882

@@ -85,12 +99,21 @@ def get_queryset(self, request: HttpRequest) -> "QuerySet[Beneficiary]":
8599
return qs
86100

87101
def get_common_context(self, request: HttpRequest, pk: str | None = None, **kwargs: Any) -> dict[str, Any]:
88-
ret = super().get_common_context(request, pk, **kwargs)
89-
ret["datachecker"] = self.get_checker(request, ret.get("original"))
90-
ret["modeladmin"] = self
91-
ret["title_plural"] = self.title_plural
92-
ret.update(**kwargs)
93-
return ret
102+
context = super().get_common_context(request, pk, **kwargs)
103+
return {
104+
**context,
105+
"modeladmin": self,
106+
"datachecker": self.get_checker(request, context.get("original")),
107+
"title_group": self.title_group,
108+
"title_group_plural": self.title_group_plural,
109+
"title_member": self.title_member,
110+
"title_member_plural": self.title_member_plural,
111+
**kwargs,
112+
}
113+
114+
def _get_title_label(self, attr: str) -> str | None:
115+
program = state.program
116+
return getattr(program.beneficiary_group, attr) if program else None
94117

95118
@button(
96119
label=_("Validate"),
@@ -201,7 +224,6 @@ def _changeform_view( # noqa: PLR0912
201224
form = form_class(prefix="flex_field", initial=initials)
202225

203226
context["show_save_invalid"] = True
204-
context["title"] = self.title
205227
context["checker_form"] = form
206228
context["has_change_permission"] = self.has_change_permission(request)
207229

src/country_workspace/workspaces/admin/household.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from django.contrib.admin import register
66
from django.http import HttpRequest
77
from django.urls import reverse
8-
from django.utils.translation import gettext as _
98

109
from ...state import state
1110
from ..models import CountryHousehold
@@ -26,15 +25,17 @@ class CountryHouseholdAdmin(BeneficiaryBaseAdmin):
2625
list_display = ["name", "batch"]
2726
search_fields = ("name",)
2827
ordering = ("name",)
29-
title = _("Household")
30-
title_plural = _("Households")
3128
list_per_page = 20
3229
list_filter = (
3330
("batch", CWLinkedAutoCompleteFilter.factory(parent=None)),
3431
WIsValidFilter,
3532
)
3633
actions = [*BeneficiaryBaseAdmin.actions, push_to_hope]
3734

35+
@property
36+
def title_plural(self) -> str:
37+
return super().title_group_plural
38+
3839
def get_list_display(self, request: HttpRequest) -> list[str]:
3940
program: "CountryProgram | None"
4041
if program := self.get_selected_program(request):
@@ -53,8 +54,9 @@ def get_queryset(self, request: HttpRequest) -> "QuerySet[CountryHousehold]":
5354
.filter(batch__country_office=state.tenant, batch__program=state.program)
5455
)
5556

56-
@link(change_list=False, html_attrs={"title": "Shows related individuals."})
57+
@link(change_list=False, html_attrs={"title": "Shows related members."})
5758
def members(self, btn: LinkButton) -> None:
5859
base = reverse("workspace:workspaces_countryindividual_changelist")
5960
obj = btn.context["original"]
6061
btn.href = f"{base}?household__exact={obj.pk}"
62+
btn.label = self.title_member_plural

src/country_workspace/workspaces/admin/individual.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from django.contrib.admin import AdminSite, register
55
from django.db.models import Model, QuerySet
66
from django.http import HttpRequest
7-
from django.utils.translation import gettext as _
87

98
from ...state import state
109
from ..models import CountryHousehold, CountryIndividual, CountryProgram
@@ -33,8 +32,10 @@ class CountryIndividualAdmin(BeneficiaryBaseAdmin):
3332
"user_fields",
3433
]
3534
ordering = ("name",)
36-
title = _("Individual")
37-
title_plural = _("Individuals")
35+
36+
@property
37+
def title_plural(self) -> str:
38+
return super().title_member_plural
3839

3940
def __init__(self, model: Model, admin_site: "AdminSite") -> None:
4041
self._selected_household = None

src/country_workspace/workspaces/admin/program.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,20 @@ def changelist_view(self, request: HttpRequest, extra_context: dict[str, None] |
150150
url = reverse("workspace:workspaces_countryprogram_change", args=[state.program.pk])
151151
return HttpResponseRedirect(url)
152152

153+
def changeform_view(
154+
self,
155+
request: "HttpRequest",
156+
object_id: str | None = None,
157+
form_url: str = "",
158+
extra_context: dict[str, Any] | None = None,
159+
) -> HttpResponse:
160+
if obj := self.get_object(request, object_id):
161+
extra_context["btnlabels"] = {
162+
"individual_columns": f"{obj.beneficiary_group.member_label} Columns",
163+
"household_columns": f"{obj.beneficiary_group.group_label} Columns",
164+
}
165+
return super().changeform_view(request, object_id, form_url, extra_context=extra_context)
166+
153167
def _configure_columns(
154168
self,
155169
request: HttpResponse,
Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
{% spaceless %}<li>
2-
<a href="{{ button.url }}{% if is_popup %}&_popup=1{% endif %}"
3-
{% include "admin_extra_buttons/includes/attrs.html" with button=button %}>
4-
{% if button.icon %}<i class="{{ button.icon }}"></i>&nbsp;{% endif %}{{ button.label }}</a>
5-
</li>{% endspaceless %}
1+
{% spaceless %}
2+
<li>
3+
<a href="{{ button.url }}{% if is_popup %}&_popup=1{% endif %}"
4+
{% include "admin_extra_buttons/includes/attrs.html" with button=button %}>
5+
{% if button.icon %}<i class="{{ button.icon }}"></i> {% endif %}
6+
{% if button.label == "Individual Columns" %}
7+
{{ btnlabels.individual_columns|default:button.label }}
8+
{% elif button.label == "Household Columns" %}
9+
{{ btnlabels.household_columns|default:button.label }}
10+
{% else %}
11+
{{ button.label }}
12+
{% endif %}
13+
</a>
14+
</li>
15+
{% endspaceless %}

src/country_workspace/workspaces/templates/workspace/admin_extra_buttons/includes/change_form_buttons.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
{% get_changeform_buttons adminform.model_admin as buttons %}
33
{% for button in buttons %}
44
{% if button.can_render and button.change_form %}
5-
{{ button }}
5+
{% include "workspace/admin_extra_buttons/includes/button.html" with button=button btnlabels=btnlabels is_popup=is_popup %}
66
{% endif %}
77
{% endfor %}

src/country_workspace/workspaces/templates/workspace/household/change_form.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
{% load admin_modify i18n static workspace_modify workspace_urls %}
33
{% block page-title %}
44
{% url "workspace:workspaces_countryhousehold_changelist" as wcl %}
5-
&rsaquo; <a href="{% add_preserved_filters wcl %}">Households</a>{% admin_url modeladmin %}
5+
&rsaquo; <a href="{% add_preserved_filters wcl %}">{{ title_group_plural }}</a>{% admin_url modeladmin %}
66
&rsaquo; {{ original }}{% admin_url original %}
77
{% endblock page-title %}

0 commit comments

Comments
 (0)