from windberg_register import models
from django.contrib import admin


class StarterAdmin(admin.ModelAdmin):
    list_display = ("name", "given", "age_group_short", "club_name", "email", "run_list", "comment")
    list_per_page = 1000

    def club_name(self, obj):
        return obj.club.name
    club_name.short_description = u"Verein"

    def age_group_short(self, obj):
        return obj.actual_age_group().short
    age_group_short.short_description = u"gemeldete Ak"

    def run_list(self, obj):
        return  u"; ".join(r.name for r in obj.runs.all())
    run_list.short_description = u"gemeldete Wertungen"



admin.site.register(models.AgeGroup)
admin.site.register(models.Club)
admin.site.register(models.Run)
admin.site.register(models.Start)
admin.site.register(models.Starter, StarterAdmin)
admin.site.register(models.Version)

@@ -1,12 +1,117 @@
+import codecs%0Afrom collections import defaultdict%0Afrom django.http import HttpResponse%0Aimport unicodecsv%0A
 from windber
@@ -333,16 +333,49 @@
 e = 1000
+%0A    actions = %5B'_make_csv_list'%5D
 %0A%0A    de
@@ -653,17 +653,16 @@
  return 
- 
 u%22; %22.jo
@@ -753,16 +753,842 @@
 ungen%22%0A%0A
+    def _make_csv_list(self, request, queryset):%0A        run_dict = defaultdict(list)%0A        for starter in queryset:%0A            for run in starter.runs.all():%0A                run_dict%5Brun.name%5D.append(starter)%0A%0A        response = HttpResponse(content_type='text/csv')%0A        response%5B'Content-Disposition'%5D = 'attachment; filename=%22meldungen.csv%22'%0A%0A        writer = unicodecsv.writer(response)%0A%0A        for collected_run in run_dict:%0A            writer.writerow(%5Bcollected_run%5D)%0A            for starter in run_dict%5Bcollected_run%5D:%0A                writer.writerow(%5B%22%22, %22%22, %22%22, starter.name, starter.given, starter.birth.year, starter.club.name,%0A                                 starter.actual_age_group().short%5D)%0A            writer.writerow(%5B%22%22%5D)%0A        return response%0A    _make_csv_list.short_description = %22export CSV%22%0A
 %0A%0Aadmin.

Add csv export feature for appointments