class PoliceWitnessAdmin(admin.ModelAdmin): search_fields = [ 'allegation__crid', 'officer__officer_first', 'officer__officer_last' ] list_display = ['allegation', 'race', 'gender', 'officer'] list_filter = ['race', 'gender'] actions = make_export_action("Export Police Witnesses to CSV")
class DocumentAdmin(admin.ModelAdmin): search_fields = ['title', 'type'] list_display = [ 'id', 'type', 'title', 'number_of_request', 'requested', 'pending', 'documentcloud_id' ] actions = make_export_action("Export Documents to CSV") ordering = ('-number_of_request', )
class OfficerAllegationAdmin(admin.ModelAdmin): search_fields = [ 'officer__officer_last', 'officer__officer_first', 'allegation__crid', 'allegation__investigator__name' ] list_filter = ['officer__race', 'officer__gender', 'cat__category'] list_display = [ 'allegation', 'cat', 'officer', 'final_finding', 'final_outcome' ] actions = make_export_action("Export Officer allegations to CSV")
class SuggestionAdmin(admin.ModelAdmin): search_fields = ['search_query', 'session_id'] list_filter = ['num_suggestions'] list_display = [ 'session_hash', 'search_query', 'num_suggestions', 'created_at' ] actions = make_export_action("Export Suggestions to CSV") def session_hash(self, obj): return obj.session_id[:6] def get_queryset(self, request): return SuggestionLog.objects.exclude(session_id__isnull=True).exclude( session_id__exact='')
class AliasAdmin(admin.ModelAdmin): list_display = ('id', 'alias', 'target') actions = make_export_action("Export Alias to CSV")
class ShareSessionAdmin(admin.ModelAdmin): search_fields = ['query'] list_display = [ 'hash_id', 'session_type', 'session_title', 'search_tags', 'shared_from', 'shared_to' ] actions = make_export_action("Export Shares to CSV") def format_as_session_link(self, obj): return format_html("<a href='/dashboard/share/session/{}'>{}</a>", obj.id, obj.hash_id) def shared_from(self, obj): if obj.share_from: return self.format_as_session_link(obj) else: return '' def session_type(self, obj): if obj.share_from or self.shared_to(obj): return 'Shared' else: return 'Fresh' def session_title(self, obj): if 'title' in obj.query: return obj.query['title'] else: return 'Chicago Police Database' def shared_to(self, obj): results = [] shared_tos = Session.objects.filter(share_from__exact=obj.id) for session in shared_tos: results.append(self.format_as_session_link(session)) return ', '.join(results) def search_tags(self, obj): tags = [] queries = [] if 'filters' in obj.query: queries = obj.query['filters'] for filter_type in queries: if 'value' in queries[filter_type]: for tag in queries[filter_type]['value']: tags.append(str(tag)) return ', '.join(tags) def get_queryset(self, request): return Session.objects.all() def get_search_results(self, request, queryset, search_term): queryset, use_distinct = super(ShareSessionAdmin, self).get_search_results( request, queryset, search_term) id = Session.id_from_hash(search_term) if id: queryset = Session.objects.filter(id=id[0]) return queryset, use_distinct shared_from.allow_tags = True shared_to.allow_tags = True
class StoryAdmin(admin.ModelAdmin): prepopulated_fields = {"slug": ("title", )} list_display = ('id', 'title', 'officer', 'created_date', 'custom_order') list_display_links = ('id', 'title') search_fields = ('title', ) actions = make_export_action("Export Officer Stories to CSV")
class InvestigatorAdmin(admin.ModelAdmin): list_display = ['id', 'name', 'current_rank', 'complaint_count'] actions = make_export_action("Export Investigators to CSV")
class OfficerAdmin(admin.ModelAdmin): list_display = ['id', 'officer_first', 'officer_last', 'gender', 'race'] list_filter = ['gender', 'race', 'unit', 'rank'] search_fields = ['officer_first', 'officer_last'] inlines = [OfficerHistoryInline, OfficerAllegationInline] actions = make_export_action("Export Officers to CSV")
class ComplainingWitnessAdmin(admin.ModelAdmin): search_fields = ['allegation__crid'] list_display = ['allegation', 'race', 'gender'] list_filter = ['race', 'gender'] actions = make_export_action("Export Complaining Witnesses to CSV")