Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions tigacrafting/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1310,20 +1310,7 @@
return new_reports_unfiltered_sites_other

def get_reports_imbornal():
reports_imbornal = ReportResponse.objects.filter(
Q(question='Is this a storm drain or sewer?', answer='Yes') | Q(question=u'\xc9s un embornal o claveguera?',
answer=u'S\xed') | Q(
question=u'\xbfEs un imbornal o alcantarilla?', answer=u'S\xed') | Q(question='Selecciona lloc de cria',
answer='Embornals') | Q(
question='Selecciona lloc de cria', answer='Embornal o similar') | Q(question='Tipo de lugar de cría',
answer='Sumidero o imbornal') | Q(
question='Tipo de lugar de cría', answer='Sumideros') | Q(question='Type of breeding site',
answer='Storm drain') | Q(
question='Type of breeding site', answer='Storm drain or similar receptacle')).values('report').distinct()

reports_imbornal_new = ReportResponse.objects.filter(question_id=12).filter(answer_id=121).values('report').distinct()

return reports_imbornal | reports_imbornal_new
return Report.objects.filter(breeding_site_type=Report.BREEDING_SITE_TYPE_STORM_DRAIN)

Check warning on line 1313 in tigacrafting/views.py

View check run for this annotation

Codecov / codecov/patch

tigacrafting/views.py#L1313

Added line #L1313 was not covered by tests

def get_reports_unfiltered_adults_except_being_validated():
new_reports_unfiltered_adults = Report.objects.exclude(creation_time__year=2014).exclude(type='site').exclude(note__icontains='#345').exclude(photos=None).annotate(n_annotations=Count('expert_report_annotations')).filter(n_annotations=0).order_by('-server_upload_time')
Expand Down
4 changes: 2 additions & 2 deletions tigamap/templates/tigamap/report_map.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
'{{ 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 }}';
{% else %}
popup_text = '<table><tr><td>{% trans 'type' %}:</td><td>'+
'{{ 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 }}';
'{{ 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 }}';
{% endif %}

{% endwith %}
Expand All @@ -123,7 +123,7 @@
'{{ report.tigaprob_text }}</td></tr><tr><td>lat:</td><td>{{ lat }}</td></tr><tr><td>lon:</td><td>{{ lon }}</td></tr></table>';
{% else %}
popup_text = '<table><tr><td>{% trans 'type' %}:</td><td>'+
'{{ report.site_type_trans }}</td></tr><tr><td>lat:</td><td>{{ lat }}</td></tr><tr><td>lon:</td><td>{{ report.lon }}</td></tr></table>';
'{{ report.breeding_site_type }}</td></tr><tr><td>lat:</td><td>{{ lat }}</td></tr><tr><td>lon:</td><td>{{ report.lon }}</td></tr></table>';
{% endif %}
{% endif %}
{% if detailed == 'detailed' %}
Expand Down
47 changes: 7 additions & 40 deletions tigascoring/xp_scoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,12 @@
SITE_STORM_DRAIN_REWARD = 4
BREEDING_SITE_MOSQUITO_REWARD = 3

MOSQUITO_HOW_LOOKS_QUESTION_ID = 7
MOSQUITO_THORAX_ANSWER_IDS = [711, 712, 713, 714]
MOSQUITO_ABDOMEN_ANSWER_IDS = [721, 722, 723, 724]
MOSQUITO_LEG_ANSWER_IDS = [731, 732, 733, 734]

MOSQUITO_BITE_QUESTION_ID = 8
MOSQUITO_BITE_ANSWER_ID = 101

BREEDING_SITE_MOSQUITO_QUESTION_ID = 11
BREEDING_SITE_MOSQUITO_ANSWER_ID = 101

SITE_WATER_QUESTION_ID = 10
SITE_WATER_ANSWER_IDS = [81, 101]

STORM_DRAIN_QUESTION_ID = 12
STORM_DRAIN_ANSWER_ID = 121

CULEX_CATEGORY_ID = 10
AEDES_CATEGORY_IDS = [4, 5, 6, 7]

Expand Down Expand Up @@ -88,53 +77,31 @@


def is_thorax_answered(report):
for response in report.responses.all():
if response.question_id == MOSQUITO_HOW_LOOKS_QUESTION_ID and response.answer_id in MOSQUITO_THORAX_ANSWER_IDS:
return True
return False
return report.user_perceived_mosquito_thorax is not None


def is_abdomen_answered(report):
for response in report.responses.all():
if response.question_id == MOSQUITO_HOW_LOOKS_QUESTION_ID and response.answer_id in MOSQUITO_ABDOMEN_ANSWER_IDS:
return True
return False
return report.user_perceived_mosquito_abdomen is not None


def is_leg_answered(report):
for response in report.responses.all():
if response.question_id == MOSQUITO_HOW_LOOKS_QUESTION_ID and response.answer_id in MOSQUITO_LEG_ANSWER_IDS:
return True
return False
return report.user_perceived_mosquito_legs is not None


def is_water_answered(report):
for response in report.responses.all():
if response.question_id == SITE_WATER_QUESTION_ID and response.answer_id in SITE_WATER_ANSWER_IDS:
return True
return False
return report.breeding_site_has_water is not None

Check warning on line 92 in tigascoring/xp_scoring.py

View check run for this annotation

Codecov / codecov/patch

tigascoring/xp_scoring.py#L92

Added line #L92 was not covered by tests


def is_bite_report_followed(report):
for response in report.responses.all():
if response.question_id == MOSQUITO_BITE_QUESTION_ID and response.answer_id == MOSQUITO_BITE_ANSWER_ID:
return True
return False
return report.responses.filter(question_id=MOSQUITO_BITE_QUESTION_ID, answer_id=MOSQUITO_BITE_ANSWER_ID).exists()


def is_mosquito_report_followed(report):
for response in report.responses.all():
if response.question_id == BREEDING_SITE_MOSQUITO_QUESTION_ID and response.answer_id == BREEDING_SITE_MOSQUITO_ANSWER_ID:
return True
return False
return report.responses.filter(question_id=BREEDING_SITE_MOSQUITO_QUESTION_ID, answer_id=BREEDING_SITE_MOSQUITO_ANSWER_ID).exists()

Check warning on line 100 in tigascoring/xp_scoring.py

View check run for this annotation

Codecov / codecov/patch

tigascoring/xp_scoring.py#L100

Added line #L100 was not covered by tests


def is_storm_drain(report):
for response in report.responses.all():
if response.question_id == STORM_DRAIN_QUESTION_ID and response.answer_id == STORM_DRAIN_ANSWER_ID:
return True
return False

return report.breeding_site_type == Report.BREEDING_SITE_TYPE_STORM_DRAIN

Check warning on line 104 in tigascoring/xp_scoring.py

View check run for this annotation

Codecov / codecov/patch

tigascoring/xp_scoring.py#L104

Added line #L104 was not covered by tests

def is_culex(validation_result):
if validation_result['category'] is not None:
Expand Down
163 changes: 142 additions & 21 deletions tigaserver_app/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.utils.encoding import smart_str
from django.http.response import HttpResponse
from django.utils.html import mark_safe
from django.utils.translation import ugettext_lazy as _


def export_full_csv(modeladmin, request, queryset):
Expand Down Expand Up @@ -116,43 +117,163 @@


class ReportAdmin(admin.ModelAdmin):
list_display = ('version_UUID', 'report_id', 'deleted', 'user', 'version_number', 'creation_time', 'version_time', 'type', 'mission',
'package_version', 'os', 'n_photos', 'map_link', 'movelab_score', 'crowd_score')
inlines = [ReportResponseInline, PhotoInline]
ordering = ('creation_time', 'report_id', 'version_number')
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')
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')
search_fields = ('version_UUID',)
list_display = (
'version_UUID', 'report_id', 'deleted', 'user', 'version_number', 'creation_time', 'version_time', 'type', 'mission',
'package_version', 'os', 'n_photos'
)
list_filter = ['os', 'type', 'mission', 'package_name', 'package_version']
search_fields = ('version_UUID',)

inlines = [ReportResponseInline, PhotoInline]
actions = [export_full_csv, export_full_csv_sc]

readonly_fields = [
"deleted",
"report_id",
"version_number",
"type",
"user",
"mission",
"session",
"server_upload_time",
"updated_at",
"version_time",
"phone_upload_time",
"creation_time",
"other_versions_of_this_report"
]

fieldsets = [
(
_('General info'),
{
"fields": [
("report_id", "version_number"),
("hide", "deleted"),
"type",
"user",
("mission","session"),
"other_versions_of_this_report",
("server_upload_time", "updated_at"),
("version_time", "datetime_fix_offset"),
("creation_time", "phone_upload_time")
]
}
),
(
_("Location information"),
{
"fields": [
("country", "nuts_2", "nuts_3"),
"location_choice",
"point"
]
}
),
(
_("Other"),
{
"fields": [
("package_name", "package_version", "app_language"),
("device_manufacturer", "device_model"),
("os", "os_version", "os_language"),
"note"
],
"classes": ["collapse",]
}
)
]

def get_readonly_fields(self, request, obj=None):
# Only allow to edit 'hide' field.
result = super().get_readonly_fields(request, obj)

Check warning on line 189 in tigaserver_app/admin.py

View check run for this annotation

Codecov / codecov/patch

tigaserver_app/admin.py#L189

Added line #L189 was not covered by tests

readonly_fields = [field.name for field in self.model._meta.get_fields()]
allow_edit_fields = ['hide',]

Check warning on line 192 in tigaserver_app/admin.py

View check run for this annotation

Codecov / codecov/patch

tigaserver_app/admin.py#L191-L192

Added lines #L191 - L192 were not covered by tests

for field_name in readonly_fields:
if not field_name in allow_edit_fields:
result.append(field_name)

Check warning on line 196 in tigaserver_app/admin.py

View check run for this annotation

Codecov / codecov/patch

tigaserver_app/admin.py#L194-L196

Added lines #L194 - L196 were not covered by tests

return result

Check warning on line 198 in tigaserver_app/admin.py

View check run for this annotation

Codecov / codecov/patch

tigaserver_app/admin.py#L198

Added line #L198 was not covered by tests

def get_fieldsets(self, request, obj = None):
result = super().get_fieldsets(request, obj)

Check warning on line 201 in tigaserver_app/admin.py

View check run for this annotation

Codecov / codecov/patch

tigaserver_app/admin.py#L201

Added line #L201 was not covered by tests

if not obj:
return result

Check warning on line 204 in tigaserver_app/admin.py

View check run for this annotation

Codecov / codecov/patch

tigaserver_app/admin.py#L203-L204

Added lines #L203 - L204 were not covered by tests

extra_fieldsets = []
if obj.type == Report.TYPE_ADULT:
extra_fieldsets.append(

Check warning on line 208 in tigaserver_app/admin.py

View check run for this annotation

Codecov / codecov/patch

tigaserver_app/admin.py#L206-L208

Added lines #L206 - L208 were not covered by tests
(
_("Classification"),
{
"fields": [
"ia_filter_1", "ia_filter_2"
]
}
)
)
extra_fieldsets.append(

Check warning on line 218 in tigaserver_app/admin.py

View check run for this annotation

Codecov / codecov/patch

tigaserver_app/admin.py#L218

Added line #L218 was not covered by tests
(
_("Specific information"),
{
"fields": [
("event_environment", "event_moment"),
"user_perceived_mosquito_specie",
("user_perceived_mosquito_thorax", "user_perceived_mosquito_abdomen", "user_perceived_mosquito_legs")
]
}
)
)
elif obj.type == Report.TYPE_BITE:
extra_fieldsets.append(

Check warning on line 231 in tigaserver_app/admin.py

View check run for this annotation

Codecov / codecov/patch

tigaserver_app/admin.py#L230-L231

Added lines #L230 - L231 were not covered by tests
(
_("Specific information"),
{
"fields": [
("event_environment", "event_moment"),
"bite_count",
("head_bite_count", "left_arm_bite_count", "right_arm_bite_count", "chest_bite_count", "left_leg_bite_count", "right_leg_bite_count")
]
}
)
)
elif obj.type == Report.TYPE_SITE:
extra_fieldsets.append(

Check warning on line 244 in tigaserver_app/admin.py

View check run for this annotation

Codecov / codecov/patch

tigaserver_app/admin.py#L243-L244

Added lines #L243 - L244 were not covered by tests
(
_("Specific information"),
{
"fields": [
"breeding_site_type",
"breeding_site_has_water",
"breeding_site_in_public_area",
"breeding_site_has_near_mosquitoes",
"breeding_site_has_larvae"
]
}
)
)

return result + extra_fieldsets

Check warning on line 259 in tigaserver_app/admin.py

View check run for this annotation

Codecov / codecov/patch

tigaserver_app/admin.py#L259

Added line #L259 was not covered by tests

def has_add_permission(self, request):
return False

def has_delete_permission(self, request, obj=None):
return False

def other_versions_of_this_report(self, obj):
result = []
result = ""

Check warning on line 268 in tigaserver_app/admin.py

View check run for this annotation

Codecov / codecov/patch

tigaserver_app/admin.py#L268

Added line #L268 was not covered by tests
for this_version in obj.other_versions:
result += '<a href="/admin/tigaserver_app/report/%s">Version %s</a> ' % (
this_version.version_UUID,
this_version.version_number,
)
return result
return mark_safe(result)

Check warning on line 274 in tigaserver_app/admin.py

View check run for this annotation

Codecov / codecov/patch

tigaserver_app/admin.py#L274

Added line #L274 was not covered by tests
other_versions_of_this_report.allow_tags = True

def movelab_score(self, obj):
return obj.movelab_score

def crowd_score(self, obj):
return obj.crowd_score

def map_link(self, obj):
return '<a href="/single_report_map/%s/">Show map</a>' % obj.version_UUID
map_link.allow_tags = True


def export_csv_photo(modeladmin, request, queryset):
response = HttpResponse(mimetype='text/csv')
response['Content-Disposition'] = 'attachment; filename=tigatrapp_photos.csv'
Expand Down Expand Up @@ -247,7 +368,7 @@
this_version.version_UUID,
this_version.version_number,
)
return result
return mark_safe(result)

Check warning on line 371 in tigaserver_app/admin.py

View check run for this annotation

Codecov / codecov/patch

tigaserver_app/admin.py#L371

Added line #L371 was not covered by tests
other_report_versions.allow_tags = True

def map_link(self, obj):
Expand Down
Loading
Loading