Skip to content

Commit e6ae958

Browse files
committed
Ensure bit count are set to 0 on Bite reports + disable blank
1 parent f54fc58 commit e6ae958

File tree

3 files changed

+63
-48
lines changed

3 files changed

+63
-48
lines changed

tigaserver_app/migrations/0045_report_responses_to_column.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,91 +13,91 @@ class Migration(migrations.Migration):
1313
migrations.AddField(
1414
model_name='report',
1515
name='breeding_site_has_larvae',
16-
field=models.BooleanField(blank=True, help_text='Either if the user perceived larvaes the breeding site.', null=True),
16+
field=models.BooleanField(help_text='Either if the user perceived larvaes the breeding site.', null=True),
1717
),
1818
migrations.AddField(
1919
model_name='report',
2020
name='breeding_site_has_near_mosquitoes',
21-
field=models.BooleanField(blank=True, help_text='Either if the user perceived mosquitoes near the breeding site (less than 10 meters).', null=True),
21+
field=models.BooleanField(help_text='Either if the user perceived mosquitoes near the breeding site (less than 10 meters).', null=True),
2222
),
2323
migrations.AddField(
2424
model_name='report',
2525
name='breeding_site_has_water',
26-
field=models.BooleanField(blank=True, help_text='Either if the user perceived water in the breeding site.', null=True),
26+
field=models.BooleanField(help_text='Either if the user perceived water in the breeding site.', null=True),
2727
),
2828
migrations.AddField(
2929
model_name='report',
3030
name='breeding_site_in_public_area',
31-
field=models.BooleanField(blank=True, help_text='Either if the breeding site is found in a public area.', null=True),
31+
field=models.BooleanField(help_text='Either if the breeding site is found in a public area.', null=True),
3232
),
3333
migrations.AddField(
3434
model_name='report',
3535
name='breeding_site_type',
36-
field=models.CharField(blank=True, choices=[('basin', 'Basin'), ('bucket', 'Bucket'), ('fountain', 'Fountain'), ('small_container', 'Small container'), ('storm_drain', 'Storm Drain'), ('well', 'Well'), ('other', 'Other')], help_text='Breedign site tpye.', max_length=32, null=True),
36+
field=models.CharField(choices=[('basin', 'Basin'), ('bucket', 'Bucket'), ('fountain', 'Fountain'), ('small_container', 'Small container'), ('storm_drain', 'Storm Drain'), ('well', 'Well'), ('other', 'Other')], help_text='Breeding site type.', max_length=32, null=True),
3737
),
3838
migrations.AddField(
3939
model_name='report',
4040
name='chest_bite_count',
41-
field=models.PositiveSmallIntegerField(blank=True, help_text='Number of bites reported in the chest.', null=True),
41+
field=models.PositiveSmallIntegerField(help_text='Number of bites reported in the chest.', null=True),
4242
),
4343
migrations.AddField(
4444
model_name='report',
4545
name='event_environment',
46-
field=models.CharField(blank=True, choices=[('indoors', 'Indoors'), ('outdoors', 'Outdoors'), ('vehicle', 'Inside vehicle')], help_text='The environment where the event took place.', max_length=16, null=True),
46+
field=models.CharField(choices=[('indoors', 'Indoors'), ('outdoors', 'Outdoors'), ('vehicle', 'Inside vehicle')], help_text='The environment where the event took place.', max_length=16, null=True),
4747
),
4848
migrations.AddField(
4949
model_name='report',
5050
name='event_moment',
51-
field=models.CharField(blank=True, choices=[('now', 'Now'), ('last_morning', 'Last morning'), ('last_midday', 'Last midday'), ('last_afternoon', 'Last afternoon'), ('last_night', 'Last night')], help_text='The moment of the day when the event took place.', max_length=32, null=True),
51+
field=models.CharField(choices=[('now', 'Now'), ('last_morning', 'Last morning'), ('last_midday', 'Last midday'), ('last_afternoon', 'Last afternoon'), ('last_night', 'Last night')], help_text='The moment of the day when the event took place.', max_length=32, null=True),
5252
),
5353
migrations.AddField(
5454
model_name='report',
5555
name='head_bite_count',
56-
field=models.PositiveSmallIntegerField(blank=True, help_text='Number of bites reported in the head.', null=True),
56+
field=models.PositiveSmallIntegerField(help_text='Number of bites reported in the head.', null=True),
5757
),
5858
migrations.AddField(
5959
model_name='report',
6060
name='left_arm_bite_count',
61-
field=models.PositiveSmallIntegerField(blank=True, help_text='Number of bites reported in the left arm.', null=True),
61+
field=models.PositiveSmallIntegerField(help_text='Number of bites reported in the left arm.', null=True),
6262
),
6363
migrations.AddField(
6464
model_name='report',
6565
name='left_leg_bite_count',
66-
field=models.PositiveSmallIntegerField(blank=True, help_text='Number of bites reported in the left leg.', null=True),
66+
field=models.PositiveSmallIntegerField(help_text='Number of bites reported in the left leg.', null=True),
6767
),
6868
migrations.AddField(
6969
model_name='report',
7070
name='right_arm_bite_count',
71-
field=models.PositiveSmallIntegerField(blank=True, help_text='Number of bites reported in the right arm.', null=True),
71+
field=models.PositiveSmallIntegerField(help_text='Number of bites reported in the right arm.', null=True),
7272
),
7373
migrations.AddField(
7474
model_name='report',
7575
name='right_leg_bite_count',
76-
field=models.PositiveSmallIntegerField(blank=True, help_text='Number of bites reported in the right leg.', null=True),
76+
field=models.PositiveSmallIntegerField(help_text='Number of bites reported in the right leg.', null=True),
7777
),
7878
migrations.AddField(
7979
model_name='report',
8080
name='user_perceived_mosquito_abdomen',
81-
field=models.CharField(blank=True, choices=[('albopictus', 'Aedes albopictus'), ('aegypti', 'Aedes aegypti'), ('japonicus', 'Aedes japonicus'), ('koreicus', 'Aedes koreicus'), ('culex', 'Culex pipiens'), ('other', 'Other')], help_text='The species of mosquito that the abdomen resembles, according to the user.', max_length=16, null=True),
81+
field=models.CharField(choices=[('albopictus', 'Aedes albopictus'), ('aegypti', 'Aedes aegypti'), ('japonicus', 'Aedes japonicus'), ('koreicus', 'Aedes koreicus'), ('culex', 'Culex pipiens'), ('other', 'Other')], help_text='The species of mosquito that the abdomen resembles, according to the user.', max_length=16, null=True),
8282
),
8383
migrations.AddField(
8484
model_name='report',
8585
name='user_perceived_mosquito_legs',
86-
field=models.CharField(blank=True, choices=[('albopictus', 'Aedes albopictus'), ('aegypti', 'Aedes aegypti'), ('japonicus', 'Aedes japonicus'), ('koreicus', 'Aedes koreicus'), ('culex', 'Culex pipiens'), ('other', 'Other')], help_text='The species of mosquito that the leg resembles, according to the user.', max_length=16, null=True),
86+
field=models.CharField(choices=[('albopictus', 'Aedes albopictus'), ('aegypti', 'Aedes aegypti'), ('japonicus', 'Aedes japonicus'), ('koreicus', 'Aedes koreicus'), ('culex', 'Culex pipiens'), ('other', 'Other')], help_text='The species of mosquito that the leg resembles, according to the user.', max_length=16, null=True),
8787
),
8888
migrations.AddField(
8989
model_name='report',
9090
name='user_perceived_mosquito_thorax',
91-
field=models.CharField(blank=True, choices=[('albopictus', 'Aedes albopictus'), ('aegypti', 'Aedes aegypti'), ('japonicus', 'Aedes japonicus'), ('koreicus', 'Aedes koreicus'), ('culex', 'Culex pipiens'), ('other', 'Other')], help_text='The species of mosquito that the thorax resembles, according to the user.', max_length=16, null=True),
91+
field=models.CharField(choices=[('albopictus', 'Aedes albopictus'), ('aegypti', 'Aedes aegypti'), ('japonicus', 'Aedes japonicus'), ('koreicus', 'Aedes koreicus'), ('culex', 'Culex pipiens'), ('other', 'Other')], help_text='The species of mosquito that the thorax resembles, according to the user.', max_length=16, null=True),
9292
),
9393
migrations.AddField(
9494
model_name='report',
9595
name='user_perceived_mosquito_specie',
96-
field=models.CharField(blank=True, choices=[('albopictus', 'Aedes albopictus'), ('aegypti', 'Aedes aegypti'), ('japonicus', 'Aedes japonicus'), ('koreicus', 'Aedes koreicus'), ('culex', 'Culex pipiens'), ('other', 'Other')], help_text='The mosquito specie perceived by the user.', max_length=16, null=True),
96+
field=models.CharField(choices=[('albopictus', 'Aedes albopictus'), ('aegypti', 'Aedes aegypti'), ('japonicus', 'Aedes japonicus'), ('koreicus', 'Aedes koreicus'), ('culex', 'Culex pipiens'), ('other', 'Other')], help_text='The mosquito specie perceived by the user.', max_length=16, null=True),
9797
),
9898
migrations.AddField(
9999
model_name='report',
100100
name='bite_count',
101-
field=models.PositiveSmallIntegerField(blank=True, help_text='Total number of bites reported.', null=True),
101+
field=models.PositiveSmallIntegerField(editable=False, help_text='Total number of bites reported.', null=True),
102102
),
103103
]

tigaserver_app/migrations/0046_populate_responses_column.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def responses_list_to_Q(responses: Tuple[str, str], connector: str =models.Q.OR)
1414
],
1515
_connector=connector
1616
)
17-
17+
1818
# Loading models
1919
Report = apps.get_model("tigaserver_app", "Report")
2020
ReportResponse = apps.get_model("tigaserver_app", "ReportResponse")
@@ -566,6 +566,14 @@ def update_bite_body_part(apps, fieldname, answer_id):
566566
)}
567567
)
568568

569+
from tigaserver_app.models import Report as ModelReport
570+
571+
# Ensure bite report field are set to 0 as default.
572+
Report.objects.filter(
573+
type=ModelReport.TYPE_BITE,
574+
**{f"{fieldname}__isnull": True}
575+
).update(**{f"{fieldname}": 0})
576+
569577
# Loading models
570578
Report = apps.get_model("tigaserver_app", "Report")
571579

tigaserver_app/models.py

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ class Report(TimeZoneModelMixin, models.Model):
642642
)
643643

644644
event_environment = models.CharField(
645-
max_length=16, choices=EVENT_ENVIRONMENT_CHOICES, null=True, blank=True,
645+
max_length=16, choices=EVENT_ENVIRONMENT_CHOICES, null=True,
646646
help_text=_("The environment where the event took place.")
647647
)
648648

@@ -660,37 +660,37 @@ class Report(TimeZoneModelMixin, models.Model):
660660
)
661661

662662
event_moment = models.CharField(
663-
max_length=32, choices=EVENT_MOMENT_CHOICES, null=True, blank=True,
663+
max_length=32, choices=EVENT_MOMENT_CHOICES, null=True,
664664
help_text=_("The moment of the day when the event took place.")
665665
)
666666

667667
bite_count = models.PositiveSmallIntegerField(
668-
null=True, blank=True,
668+
null=True, editable=False,
669669
help_text=_("Total number of bites reported.")
670670
)
671671

672672
head_bite_count = models.PositiveSmallIntegerField(
673-
null=True, blank=True,
673+
null=True,
674674
help_text=_("Number of bites reported in the head.")
675675
)
676676
left_arm_bite_count = models.PositiveSmallIntegerField(
677-
null=True, blank=True,
677+
null=True,
678678
help_text=_("Number of bites reported in the left arm.")
679679
)
680680
right_arm_bite_count = models.PositiveSmallIntegerField(
681-
null=True, blank=True,
681+
null=True,
682682
help_text=_("Number of bites reported in the right arm.")
683683
)
684684
chest_bite_count = models.PositiveSmallIntegerField(
685-
null=True, blank=True,
685+
null=True,
686686
help_text=_("Number of bites reported in the chest.")
687687
)
688688
left_leg_bite_count = models.PositiveSmallIntegerField(
689-
null=True, blank=True,
689+
null=True,
690690
help_text=_("Number of bites reported in the left leg.")
691691
)
692692
right_leg_bite_count = models.PositiveSmallIntegerField(
693-
null=True, blank=True,
693+
null=True,
694694
help_text=_("Number of bites reported in the right leg.")
695695
)
696696

@@ -711,20 +711,20 @@ class Report(TimeZoneModelMixin, models.Model):
711711
)
712712

713713
user_perceived_mosquito_specie = models.CharField(
714-
max_length=16, choices=MOSQUITO_SPECIE_CHOICES, null=True, blank=True,
714+
max_length=16, choices=MOSQUITO_SPECIE_CHOICES, null=True,
715715
help_text=_("The mosquito specie perceived by the user.")
716716
)
717717

718718
user_perceived_mosquito_thorax = models.CharField(
719-
max_length=16, choices=MOSQUITO_SPECIE_CHOICES, null=True, blank=True,
719+
max_length=16, choices=MOSQUITO_SPECIE_CHOICES, null=True,
720720
help_text=_("The species of mosquito that the thorax resembles, according to the user.")
721721
)
722722
user_perceived_mosquito_abdomen = models.CharField(
723-
max_length=16, choices=MOSQUITO_SPECIE_CHOICES, null=True, blank=True,
723+
max_length=16, choices=MOSQUITO_SPECIE_CHOICES, null=True,
724724
help_text=_("The species of mosquito that the abdomen resembles, according to the user.")
725725
)
726726
user_perceived_mosquito_legs = models.CharField(
727-
max_length=16, choices=MOSQUITO_SPECIE_CHOICES, null=True, blank=True,
727+
max_length=16, choices=MOSQUITO_SPECIE_CHOICES, null=True,
728728
help_text=_("The species of mosquito that the leg resembles, according to the user.")
729729
)
730730

@@ -747,23 +747,23 @@ class Report(TimeZoneModelMixin, models.Model):
747747
)
748748

749749
breeding_site_type = models.CharField(
750-
max_length=32, choices=BREEDING_SITE_TYPE_CHOICES, null=True, blank=True,
751-
help_text=_("Breedign site tpye.")
750+
max_length=32, choices=BREEDING_SITE_TYPE_CHOICES, null=True,
751+
help_text=_("Breeding site type.")
752752
)
753753
breeding_site_has_water = models.BooleanField(
754-
null=True, blank=True,
754+
null=True,
755755
help_text=_("Either if the user perceived water in the breeding site.")
756756
)
757757
breeding_site_in_public_area = models.BooleanField(
758-
null=True, blank=True,
758+
null=True,
759759
help_text=_("Either if the breeding site is found in a public area.")
760760
)
761761
breeding_site_has_near_mosquitoes = models.BooleanField(
762-
null=True, blank=True,
762+
null=True,
763763
help_text=_("Either if the user perceived mosquitoes near the breeding site (less than 10 meters).")
764764
)
765765
breeding_site_has_larvae = models.BooleanField(
766-
null=True, blank=True,
766+
null=True,
767767
help_text=_("Either if the user perceived larvaes the breeding site.")
768768
)
769769
# Object Manager
@@ -1490,17 +1490,24 @@ def save(self, *args, **kwargs):
14901490
if nuts2:
14911491
self.nuts_2 = nuts2.nuts_id
14921492

1493-
bite_fields = [
1494-
self.head_bite_count,
1495-
self.left_arm_bite_count,
1496-
self.right_arm_bite_count,
1497-
self.chest_bite_count,
1498-
self.left_leg_bite_count,
1499-
self.right_leg_bite_count
1493+
bite_fieldnames = [
1494+
'head_bite_count',
1495+
'left_arm_bite_count',
1496+
'right_arm_bite_count',
1497+
'chest_bite_count',
1498+
'left_leg_bite_count',
1499+
'right_leg_bite_count'
15001500
]
1501-
self.bite_count = sum(
1502-
f for f in bite_fields if f is not None
1503-
) if self.type == self.TYPE_BITE else None
1501+
1502+
if self.type == self.TYPE_BITE:
1503+
# Make sure all bites are set to 0 if none.
1504+
for bite_fieldname in bite_fieldnames:
1505+
if getattr(self, bite_fieldname) is None:
1506+
setattr(self, bite_fieldname, 0)
1507+
1508+
self.bite_count = sum(
1509+
getattr(self, fname) for fname in bite_fieldnames
1510+
)
15041511

15051512
super(Report, self).save(*args, **kwargs)
15061513

0 commit comments

Comments
 (0)