You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
5.2 KiB

  1. import csv
  2. from django.contrib import admin
  3. from django.http import HttpResponse
  4. from .models import Account, Project, HonoraryCertificate, Library, IFG, Travel,\
  5. Email, BusinessCard, List, Literature
  6. def export_as_csv(self, request, queryset):
  7. meta = self.model._meta
  8. field_names = [field.name for field in meta.fields]
  9. response = HttpResponse(content_type='text/csv')
  10. response['Content-Disposition'] = 'attachment; filename={}.csv'.format(meta)
  11. writer = csv.writer(response)
  12. writer.writerow(field_names)
  13. for obj in queryset:
  14. row = writer.writerow([getattr(obj, field) for field in field_names])
  15. return response
  16. export_as_csv.short_description = "Ausgewähltes zu CSV exportieren"
  17. admin.site.add_action(export_as_csv)
  18. @admin.register(Project)
  19. class ProjectAdmin(admin.ModelAdmin):
  20. save_as = True
  21. search_fields = ('name', 'pid','finance_id', 'realname', 'start', 'end', 'participants_estimated', 'participants_real', 'cost', 'status', 'end_quartal')
  22. list_display = ('name', 'pid','finance_id', 'realname', 'start', 'end', 'participants_estimated', 'participants_real', 'cost', 'status', 'end_quartal')
  23. 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')
  24. # action = ['export_as_csv']
  25. date_hierarchy = 'end'
  26. readonly_fields = ('end_quartal', 'project_of_year', 'pid', 'finance_id')
  27. @admin.register(BusinessCard)
  28. class BusinessCardAdmin(admin.ModelAdmin):
  29. save_as = True
  30. search_fields = ('realname', 'service_id', 'granted', 'granted_date', 'project')
  31. list_display = ('realname', 'service_id', 'granted', 'granted_date', 'project')
  32. list_display_links = ('realname', 'service_id')
  33. # action = ['export_as_csv']
  34. date_hierarchy = 'granted_date'
  35. readonly_fields = ['service_id']
  36. class Media:
  37. js = ('dropdown/js/base.js',)
  38. @admin.register(Literature)
  39. class LiteratureAdmin(admin.ModelAdmin):
  40. save_as = True
  41. search_fields = ('realname', 'service_id', 'granted', 'granted_date')
  42. list_display = ('realname', 'service_id', 'granted', 'granted_date')
  43. list_display_links = ('realname', 'service_id')
  44. date_hierarchy = 'granted_date'
  45. readonly_fields = ['service_id']
  46. @admin.register(Account)
  47. class AccountAdmin(admin.ModelAdmin):
  48. save_as = True
  49. @admin.register(HonoraryCertificate)
  50. class HonoraryCertificateAdmin(admin.ModelAdmin):
  51. save_as = True
  52. search_fields = ['realname', 'granted']
  53. list_display = ('realname', 'granted','project')
  54. date_hierarchy = 'granted_date'
  55. @admin.register(Library)
  56. class LibraryAdmin(admin.ModelAdmin):
  57. save_as = True
  58. search_fields = ('realname', 'service_id', 'granted', 'granted_date')
  59. list_display = ('realname', 'service_id', 'granted', 'granted_date')
  60. list_display_links = ('realname', 'service_id')
  61. date_hierarchy = 'granted_date'
  62. readonly_fields = ['service_id']
  63. @admin.register(IFG)
  64. class IFGAdmin(admin.ModelAdmin):
  65. save_as = True
  66. search_fields = ('realname', 'service_id', 'granted', 'granted_date')
  67. list_display = ('realname', 'service_id', 'granted', 'granted_date')
  68. list_display_links = ('realname', 'service_id')
  69. date_hierarchy = 'granted_date'
  70. readonly_fields = ['service_id']
  71. @admin.register(Travel)
  72. class TravelAdmin(admin.ModelAdmin):
  73. save_as = True
  74. search_fields = ['realname', 'service_id', 'granted_date']
  75. list_display = ('realname', 'service_id', 'granted', 'granted_date', 'project_end', 'project', 'project_end_quartal')
  76. list_display_links = ('realname', 'project')
  77. date_hierarchy = 'project_end'
  78. readonly_fields = ('project_end_quartal', 'project_end')
  79. autocomplete_fields = ['project']
  80. readonly_fields = ['service_id']
  81. @admin.register(Email)
  82. class EmailAdmin(admin.ModelAdmin):
  83. save_as = True
  84. search_fields = ('realname', 'service_id', 'granted', 'granted_date')
  85. list_display = ('realname', 'service_id', 'granted', 'granted_date')
  86. list_display_links = ('realname', 'service_id')
  87. date_hierarchy = 'granted_date'
  88. radio_fields = {'adult': admin.VERTICAL}
  89. readonly_fields = ['service_id']
  90. class Media:
  91. js = ('dropdown/js/base.js',)
  92. @admin.register(List)
  93. class ListAdmin(admin.ModelAdmin):
  94. save_as = True
  95. search_fields = ('realname', 'service_id', 'granted', 'granted_date')
  96. list_display = ('realname', 'service_id', 'granted', 'granted_date')
  97. list_display_links = ('realname', 'service_id')
  98. date_hierarchy = 'granted_date'
  99. readonly_fields = ['service_id']
  100. # commented out because of the individual registering to control displays in admin panel
  101. #admin.site.register([
  102. # Account,
  103. # HonoraryCertificate,
  104. # Library,
  105. # IFG,
  106. # Travel,
  107. # Email,
  108. # List,
  109. # ])