2020-11-24 12:44:07 +00:00
|
|
|
import csv
|
|
|
|
|
2020-09-21 12:27:16 +00:00
|
|
|
from django.contrib import admin
|
2020-11-24 12:44:07 +00:00
|
|
|
from django.http import HttpResponse
|
2020-09-21 12:27:16 +00:00
|
|
|
|
2021-07-08 06:00:28 +00:00
|
|
|
from .models import Account, Project, HonoraryCertificate, Library, IFG, Travel,\
|
2021-01-04 09:58:47 +00:00
|
|
|
Email, BusinessCard, List, Literature
|
2020-10-06 12:55:46 +00:00
|
|
|
|
2020-11-24 12:44:07 +00:00
|
|
|
|
|
|
|
def export_as_csv(self, request, queryset):
|
|
|
|
|
|
|
|
meta = self.model._meta
|
|
|
|
field_names = [field.name for field in meta.fields]
|
|
|
|
|
|
|
|
response = HttpResponse(content_type='text/csv')
|
|
|
|
response['Content-Disposition'] = 'attachment; filename={}.csv'.format(meta)
|
|
|
|
writer = csv.writer(response)
|
|
|
|
|
|
|
|
writer.writerow(field_names)
|
|
|
|
for obj in queryset:
|
|
|
|
row = writer.writerow([getattr(obj, field) for field in field_names])
|
|
|
|
|
|
|
|
return response
|
|
|
|
|
|
|
|
export_as_csv.short_description = "Export Selected"
|
|
|
|
|
|
|
|
admin.site.add_action(export_as_csv)
|
|
|
|
|
2020-10-06 11:17:28 +00:00
|
|
|
@admin.register(Project)
|
|
|
|
class ProjectAdmin(admin.ModelAdmin):
|
2020-11-19 13:41:31 +00:00
|
|
|
save_as = True
|
2022-11-03 17:02:39 +00:00
|
|
|
search_fields = ('name', 'pid','finance_id', 'realname', 'start', 'end', 'participants_estimated', 'participants_real', 'cost', 'status')
|
|
|
|
list_display = ('name', 'pid','finance_id', 'realname', 'start', 'end', 'participants_estimated', 'participants_real', 'cost', 'status')
|
2020-11-24 12:44:07 +00:00
|
|
|
# action = ['export_as_csv']
|
2022-11-04 11:18:09 +00:00
|
|
|
date_hierarchy = 'start'
|
2020-11-24 12:44:07 +00:00
|
|
|
|
2022-11-15 16:57:01 +00:00
|
|
|
|
2022-11-03 17:02:39 +00:00
|
|
|
@admin.register(BusinessCard)
|
|
|
|
class BusinessCardAdmin(admin.ModelAdmin):
|
2022-11-04 11:18:09 +00:00
|
|
|
save_as = True
|
2022-12-02 16:04:11 +00:00
|
|
|
search_fields = ('realname', 'service_id', 'granted', 'granted_date', 'project')
|
2022-11-03 17:02:39 +00:00
|
|
|
list_display = ('realname', 'service_id', 'granted', 'granted_date', 'project')
|
2022-11-04 11:18:09 +00:00
|
|
|
list_display_links = ('realname', 'service_id')
|
2022-11-03 17:02:39 +00:00
|
|
|
# action = ['export_as_csv']
|
2022-11-17 17:39:43 +00:00
|
|
|
date_hierarchy = 'granted_date'
|
2022-11-11 08:28:46 +00:00
|
|
|
class Media:
|
|
|
|
js = ('dropdown/js/base.js',)
|
|
|
|
|
2022-11-15 16:57:01 +00:00
|
|
|
@admin.register(Literature)
|
|
|
|
class LiteratureAdmin(admin.ModelAdmin):
|
2022-11-17 17:39:43 +00:00
|
|
|
save_as = True
|
2022-12-02 16:04:11 +00:00
|
|
|
search_fields = ('realname', 'service_id', 'granted', 'granted_date')
|
2022-11-17 17:39:43 +00:00
|
|
|
list_display = ('realname', 'service_id', 'granted', 'granted_date')
|
|
|
|
list_display_links = ('realname', 'service_id')
|
|
|
|
date_hierarchy = 'granted_date'
|
2022-11-15 16:57:01 +00:00
|
|
|
class Media:
|
|
|
|
js = ('dropdown/js/base.js',)
|
2022-11-11 08:28:46 +00:00
|
|
|
|
2022-11-04 11:18:09 +00:00
|
|
|
|
2022-11-17 17:39:43 +00:00
|
|
|
@admin.register(Account)
|
|
|
|
class AccountAdmin(admin.ModelAdmin):
|
|
|
|
save_as = True
|
|
|
|
|
|
|
|
|
|
|
|
@admin.register(HonoraryCertificate)
|
|
|
|
class HonoraryCertificateAdmin(admin.ModelAdmin):
|
|
|
|
save_as = True
|
|
|
|
search_fields = ('realname', 'granted', 'granted_date', 'project')
|
|
|
|
list_display = ('realname', 'granted', 'granted_date', 'project')
|
|
|
|
list_display_links = ('realname', 'project')
|
|
|
|
date_hierarchy = 'granted_date'
|
|
|
|
|
|
|
|
@admin.register(Library)
|
|
|
|
class LibraryAdmin(admin.ModelAdmin):
|
|
|
|
save_as = True
|
2022-12-02 16:04:11 +00:00
|
|
|
search_fields = ('realname', 'service_id', 'granted', 'granted_date')
|
2022-11-17 17:39:43 +00:00
|
|
|
list_display = ('realname', 'service_id', 'granted', 'granted_date')
|
|
|
|
list_display_links = ('realname', 'service_id')
|
|
|
|
date_hierarchy = 'granted_date'
|
|
|
|
|
|
|
|
@admin.register(IFG)
|
|
|
|
class IFGAdmin(admin.ModelAdmin):
|
|
|
|
save_as = True
|
2022-12-02 16:04:11 +00:00
|
|
|
search_fields = ('realname', 'service_id', 'granted', 'granted_date')
|
2022-11-17 17:39:43 +00:00
|
|
|
list_display = ('realname', 'service_id', 'granted', 'granted_date')
|
|
|
|
list_display_links = ('realname', 'service_id')
|
|
|
|
date_hierarchy = 'granted_date'
|
|
|
|
|
|
|
|
@admin.register(Travel)
|
|
|
|
class TravelAdmin(admin.ModelAdmin):
|
|
|
|
save_as = True
|
|
|
|
search_fields = ('realname', 'granted', 'granted_date', 'project')
|
|
|
|
list_display = ('realname', 'granted', 'granted_date', 'project')
|
|
|
|
list_display_links = ('realname', 'project')
|
|
|
|
date_hierarchy = 'granted_date'
|
|
|
|
|
|
|
|
@admin.register(Email)
|
|
|
|
class EmailAdmin(admin.ModelAdmin):
|
|
|
|
save_as = True
|
2022-12-02 16:04:11 +00:00
|
|
|
search_fields = ('realname', 'service_id', 'granted', 'granted_date')
|
2022-11-17 17:39:43 +00:00
|
|
|
list_display = ('realname', 'service_id', 'granted', 'granted_date')
|
|
|
|
list_display_links = ('realname', 'service_id')
|
|
|
|
date_hierarchy = 'granted_date'
|
|
|
|
|
2020-10-06 11:17:28 +00:00
|
|
|
|
2022-11-17 17:39:43 +00:00
|
|
|
@admin.register(List)
|
|
|
|
class ListAdmin(admin.ModelAdmin):
|
|
|
|
save_as = True
|
2022-12-02 16:04:11 +00:00
|
|
|
search_fields = ('realname', 'service_id', 'granted', 'granted_date')
|
2022-11-17 17:39:43 +00:00
|
|
|
list_display = ('realname', 'service_id', 'granted', 'granted_date')
|
|
|
|
list_display_links = ('realname', 'service_id')
|
|
|
|
date_hierarchy = 'granted_date'
|
|
|
|
|
|
|
|
# commented out because of the individual registering to control displays in admin panel
|
|
|
|
|
|
|
|
#admin.site.register([
|
|
|
|
# Account,
|
|
|
|
# HonoraryCertificate,
|
|
|
|
# Library,
|
|
|
|
# IFG,
|
|
|
|
# Travel,
|
|
|
|
# Email,
|
|
|
|
# List,
|
|
|
|
# ])
|