|
7 | 7 | from django.utils.encoding import smart_str |
8 | 8 | from django.http.response import HttpResponse |
9 | 9 | from django.utils.html import mark_safe |
| 10 | +from django.utils.translation import ugettext_lazy as _ |
10 | 11 |
|
11 | 12 |
|
12 | 13 | def export_full_csv(modeladmin, request, queryset): |
@@ -107,40 +108,148 @@ class PhotoInline(admin.StackedInline): |
107 | 108 |
|
108 | 109 |
|
109 | 110 | 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 | + ) |
116 | 115 | list_filter = ['os', 'type', 'mission', 'package_name', 'package_version'] |
| 116 | + |
| 117 | + inlines = [ReportResponseInline, PhotoInline] |
117 | 118 | actions = [export_full_csv, export_full_csv_sc] |
118 | 119 |
|
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) |
121 | 184 |
|
122 | | - def has_delete_permission(self, request, obj=None): |
123 | | - return False |
| 185 | + return result |
124 | 186 |
|
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 | + ) |
131 | 244 | ) |
132 | | - return result |
133 | | - other_versions_of_this_report.allow_tags = True |
134 | 245 |
|
135 | | - def movelab_score(self, obj): |
136 | | - return obj.movelab_score |
| 246 | + return result + extra_fieldsets |
137 | 247 |
|
138 | | - def crowd_score(self, obj): |
139 | | - return obj.crowd_score |
| 248 | + def has_add_permission(self, request): |
| 249 | + return False |
140 | 250 |
|
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 |
144 | 253 |
|
145 | 254 |
|
146 | 255 | def export_csv_photo(modeladmin, request, queryset): |
|
0 commit comments