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.

125 lines
4.4 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. # action = ['export_as_csv']
  24. date_hierarchy = 'end'
  25. readonly_fields = ('end_quartal', 'project_of_year', 'pid', 'finance_id')
  26. @admin.register(BusinessCard)
  27. class BusinessCardAdmin(admin.ModelAdmin):
  28. save_as = True
  29. search_fields = ('realname', 'service_id', 'granted', 'granted_date', 'project')
  30. list_display = ('realname', 'service_id', 'granted', 'granted_date', 'project')
  31. list_display_links = ('realname', 'service_id')
  32. # action = ['export_as_csv']
  33. date_hierarchy = 'granted_date'
  34. class Media:
  35. js = ('dropdown/js/base.js',)
  36. @admin.register(Literature)
  37. class LiteratureAdmin(admin.ModelAdmin):
  38. save_as = True
  39. search_fields = ('realname', 'service_id', 'granted', 'granted_date')
  40. list_display = ('realname', 'service_id', 'granted', 'granted_date')
  41. list_display_links = ('realname', 'service_id')
  42. date_hierarchy = 'granted_date'
  43. @admin.register(Account)
  44. class AccountAdmin(admin.ModelAdmin):
  45. save_as = True
  46. @admin.register(HonoraryCertificate)
  47. class HonoraryCertificateAdmin(admin.ModelAdmin):
  48. save_as = True
  49. search_fields = ['realname', 'granted']
  50. list_display = ('realname', 'granted','project')
  51. date_hierarchy = 'granted_date'
  52. @admin.register(Library)
  53. class LibraryAdmin(admin.ModelAdmin):
  54. save_as = True
  55. search_fields = ('realname', 'service_id', 'granted', 'granted_date')
  56. list_display = ('realname', 'service_id', 'granted', 'granted_date')
  57. list_display_links = ('realname', 'service_id')
  58. date_hierarchy = 'granted_date'
  59. @admin.register(IFG)
  60. class IFGAdmin(admin.ModelAdmin):
  61. save_as = True
  62. search_fields = ('realname', 'service_id', 'granted', 'granted_date')
  63. list_display = ('realname', 'service_id', 'granted', 'granted_date')
  64. list_display_links = ('realname', 'service_id')
  65. date_hierarchy = 'granted_date'
  66. @admin.register(Travel)
  67. class TravelAdmin(admin.ModelAdmin):
  68. save_as = True
  69. search_fields = ['realname', 'granted_date']
  70. list_display = ('realname', 'granted', 'granted_date', 'project_end', 'project', 'project_end_quartal')
  71. list_display_links = ('realname', 'project')
  72. date_hierarchy = 'project_end'
  73. readonly_fields = ('project_end_quartal', 'project_end')
  74. @admin.register(Email)
  75. class EmailAdmin(admin.ModelAdmin):
  76. save_as = True
  77. search_fields = ('realname', 'service_id', 'granted', 'granted_date')
  78. list_display = ('realname', 'service_id', 'granted', 'granted_date')
  79. list_display_links = ('realname', 'service_id')
  80. date_hierarchy = 'granted_date'
  81. radio_fields = {'adult': admin.VERTICAL}
  82. class Media:
  83. js = ('dropdown/js/base.js',)
  84. @admin.register(List)
  85. class ListAdmin(admin.ModelAdmin):
  86. save_as = True
  87. search_fields = ('realname', 'service_id', 'granted', 'granted_date')
  88. list_display = ('realname', 'service_id', 'granted', 'granted_date')
  89. list_display_links = ('realname', 'service_id')
  90. date_hierarchy = 'granted_date'
  91. # commented out because of the individual registering to control displays in admin panel
  92. #admin.site.register([
  93. # Account,
  94. # HonoraryCertificate,
  95. # Library,
  96. # IFG,
  97. # Travel,
  98. # Email,
  99. # List,
  100. # ])