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