Skip to content

Commit dbf68fe

Browse files
Merge pull request #2432 from IFRCGo/feature/new-country-plan
Use country_plan document_url if given, else file
2 parents 0e0a8a4 + d71a96d commit dbf68fe

File tree

5 files changed

+46
-1
lines changed

5 files changed

+46
-1
lines changed

Population.GO.Admin1.Matched.xlsx

-232 KB
Binary file not shown.

country_plan/management/commands/ingest_country_plan_file.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,18 @@ def load_for_country(self, country_data: dict, file_field: str, field_inserted_d
103103
file_field,
104104
)
105105
country_plan.is_publish = True
106+
if "public" in file_field:
107+
country_plan.public_plan_url = plan_url.replace(" ", "%20")
108+
# Maybe urllib.parse.urlencode would be more general
109+
url_field = "public_plan_url"
110+
else:
111+
country_plan.internal_plan_url = plan_url.replace(" ", "%20")
112+
url_field = "internal_plan_url"
106113
country_plan.save(
107114
update_fields=(
108115
field_inserted_date_field,
109116
file_field, # By load_file_to_country_plan
117+
url_field,
110118
"is_publish",
111119
)
112120
)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by Django 4.2.19 on 2025-03-03 16:01
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("country_plan", "0008_alter_countryplan_internal_plan_file"),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name="countryplan",
15+
name="internal_plan_url",
16+
field=models.URLField(blank=True, null=True, verbose_name="internal_plan_url"),
17+
),
18+
migrations.AddField(
19+
model_name="countryplan",
20+
name="public_plan_url",
21+
field=models.URLField(blank=True, null=True, verbose_name="public_plan_url"),
22+
),
23+
]

country_plan/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,15 @@ class CountryPlan(CountryPlanAbstract):
7171
blank=True,
7272
null=True,
7373
)
74+
internal_plan_url = models.URLField(verbose_name=_("internal_plan_url"), blank=True, null=True)
7475
public_plan_file = models.FileField(
7576
verbose_name=_("Country Plan"),
7677
validators=[FileExtensionValidator(["pdf"])],
7778
upload_to=pdf_upload_to,
7879
blank=True,
7980
null=True,
8081
)
82+
public_plan_url = models.URLField(verbose_name=_("public_plan_url"), blank=True, null=True)
8183
requested_amount = models.FloatField(verbose_name=_("Requested Amount"), blank=True, null=True)
8284
people_targeted = models.IntegerField(verbose_name=_("People Targeted"), blank=True, null=True)
8385
is_publish = models.BooleanField(default=False, verbose_name=_("Published"))

country_plan/serializers.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class CountryPlanSerializer(serializers.ModelSerializer):
4343
strategic_priorities = StrategicPrioritySerializer(source="country_plan_sp", many=True, read_only=True)
4444
membership_coordinations = MembershipCoordinationSerializer(source="full_country_plan_mc", many=True, read_only=True)
4545
internal_plan_file = serializers.SerializerMethodField()
46+
public_plan_file = serializers.SerializerMethodField()
4647

4748
class Meta:
4849
model = CountryPlan
@@ -61,7 +62,18 @@ class Meta:
6162
def get_internal_plan_file(self, obj):
6263
file = obj.internal_plan_file
6364
request = self.context["request"]
64-
if request.user.is_authenticated and file.name:
65+
if request.user.is_authenticated:
66+
if obj.internal_plan_url:
67+
return obj.internal_plan_url
68+
elif file.name:
69+
return request.build_absolute_uri(serializers.FileField().to_representation(file))
70+
71+
def get_public_plan_file(self, obj):
72+
file = obj.public_plan_file
73+
request = self.context["request"]
74+
if obj.public_plan_url:
75+
return obj.public_plan_url
76+
elif file.name:
6577
return request.build_absolute_uri(serializers.FileField().to_representation(file))
6678

6779
def validate_internal_plan_file(self, internal_plan_file):

0 commit comments

Comments
 (0)