Skip to content

Commit

Permalink
Merge pull request #133 from iMMAP/add_facility_type
Browse files Browse the repository at this point in the history
Added facility site type to activity planning and reporting
  • Loading branch information
shtayeb authored Jan 3, 2024
2 parents c8daf86 + af485b3 commit 5191b70
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 20 deletions.
12 changes: 11 additions & 1 deletion src/project_reports/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
from django.db import models

from rh.models import ActivityPlan, Disaggregation, Indicator, Location, LocationType, Project, ReportType
from rh.models import (
ActivityPlan,
Disaggregation,
Indicator,
Location,
LocationType,
Project,
ReportType,
FacilitySiteType,
)

# ##############################################
# ############# Project Reporting ##############
Expand Down Expand Up @@ -89,6 +98,7 @@ class TargetLocationReport(models.Model):
blank=True,
)
location_type = models.ForeignKey(LocationType, on_delete=models.SET_NULL, null=True, blank=True)
facility_site_type = models.ForeignKey(FacilitySiteType, on_delete=models.SET_NULL, null=True)

def __str__(self):
return f"{self.activity_plan_report}, {self.province}, {self.district}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,19 @@
{{ location_report_form.district }}
</div>
</div>
{% if location_report_form.zone.choices %}
<div class="field-col">
<div class="input-field">
<label for="{{location_report_form.zone.id_for_label}}">Ward / Zone</label>
{{ location_report_form.zone }}
</div>
</div>
{% endif %}
<div class="field-col">
<div class="input-field">
<label for="{{location_report_form.facility_site_type.id_for_label}}">Facility Site Type</label>
{{ location_report_form.facility_site_type }}
</div>
</div>
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/rh/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
Organization,
Project,
TargetLocation,
FacilitySiteType,
)


Expand Down Expand Up @@ -222,6 +223,8 @@ def __init__(self, *args, **kwargs):
)
self.fields["province"].queryset = self.fields["province"].queryset.filter(type="Province")
self.fields["district"].queryset = self.fields["district"].queryset.filter(type="District")
# Get only the relevant facility types - related to cluster
self.fields["facility_site_type"].queryset = FacilitySiteType.objects.all()
self.fields["zone"].queryset = self.fields["zone"].queryset.filter(type="Zone")
self.fields["province"].widget.attrs.update(
{
Expand Down Expand Up @@ -295,9 +298,6 @@ def __init__(self, *args, project, **kwargs):
{"onchange": f"updateActivityTitle('{prefix}', 'id_{prefix}-activity_detail');"}
)
self.fields["indicators"].widget.attrs.update({"style": "height: 128px;"})
# self.fields["facility_type"].queryset = self.fields[
# "facility_type"
# ].queryset.filter(cluster__in=cluster_ids)


ActivityPlanFormSet = inlineformset_factory(
Expand Down
18 changes: 18 additions & 0 deletions src/rh/migrations/0013_targetlocation_facility_site_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.0.6 on 2024-01-03 05:08

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
dependencies = [
("rh", "0012_merge_20231220_0933"),
]

operations = [
migrations.AddField(
model_name="targetlocation",
name="facility_site_type",
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to="rh.facilitysitetype"),
),
]
20 changes: 11 additions & 9 deletions src/rh/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class Meta:

class FacilitySiteType(models.Model):
cluster = models.ForeignKey(Cluster, on_delete=models.SET_NULL, blank=True, null=True)
name = models.fields.CharField(max_length=NAME_MAX_LENGTH, blank=True, null=True)
name = models.CharField(max_length=NAME_MAX_LENGTH, blank=True, null=True)

def __str__(self):
return self.name
Expand All @@ -186,7 +186,7 @@ class Meta:

class ImplementationModalityType(models.Model):
code = models.CharField(max_length=NAME_MAX_LENGTH, blank=True, null=True)
name = models.fields.CharField(max_length=NAME_MAX_LENGTH, blank=True, null=True)
name = models.CharField(max_length=NAME_MAX_LENGTH, blank=True, null=True)

def __str__(self):
return self.name
Expand All @@ -199,7 +199,7 @@ class Meta:
class TransferMechanismType(models.Model):
modality_id = models.ForeignKey(ImplementationModalityType, on_delete=models.SET_NULL, blank=True, null=True)
code = models.CharField(max_length=NAME_MAX_LENGTH, blank=True, null=True)
name = models.fields.CharField(max_length=NAME_MAX_LENGTH, blank=True, null=True)
name = models.CharField(max_length=NAME_MAX_LENGTH, blank=True, null=True)

def __str__(self):
return self.name
Expand All @@ -211,7 +211,7 @@ class Meta:

class PackageType(models.Model):
code = models.CharField(max_length=NAME_MAX_LENGTH, blank=True, null=True)
name = models.fields.CharField(max_length=NAME_MAX_LENGTH, blank=True, null=True)
name = models.CharField(max_length=NAME_MAX_LENGTH, blank=True, null=True)

def __str__(self):
return self.name
Expand All @@ -223,7 +223,7 @@ class Meta:

class TransferCategory(models.Model):
code = models.CharField(max_length=NAME_MAX_LENGTH, blank=True, null=True)
name = models.fields.CharField(max_length=NAME_MAX_LENGTH, blank=True, null=True)
name = models.CharField(max_length=NAME_MAX_LENGTH, blank=True, null=True)

def __str__(self):
return self.name
Expand All @@ -235,7 +235,7 @@ class Meta:

class GrantType(models.Model):
code = models.CharField(max_length=NAME_MAX_LENGTH, blank=True, null=True)
name = models.fields.CharField(max_length=NAME_MAX_LENGTH, blank=True, null=True)
name = models.CharField(max_length=NAME_MAX_LENGTH, blank=True, null=True)

def __str__(self):
return self.name
Expand All @@ -247,7 +247,7 @@ class Meta:

class UnitType(models.Model):
code = models.CharField(max_length=NAME_MAX_LENGTH, blank=True, null=True)
name = models.fields.CharField(max_length=NAME_MAX_LENGTH, blank=True, null=True)
name = models.CharField(max_length=NAME_MAX_LENGTH, blank=True, null=True)

def __str__(self):
return self.name
Expand All @@ -259,7 +259,7 @@ class Meta:

class ReportType(models.Model):
code = models.CharField(max_length=NAME_MAX_LENGTH, blank=True, null=True)
name = models.fields.CharField(max_length=NAME_MAX_LENGTH, blank=True, null=True)
name = models.CharField(max_length=NAME_MAX_LENGTH, blank=True, null=True)

def __str__(self):
return self.name
Expand Down Expand Up @@ -557,14 +557,16 @@ class TargetLocation(models.Model):
blank=True,
)
location_type = models.ForeignKey(LocationType, on_delete=models.SET_NULL, null=True, blank=True)
classification = models.CharField(max_length=15, choices=TARGET_CLASSIFICATION, blank=True, null=True)

implementing_partner = models.ForeignKey(Organization, on_delete=models.SET_NULL, null=True, blank=True)

facility_site_type = models.ForeignKey(FacilitySiteType, on_delete=models.SET_NULL, null=True)

site_monitoring = models.BooleanField(default=False)
site_name = models.CharField(max_length=255, blank=True, null=True)
site_lat = models.CharField(max_length=255, blank=True, null=True)
site_long = models.CharField(max_length=255, blank=True, null=True)
classification = models.CharField(max_length=15, choices=TARGET_CLASSIFICATION, blank=True, null=True)
old_id = models.CharField(max_length=NAME_MAX_LENGTH, blank=True, null=True)

def __str__(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,20 @@
{{ target_location_form.district }}
</div>
</div>
<div class="field-col">
{% if target_location_form.zone.choices %}
<div class="field-col">
<div class="input-field">
<label for="{{target_location_form.zone.id_for_label}}">Ward / Zone</label>
{{ target_location_form.zone }}
</div>
</div>
{% endif %}
<div class="field-col">
<div class="input-field">
<label for="{{target_location_form.facility_site_type.id_for_label}}">Facility Site Type</label>
{{ target_location_form.facility_site_type }}
</div>
</div>
<div class="field-col">
<div class="select-field is is-required">
<label for="{{target_location_form.classification_for_label}}">Classification</label>
Expand Down
2 changes: 1 addition & 1 deletion src/rh/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ def get_activity_empty_form(request):

# Prepare context for rendering the activity empty form template
context = {
"form": activity_plan_formset.empty_form,
"form": activity_plan_formset,
"target_location_formset": target_location_formset,
"project": project,
}
Expand Down
10 changes: 5 additions & 5 deletions src/static/rh/js/activity_planning.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,11 @@ function getLocations(locationPrefix, locationType, parentType, clearZone=null)
$(`select#id_${locationPrefix}-${locationType}`).val(selectedLocations);
}

if(locationType == 'zone' && data === ''){
$(`#id_${locationPrefix}-${locationType}`).parent().hide();
}else{
$(`#id_${locationPrefix}-${locationType}`).parent().show();
}
// if(locationType == 'zone' && data === ''){
// $(`#id_${locationPrefix}-${locationType}`).parent().hide();
// }else{
// $(`#id_${locationPrefix}-${locationType}`).parent().show();
// }

},
error: function (error) {
Expand Down

0 comments on commit 5191b70

Please sign in to comment.