2020-11-24 13:44:07 +01:00
|
|
|
import csv
|
|
|
|
|
2020-09-21 14:27:16 +02:00
|
|
|
from django.contrib import admin
|
2020-11-24 13:44:07 +01:00
|
|
|
from django.http import HttpResponse
|
2020-09-21 14:27:16 +02:00
|
|
|
|
2021-07-08 08:00:28 +02:00
|
|
|
from .models import Account, Project, HonoraryCertificate, Library, IFG, Travel,\
|
2021-01-04 10:58:47 +01:00
|
|
|
Email, BusinessCard, List, Literature
|
2020-10-06 14:55:46 +02:00
|
|
|
|
2020-11-24 13:44:07 +01: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
|
|
|
|
|
2022-12-04 17:40:23 +01:00
|
|
|
export_as_csv.short_description = "Ausgewähltes zu CSV exportieren"
|
2020-11-24 13:44:07 +01:00
|
|
|
|
|
|
|
admin.site.add_action(export_as_csv)
|
|
|
|
|
2020-10-06 13:17:28 +02:00
|
|
|
@admin.register(Project)
|
|
|
|
class ProjectAdmin(admin.ModelAdmin):
|
2020-11-19 14:41:31 +01:00
|
|
|
save_as = True
|
2022-12-07 14:56:22 +01:00
|
|
|
search_fields = ('name', 'pid','finance_id', 'realname', 'start', 'end', 'participants_estimated', 'participants_real', 'cost', 'status', 'end_quartal')
|
|
|
|
list_display = ('name', 'pid','finance_id', 'realname', 'start', 'end', 'participants_estimated', 'participants_real', 'cost', 'status', 'end_quartal')
|
2022-12-09 19:54:58 +01:00
|
|
|
fields = ('realname', 'email', 'granted', 'granted_date', 'mail_state', 'end_mail_send', 'survey_mail_send', 'survey_mail_date', 'name', 'description', 'pid', 'finance_id', 'start', 'end', 'otrs', 'plan', 'page', 'urls', 'group', 'location', 'participants_estimated', 'participants_real', 'insurance', 'insurance_technic', 'support', 'cost', 'account', 'granted_from', 'notes', 'intern_notes', 'status', 'project_of_year', 'end_quartal')
|
2020-11-24 13:44:07 +01:00
|
|
|
# action = ['export_as_csv']
|
2022-12-06 17:19:02 +01:00
|
|
|
date_hierarchy = 'end'
|
2022-12-07 14:56:22 +01:00
|
|
|
readonly_fields = ('end_quartal', 'project_of_year', 'pid', 'finance_id')
|
2022-11-15 17:57:01 +01:00
|
|
|
|
2022-11-03 18:02:39 +01:00
|
|
|
@admin.register(BusinessCard)
|
|
|
|
class BusinessCardAdmin(admin.ModelAdmin):
|
2022-11-04 12:18:09 +01:00
|
|
|
save_as = True
|
2022-12-02 17:04:11 +01:00
|
|
|
search_fields = ('realname', 'service_id', 'granted', 'granted_date', 'project')
|
2022-11-03 18:02:39 +01:00
|
|
|
list_display = ('realname', 'service_id', 'granted', 'granted_date', 'project')
|
2022-11-04 12:18:09 +01:00
|
|
|
list_display_links = ('realname', 'service_id')
|
2022-11-03 18:02:39 +01:00
|
|
|
# action = ['export_as_csv']
|
2022-11-17 18:39:43 +01:00
|
|
|
date_hierarchy = 'granted_date'
|
2022-12-09 17:33:52 +01:00
|
|
|
readonly_fields = ['service_id']
|
2022-11-11 09:28:46 +01:00
|
|
|
class Media:
|
|
|
|
js = ('dropdown/js/base.js',)
|
|
|
|
|
2022-11-15 17:57:01 +01:00
|
|
|
@admin.register(Literature)
|
|
|
|
class LiteratureAdmin(admin.ModelAdmin):
|
2022-11-17 18:39:43 +01:00
|
|
|
save_as = True
|
2022-12-02 17:04:11 +01:00
|
|
|
search_fields = ('realname', 'service_id', 'granted', 'granted_date')
|
2022-11-17 18:39:43 +01:00
|
|
|
list_display = ('realname', 'service_id', 'granted', 'granted_date')
|
|
|
|
list_display_links = ('realname', 'service_id')
|
|
|
|
date_hierarchy = 'granted_date'
|
2022-12-09 17:33:52 +01:00
|
|
|
readonly_fields = ['service_id']
|
2022-11-11 09:28:46 +01:00
|
|
|
|
2022-11-04 12:18:09 +01:00
|
|
|
|
2022-11-17 18:39:43 +01:00
|
|
|
@admin.register(Account)
|
|
|
|
class AccountAdmin(admin.ModelAdmin):
|
|
|
|
save_as = True
|
|
|
|
|
|
|
|
|
|
|
|
@admin.register(HonoraryCertificate)
|
|
|
|
class HonoraryCertificateAdmin(admin.ModelAdmin):
|
|
|
|
save_as = True
|
2022-12-12 11:26:19 +01:00
|
|
|
search_fields = ['realname', 'granted', 'project__name', 'project__pid']
|
2022-12-05 11:19:03 +01:00
|
|
|
list_display = ('realname', 'granted','project')
|
2022-11-17 18:39:43 +01:00
|
|
|
date_hierarchy = 'granted_date'
|
2022-12-12 11:13:46 +01:00
|
|
|
autocomplete_fields = ['project']
|
2022-11-17 18:39:43 +01:00
|
|
|
|
|
|
|
@admin.register(Library)
|
|
|
|
class LibraryAdmin(admin.ModelAdmin):
|
|
|
|
save_as = True
|
2022-12-02 17:04:11 +01:00
|
|
|
search_fields = ('realname', 'service_id', 'granted', 'granted_date')
|
2022-11-17 18:39:43 +01:00
|
|
|
list_display = ('realname', 'service_id', 'granted', 'granted_date')
|
|
|
|
list_display_links = ('realname', 'service_id')
|
|
|
|
date_hierarchy = 'granted_date'
|
2022-12-09 17:33:52 +01:00
|
|
|
readonly_fields = ['service_id']
|
2022-11-17 18:39:43 +01:00
|
|
|
|
|
|
|
@admin.register(IFG)
|
|
|
|
class IFGAdmin(admin.ModelAdmin):
|
|
|
|
save_as = True
|
2022-12-02 17:04:11 +01:00
|
|
|
search_fields = ('realname', 'service_id', 'granted', 'granted_date')
|
2022-11-17 18:39:43 +01:00
|
|
|
list_display = ('realname', 'service_id', 'granted', 'granted_date')
|
|
|
|
list_display_links = ('realname', 'service_id')
|
|
|
|
date_hierarchy = 'granted_date'
|
2022-12-09 17:33:52 +01:00
|
|
|
readonly_fields = ['service_id']
|
2022-11-17 18:39:43 +01:00
|
|
|
|
|
|
|
@admin.register(Travel)
|
|
|
|
class TravelAdmin(admin.ModelAdmin):
|
|
|
|
save_as = True
|
2022-12-12 11:26:19 +01:00
|
|
|
search_fields = ['realname', 'service_id', 'granted_date', 'project__name', 'project__pid']
|
2022-12-09 17:52:52 +01:00
|
|
|
list_display = ('realname', 'service_id', 'granted', 'granted_date', 'project_end', 'project', 'project_end_quartal')
|
2022-11-17 18:39:43 +01:00
|
|
|
list_display_links = ('realname', 'project')
|
2022-12-06 17:48:02 +01:00
|
|
|
date_hierarchy = 'project_end'
|
2022-12-07 14:56:22 +01:00
|
|
|
readonly_fields = ('project_end_quartal', 'project_end')
|
2022-12-08 22:36:48 +01:00
|
|
|
autocomplete_fields = ['project']
|
2022-12-09 17:52:52 +01:00
|
|
|
readonly_fields = ['service_id']
|
2022-11-17 18:39:43 +01:00
|
|
|
|
|
|
|
@admin.register(Email)
|
|
|
|
class EmailAdmin(admin.ModelAdmin):
|
|
|
|
save_as = True
|
2022-12-02 17:04:11 +01:00
|
|
|
search_fields = ('realname', 'service_id', 'granted', 'granted_date')
|
2022-11-17 18:39:43 +01:00
|
|
|
list_display = ('realname', 'service_id', 'granted', 'granted_date')
|
|
|
|
list_display_links = ('realname', 'service_id')
|
|
|
|
date_hierarchy = 'granted_date'
|
2022-12-06 18:39:25 +01:00
|
|
|
radio_fields = {'adult': admin.VERTICAL}
|
2022-12-09 17:33:52 +01:00
|
|
|
readonly_fields = ['service_id']
|
2022-12-05 11:19:03 +01:00
|
|
|
class Media:
|
|
|
|
js = ('dropdown/js/base.js',)
|
2022-11-17 18:39:43 +01:00
|
|
|
|
2020-10-06 13:17:28 +02:00
|
|
|
|
2022-11-17 18:39:43 +01:00
|
|
|
@admin.register(List)
|
|
|
|
class ListAdmin(admin.ModelAdmin):
|
|
|
|
save_as = True
|
2022-12-02 17:04:11 +01:00
|
|
|
search_fields = ('realname', 'service_id', 'granted', 'granted_date')
|
2022-11-17 18:39:43 +01:00
|
|
|
list_display = ('realname', 'service_id', 'granted', 'granted_date')
|
|
|
|
list_display_links = ('realname', 'service_id')
|
|
|
|
date_hierarchy = 'granted_date'
|
2022-12-09 17:33:52 +01:00
|
|
|
readonly_fields = ['service_id']
|
2022-11-17 18:39:43 +01:00
|
|
|
|
|
|
|
# commented out because of the individual registering to control displays in admin panel
|
|
|
|
|
|
|
|
#admin.site.register([
|
|
|
|
# Account,
|
|
|
|
# HonoraryCertificate,
|
|
|
|
# Library,
|
|
|
|
# IFG,
|
|
|
|
# Travel,
|
|
|
|
# Email,
|
|
|
|
# List,
|
|
|
|
# ])
|