Skip to content

Commit 9d7c227

Browse files
sudip-khanalsusilnem
authored andcommitted
refactor is published to status
1 parent 59b74da commit 9d7c227

File tree

10 files changed

+253
-145
lines changed

10 files changed

+253
-145
lines changed

api/test_views.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ def test_guest_user_permission(self):
8989
go_post_apis = [
9090
"/api/v2/dref/",
9191
"/api/v2/dref-final-report/",
92-
f"/api/v2/dref-final-report/{id}/publish/",
92+
f"/api/v2/dref-final-report/{id}/approve/",
9393
"/api/v2/dref-op-update/",
94-
f"/api/v2/dref-op-update/{id}/publish/",
94+
f"/api/v2/dref-op-update/{id}/approve/",
9595
"/api/v2/dref-share/",
96-
f"/api/v2/dref/{id}/publish/",
96+
f"/api/v2/dref/{id}/approve/",
9797
"/api/v2/flash-update/",
9898
"/api/v2/flash-update-file/multiple/",
9999
"/api/v2/local-units/",

dref/admin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def get_queryset(self, request):
230230

231231
# NOTE: If the Dref Final report is unpublished, set Dref related to it as active
232232
def save_model(self, request, obj, form, change):
233-
if not obj.is_published and obj.dref:
233+
if obj.status != Dref.Status.APPROVED and obj.dref:
234234
obj.dref.is_active = True
235235
obj.dref.save(update_fields=["is_active"])
236236
super().save_model(request, obj, form, change)

dref/filter_set.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ class DrefFilter(filters.FilterSet):
1515

1616
class Meta:
1717
model = Dref
18-
fields = ["is_published"]
18+
fields = ["status"]
1919

2020

2121
class DrefOperationalUpdateFilter(filters.FilterSet):
2222
dref = filters.ModelMultipleChoiceFilter(field_name="dref", queryset=Dref.objects.all().distinct())
2323

2424
class Meta:
2525
model = DrefOperationalUpdate
26-
fields = ["is_published"]
26+
fields = ["status"]
2727

2828

2929
class BaseDrefFilterSet(filters.FilterSet):
Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by Django 4.2.19 on 2025-09-10 08:48
1+
# Generated by Django 4.2.19 on 2025-09-16 09:09
22

33
from django.db import migrations, models
44

@@ -28,34 +28,55 @@ class Migration(migrations.Migration):
2828
]
2929

3030
operations = [
31+
migrations.AddField(
32+
model_name="dref",
33+
name="original_language",
34+
field=models.CharField(
35+
blank=True,
36+
help_text="The language in which this record was first created.",
37+
null=True,
38+
verbose_name="Original language",
39+
),
40+
),
41+
migrations.AddField(
42+
model_name="dreffinalreport",
43+
name="original_language",
44+
field=models.CharField(
45+
blank=True,
46+
help_text="The language in which this record was first created.",
47+
null=True,
48+
verbose_name="Original language",
49+
),
50+
),
51+
migrations.AddField(
52+
model_name="drefoperationalupdate",
53+
name="original_language",
54+
field=models.CharField(
55+
blank=True,
56+
help_text="The language in which this record was first created.",
57+
null=True,
58+
verbose_name="Original language",
59+
),
60+
),
3161
migrations.AlterField(
3262
model_name="dref",
3363
name="status",
3464
field=models.IntegerField(
35-
blank=True,
36-
choices=[(1, "Draft"), (2, "Finalizing"), (3, "Finalized"), (4, "Approved")],
37-
null=True,
38-
verbose_name="status",
65+
choices=[(1, "Draft"), (2, "Finalizing"), (3, "Finalized"), (4, "Approved")], default=1, verbose_name="status"
3966
),
4067
),
4168
migrations.AlterField(
4269
model_name="dreffinalreport",
4370
name="status",
4471
field=models.IntegerField(
45-
blank=True,
46-
choices=[(1, "Draft"), (2, "Finalizing"), (3, "Finalized"), (4, "Approved")],
47-
null=True,
48-
verbose_name="status",
72+
choices=[(1, "Draft"), (2, "Finalizing"), (3, "Finalized"), (4, "Approved")], default=1, verbose_name="status"
4973
),
5074
),
5175
migrations.AlterField(
5276
model_name="drefoperationalupdate",
5377
name="status",
5478
field=models.IntegerField(
55-
blank=True,
56-
choices=[(1, "Draft"), (2, "Finalizing"), (3, "Finalized"), (4, "Approved")],
57-
null=True,
58-
verbose_name="status",
79+
choices=[(1, "Draft"), (2, "Finalizing"), (3, "Finalized"), (4, "Approved")], default=1, verbose_name="status"
5980
),
6081
),
6182
migrations.RunPython(update_status, reverse_code=migrations.RunPython.noop),
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Generated by Django 4.2.19 on 2025-09-16 09:13
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("dref", "0084_dref_original_language_and_more"),
10+
]
11+
12+
operations = [
13+
migrations.RemoveField(
14+
model_name="dref",
15+
name="is_published",
16+
),
17+
migrations.RemoveField(
18+
model_name="dreffinalreport",
19+
name="is_published",
20+
),
21+
migrations.RemoveField(
22+
model_name="drefoperationalupdate",
23+
name="is_published",
24+
),
25+
]

dref/models.py

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,14 @@ class DisasterCategory(models.IntegerChoices):
264264
RED = 2, _("Red")
265265

266266
class Status(models.IntegerChoices):
267-
# NOTE: Updated statuses for clarity:
268-
# IN_PROGRESS → DRAFT, COMPLETED → APPROVED.
269-
# Added FINALIZING and FINALIZED for translation/finalization.
270267
DRAFT = 1, _("Draft")
268+
"""Draft: Initial stage content is being created and is not ready for review."""
271269
FINALIZING = 2, _("Finalizing")
270+
"""Finalizing: Content is in the translation process from the original language into English."""
272271
FINALIZED = 3, _("Finalized")
272+
"""Finalized: Translation is completed, content is ready for review, and updates to the original language are locked."""
273273
APPROVED = 4, _("Approved")
274+
"""Approved: The content has been reviewed, accepted, and is ready for use."""
274275

275276
created_at = models.DateTimeField(verbose_name=_("created at"), auto_now_add=True)
276277
modified_at = models.DateTimeField(verbose_name=_("modified at"), default=timezone.now, null=True)
@@ -334,7 +335,13 @@ class Status(models.IntegerChoices):
334335
verbose_name=_("If available please upload additional support documentation for targeting strategy"),
335336
related_name="dref_targeting_strategy_support_file",
336337
)
337-
status = models.IntegerField(choices=Status.choices, verbose_name=_("status"), null=True, blank=True)
338+
status = models.IntegerField(choices=Status.choices, verbose_name=_("status"), default=Status.DRAFT)
339+
original_language = models.CharField(
340+
blank=True,
341+
null=True,
342+
verbose_name=_("Original language"),
343+
help_text="The language in which this record was first created.",
344+
) # NOTE: This field is set at creation with the active language.
338345
num_assisted = models.IntegerField(verbose_name=_("number of assisted"), blank=True, null=True)
339346
num_affected = models.IntegerField(verbose_name=_("number of affected"), blank=True, null=True)
340347
estimated_number_of_affected_male = models.IntegerField(
@@ -650,10 +657,6 @@ class Status(models.IntegerChoices):
650657
verbose_name=_("cover image"),
651658
related_name="cover_image_dref",
652659
)
653-
is_published = models.BooleanField(
654-
default=False,
655-
verbose_name=_("Is published"),
656-
)
657660
is_final_report_created = models.BooleanField(
658661
default=False,
659662
verbose_name=_("Is final report created"),
@@ -862,7 +865,13 @@ class DrefOperationalUpdate(models.Model):
862865
disaster_category = models.IntegerField(
863866
choices=Dref.DisasterCategory.choices, verbose_name=_("disaster category"), null=True, blank=True
864867
)
865-
status = models.IntegerField(choices=Dref.Status.choices, verbose_name=_("status"), null=True, blank=True)
868+
status = models.IntegerField(choices=Dref.Status.choices, verbose_name=_("status"), default=Dref.Status.DRAFT)
869+
original_language = models.CharField(
870+
blank=True,
871+
null=True,
872+
verbose_name=_("Original language"),
873+
help_text="The language in which this record was first created.",
874+
) # NOTE: This field is set at creation with the active language.
866875
number_of_people_targeted = models.IntegerField(verbose_name=_("Number of people targeted"), blank=True, null=True)
867876
number_of_people_affected = models.IntegerField(verbose_name=_("number of people affected"), blank=True, null=True)
868877
estimated_number_of_affected_male = models.IntegerField(
@@ -1097,10 +1106,6 @@ class DrefOperationalUpdate(models.Model):
10971106
null=True,
10981107
)
10991108
planned_interventions = models.ManyToManyField(PlannedIntervention, verbose_name=_("planned intervention"), blank=True)
1100-
is_published = models.BooleanField(
1101-
default=False,
1102-
verbose_name=_("Is published"),
1103-
)
11041109
country = models.ForeignKey(
11051110
Country,
11061111
verbose_name=_("country"),
@@ -1299,7 +1304,13 @@ class DrefFinalReport(models.Model):
12991304
disaster_category = models.IntegerField(
13001305
choices=Dref.DisasterCategory.choices, verbose_name=_("disaster category"), null=True, blank=True
13011306
)
1302-
status = models.IntegerField(choices=Dref.Status.choices, verbose_name=_("status"), null=True, blank=True)
1307+
status = models.IntegerField(choices=Dref.Status.choices, verbose_name=_("status"), default=Dref.Status.DRAFT)
1308+
original_language = models.CharField(
1309+
blank=True,
1310+
null=True,
1311+
verbose_name=_("Original language"),
1312+
help_text="The language in which this record was first created.",
1313+
) # NOTE: This field is set at creation with the active language.
13031314
number_of_people_targeted = models.IntegerField(verbose_name=_("Number of people targeted"), blank=True, null=True)
13041315
number_of_people_affected = models.IntegerField(verbose_name=_("number of people affected"), blank=True, null=True)
13051316
estimated_number_of_affected_male = models.IntegerField(
@@ -1483,7 +1494,6 @@ class DrefFinalReport(models.Model):
14831494
verbose_name=_("Additional National Societies Actions"), null=True, blank=True
14841495
)
14851496
planned_interventions = models.ManyToManyField(PlannedIntervention, verbose_name=_("planned intervention"), blank=True)
1486-
is_published = models.BooleanField(verbose_name=_("Is Published"), default=False)
14871497
country = models.ForeignKey(
14881498
Country,
14891499
verbose_name=_("country"),
@@ -1657,7 +1667,7 @@ def save(self, *args, **kwargs):
16571667
super().save(*args, **kwargs)
16581668

16591669
@staticmethod
1660-
def get_for(user, is_published=False):
1670+
def get_for(user, status=None):
16611671
from dref.utils import get_dref_users
16621672

16631673
# get the user in dref
@@ -1676,6 +1686,6 @@ def get_for(user, is_published=False):
16761686
final_report_created_by = DrefFinalReport.objects.filter(created_by=user).distinct()
16771687
union_query = final_report_users.union(final_report_created_by)
16781688
queryset = DrefFinalReport.objects.filter(id__in=union_query.values("id")).distinct()
1679-
if is_published:
1680-
return queryset.filter(is_published=True)
1689+
if status == Dref.Status.APPROVED:
1690+
return queryset.filter(status=Dref.Status.APPROVED)
16811691
return queryset

dref/permissions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django.contrib.auth.models import Permission
22
from rest_framework import permissions
33

4-
from dref.models import DrefFinalReport, DrefOperationalUpdate
4+
from dref.models import Dref, DrefFinalReport, DrefOperationalUpdate
55
from dref.utils import get_dref_users
66

77

@@ -42,6 +42,6 @@ def has_object_permission(self, request, view, obj):
4242
region = obj.country.region.name
4343
codename = f"dref_region_admin_{region}"
4444
user = request.user
45-
if Permission.objects.filter(user=user, codename=codename).exists() and not obj.is_published:
45+
if Permission.objects.filter(user=user, codename=codename).exists() and obj.status != Dref.Status.APPROVED:
4646
return True
4747
return False

0 commit comments

Comments
 (0)