Skip to content

Commit c26de1c

Browse files
committed
Report responses to report columns
1 parent 8297cee commit c26de1c

File tree

5 files changed

+1139
-143
lines changed

5 files changed

+1139
-143
lines changed

tigamap/templates/tigamap/report_map.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
'{{ report.tigaprob_text }}</td></tr><tr><td>cc score:</td><td>{{ score|floatformat:2 }}</td></tr><tr><td>lat:</td><td>{{ lat }}</td></tr><tr><td>lon:</td><td>{{ lon }}</td></tr></table>{{ report.get_validated_photo_html | safe }}';
111111
{% else %}
112112
popup_text = '<table><tr><td>{% trans 'type' %}:</td><td>'+
113-
'{{ report.site_type_trans }}</td></tr><tr><td>cc score:</td><td>{{ score|floatformat:2 }}</td></tr><tr><td>lat:</td><td>{{ lat }}</td></tr><tr><td>lon:</td><td>{{ report.lon }}</td></tr></table>{{ report.get_validated_photo_html | safe }}';
113+
'{{ report.breeding_site_type }}</td></tr><tr><td>cc score:</td><td>{{ score|floatformat:2 }}</td></tr><tr><td>lat:</td><td>{{ lat }}</td></tr><tr><td>lon:</td><td>{{ report.lon }}</td></tr></table>{{ report.get_validated_photo_html | safe }}';
114114
{% endif %}
115115

116116
{% endwith %}
@@ -123,7 +123,7 @@
123123
'{{ report.tigaprob_text }}</td></tr><tr><td>lat:</td><td>{{ lat }}</td></tr><tr><td>lon:</td><td>{{ lon }}</td></tr></table>';
124124
{% else %}
125125
popup_text = '<table><tr><td>{% trans 'type' %}:</td><td>'+
126-
'{{ report.site_type_trans }}</td></tr><tr><td>lat:</td><td>{{ lat }}</td></tr><tr><td>lon:</td><td>{{ report.lon }}</td></tr></table>';
126+
'{{ report.breeding_site_type }}</td></tr><tr><td>lat:</td><td>{{ lat }}</td></tr><tr><td>lon:</td><td>{{ report.lon }}</td></tr></table>';
127127
{% endif %}
128128
{% endif %}
129129
{% if detailed == 'detailed' %}

tigaserver_app/admin.py

Lines changed: 134 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from django.utils.encoding import smart_str
88
from django.http.response import HttpResponse
99
from django.utils.html import mark_safe
10+
from django.utils.translation import ugettext_lazy as _
1011

1112

1213
def export_full_csv(modeladmin, request, queryset):
@@ -107,40 +108,148 @@ class PhotoInline(admin.StackedInline):
107108

108109

109110
class ReportAdmin(admin.ModelAdmin):
110-
list_display = ('report_id', 'deleted', 'user', 'version_number', 'creation_time', 'version_time', 'type', 'mission',
111-
'package_version', 'os', 'n_photos', 'map_link', 'movelab_score', 'crowd_score')
112-
inlines = [ReportResponseInline, PhotoInline]
113-
ordering = ('creation_time', 'report_id', 'version_number')
114-
readonly_fields = ('deleted', 'version_UUID', 'user', 'report_id', 'version_number', 'other_versions_of_this_report', 'creation_time', 'version_time', 'server_upload_time', 'updated_at', 'datetime_fix_offset', 'phone_upload_time', 'type', 'mission', 'location_choice', 'current_location_lon', 'current_location_lat', 'selected_location_lon', 'selected_location_lat', 'note', 'package_name', 'package_version', 'device_manufacturer', 'device_model', 'os', 'os_version', 'os_language', 'app_language', 'n_photos', 'lon', 'lat', 'tigaprob', 'tigaprob_text', 'site_type', 'site_type_trans', 'embornals', 'fonts', 'basins', 'buckets', 'wells', 'other', 'masked_lat', 'masked_lon', 'map_link', 'movelab_score', 'crowd_score')
115-
fields = ('hide', 'deleted', 'map_link', 'version_UUID', 'user', 'report_id', 'version_number', 'other_versions_of_this_report', ('creation_time', 'version_time', 'datetime_fix_offset'), ('server_upload_time','phone_upload_time'), 'updated_at', 'type', 'mission', 'location_choice', 'current_location_lon', 'current_location_lat', 'selected_location_lon', 'selected_location_lat', 'note', 'package_name', 'package_version', 'device_manufacturer', 'device_model', 'os', 'os_version', 'os_language', 'app_language', 'n_photos', 'lon', 'lat', 'tigaprob', 'tigaprob_text', 'site_type', 'site_type_trans', 'embornals', 'fonts', 'basins', 'buckets', 'wells', 'other', 'masked_lat', 'masked_lon', 'movelab_score', 'crowd_score')
111+
list_display = (
112+
'report_id', 'deleted', 'user', 'version_number', 'creation_time', 'version_time', 'type', 'mission',
113+
'package_version', 'os', 'n_photos'
114+
)
116115
list_filter = ['os', 'type', 'mission', 'package_name', 'package_version']
116+
117+
inlines = [ReportResponseInline, PhotoInline]
117118
actions = [export_full_csv, export_full_csv_sc]
118119

119-
def has_add_permission(self, request):
120-
return False
120+
readonly_fields = [
121+
"deleted",
122+
"report_id",
123+
"version_number",
124+
"type",
125+
"user",
126+
"mission",
127+
"session",
128+
"server_upload_time",
129+
"updated_at",
130+
"version_time",
131+
"phone_upload_time",
132+
"creation_time"
133+
]
134+
135+
fieldsets = [
136+
(
137+
_('General info'),
138+
{
139+
"fields": [
140+
("report_id", "version_number"),
141+
("hide", "deleted"),
142+
"type",
143+
"user",
144+
("mission","session"),
145+
("server_upload_time", "updated_at"),
146+
"version_time",
147+
("creation_time", "phone_upload_time")
148+
]
149+
}
150+
),
151+
(
152+
_("Location information"),
153+
{
154+
"fields": [
155+
("country", "nuts_2", "nuts_3"),
156+
"location_choice",
157+
"point"
158+
]
159+
}
160+
),
161+
(
162+
_("Other"),
163+
{
164+
"fields": [
165+
("package_name", "package_version", "app_language"),
166+
("device_manufacturer", "device_model"),
167+
("os", "os_version", "os_language")
168+
],
169+
"classes": ["collapse",]
170+
}
171+
)
172+
]
173+
174+
def get_readonly_fields(self, request, obj=None):
175+
# Only allow to edit 'hide' field.
176+
result = super().get_readonly_fields(request, obj)
177+
178+
readonly_fields = [field.name for field in self.model._meta.get_fields()]
179+
allow_edit_fields = ['hide',]
180+
181+
for field_name in readonly_fields:
182+
if not field_name in allow_edit_fields:
183+
result.append(field_name)
121184

122-
def has_delete_permission(self, request, obj=None):
123-
return False
185+
return result
124186

125-
def other_versions_of_this_report(self, obj):
126-
result = []
127-
for this_version in obj.other_versions:
128-
result += '<a href="/admin/tigaserver_app/report/%s">Version %s</a> ' % (
129-
this_version.version_UUID,
130-
this_version.version_number,
187+
def get_fieldsets(self, request, obj = None):
188+
result = super().get_fieldsets(request, obj)
189+
190+
if not obj:
191+
return result
192+
193+
extra_fieldsets = []
194+
if obj.type == Report.TYPE_ADULT:
195+
extra_fieldsets.append(
196+
(
197+
_("Classification"),
198+
{
199+
"fields": [
200+
"ia_filter_1", "ia_filter_2"
201+
]
202+
}
203+
)
204+
)
205+
extra_fieldsets.append(
206+
(
207+
_("Specific information"),
208+
{
209+
"fields": [
210+
("event_environment", "event_moment"),
211+
"user_perceived_mosquito_specie",
212+
("user_perceived_mosquito_thorax", "user_perceived_mosquito_abdomen", "user_perceived_mosquito_legs")
213+
]
214+
}
215+
)
216+
)
217+
elif obj.type == Report.TYPE_BITE:
218+
extra_fieldsets.append(
219+
(
220+
_("Specific information"),
221+
{
222+
"fields": [
223+
("event_environment", "event_moment"),
224+
"bite_count",
225+
("head_bite_count", "left_arm_bite_count", "right_arm_bite_count", "chest_bite_count", "left_leg_bite_count", "right_leg_bite_count")
226+
]
227+
}
228+
)
229+
)
230+
elif obj.type == Report.TYPE_SITE:
231+
extra_fieldsets.append(
232+
(
233+
_("Specific information"),
234+
{
235+
"fields": [
236+
"breeding_site_type",
237+
"breeding_site_has_water",
238+
"breeding_site_in_public_area",
239+
"breeding_site_has_near_mosquitoes",
240+
"breeding_site_has_larvae"
241+
]
242+
}
243+
)
131244
)
132-
return result
133-
other_versions_of_this_report.allow_tags = True
134245

135-
def movelab_score(self, obj):
136-
return obj.movelab_score
246+
return result + extra_fieldsets
137247

138-
def crowd_score(self, obj):
139-
return obj.crowd_score
248+
def has_add_permission(self, request):
249+
return False
140250

141-
def map_link(self, obj):
142-
return '<a href="/single_report_map/%s/">Show map</a>' % obj.version_UUID
143-
map_link.allow_tags = True
251+
def has_delete_permission(self, request, obj=None):
252+
return False
144253

145254

146255
def export_csv_photo(modeladmin, request, queryset):
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Generated by Django 2.2.7 on 2024-02-12 15:12
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('tigaserver_app', '0043_auto_20240124_1254'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='report',
15+
name='breeding_site_has_larvae',
16+
field=models.BooleanField(blank=True, help_text='Either if the user perceived larvaes the breeding site.', null=True),
17+
),
18+
migrations.AddField(
19+
model_name='report',
20+
name='breeding_site_has_near_mosquitoes',
21+
field=models.BooleanField(blank=True, help_text='Either if the user perceived mosquitoes near the breeding site.', null=True),
22+
),
23+
migrations.AddField(
24+
model_name='report',
25+
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),
27+
),
28+
migrations.AddField(
29+
model_name='report',
30+
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),
32+
),
33+
migrations.AddField(
34+
model_name='report',
35+
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),
37+
),
38+
migrations.AddField(
39+
model_name='report',
40+
name='chest_bite_count',
41+
field=models.PositiveSmallIntegerField(blank=True, help_text='Number of bites reported in the chest.', null=True),
42+
),
43+
migrations.AddField(
44+
model_name='report',
45+
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),
47+
),
48+
migrations.AddField(
49+
model_name='report',
50+
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),
52+
),
53+
migrations.AddField(
54+
model_name='report',
55+
name='head_bite_count',
56+
field=models.PositiveSmallIntegerField(blank=True, help_text='Number of bites reported in the head.', null=True),
57+
),
58+
migrations.AddField(
59+
model_name='report',
60+
name='left_arm_bite_count',
61+
field=models.PositiveSmallIntegerField(blank=True, help_text='Number of bites reported in the left arm.', null=True),
62+
),
63+
migrations.AddField(
64+
model_name='report',
65+
name='left_leg_bite_count',
66+
field=models.PositiveSmallIntegerField(blank=True, help_text='Number of bites reported in the left leg.', null=True),
67+
),
68+
migrations.AddField(
69+
model_name='report',
70+
name='right_arm_bite_count',
71+
field=models.PositiveSmallIntegerField(blank=True, help_text='Number of bites reported in the right arm.', null=True),
72+
),
73+
migrations.AddField(
74+
model_name='report',
75+
name='right_leg_bite_count',
76+
field=models.PositiveSmallIntegerField(blank=True, help_text='Number of bites reported in the right leg.', null=True),
77+
),
78+
migrations.AddField(
79+
model_name='report',
80+
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),
82+
),
83+
migrations.AddField(
84+
model_name='report',
85+
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),
87+
),
88+
migrations.AddField(
89+
model_name='report',
90+
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),
92+
),
93+
migrations.AddField(
94+
model_name='report',
95+
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),
97+
),
98+
migrations.AddField(
99+
model_name='report',
100+
name='bite_count',
101+
field=models.PositiveSmallIntegerField(blank=True, help_text='Total number of bites reported.', null=True),
102+
),
103+
]

0 commit comments

Comments
 (0)