|
@ -306,10 +306,6 @@ def export_csv(request): |
|
|
value = "" |
|
|
value = "" |
|
|
return unicode(value).encode('utf8') |
|
|
return unicode(value).encode('utf8') |
|
|
|
|
|
|
|
|
eventos_fields = Evento._meta.fields |
|
|
|
|
|
equipe_fields = Equipe._meta.fields |
|
|
|
|
|
convite_fields = Convite._meta.fields |
|
|
|
|
|
|
|
|
|
|
|
eventos = carrinhoOrGet_for_qs(request) |
|
|
eventos = carrinhoOrGet_for_qs(request) |
|
|
eventos.select_related('equipe', 'convite') |
|
|
eventos.select_related('equipe', 'convite') |
|
|
|
|
|
|
|
@ -318,17 +314,13 @@ def export_csv(request): |
|
|
return HttpResponseRedirect('../') |
|
|
return HttpResponseRedirect('../') |
|
|
|
|
|
|
|
|
max_equipe = max([e.equipe_set.count() for e in eventos]) |
|
|
max_equipe = max([e.equipe_set.count() for e in eventos]) |
|
|
max_convite = max([e.convite_set.count() for e in eventos]) |
|
|
|
|
|
|
|
|
|
|
|
head = [f.verbose_name.encode('utf8') for f in eventos_fields |
|
|
head = [f.verbose_name.encode('utf8') for f in Evento._meta.fields] |
|
|
if f.name != 'id'] |
|
|
|
|
|
head.extend([f.verbose_name.encode('utf8')+"_{0}".format(i+1) |
|
|
head.extend([f.verbose_name.encode('utf8')+"_{0}".format(i+1) |
|
|
for i in range(max_equipe) for f in Equipe._meta.fields |
|
|
for i in range(max_equipe) for f in Equipe._meta.fields |
|
|
if f.name not in ('id', 'evento')]) |
|
|
if f.name not in ('id', 'evento')]) |
|
|
head.extend([f.verbose_name.encode('utf8')+"_{0}".format(i+1) |
|
|
head.extend([f.verbose_name.encode('utf8') for f in Convite._meta.fields |
|
|
for i in range(max_convite) for f in Convite._meta.fields |
|
|
|
|
|
if f.name not in ('id', 'evento')]) |
|
|
if f.name not in ('id', 'evento')]) |
|
|
head.append('total_participantes') |
|
|
|
|
|
|
|
|
|
|
|
response = HttpResponse(content_type='text/csv') |
|
|
response = HttpResponse(content_type='text/csv') |
|
|
response['Content-Disposition'] = 'attachment; filename=eventos.csv' |
|
|
response['Content-Disposition'] = 'attachment; filename=eventos.csv' |
|
@ -338,8 +330,7 @@ def export_csv(request): |
|
|
|
|
|
|
|
|
for evento in eventos: |
|
|
for evento in eventos: |
|
|
reg = {f.verbose_name.encode('utf8'): serialize(evento, f) |
|
|
reg = {f.verbose_name.encode('utf8'): serialize(evento, f) |
|
|
for f in Evento._meta.fields if f.name != 'id'} |
|
|
for f in Evento._meta.fields} |
|
|
reg['total_participantes'] = 0 |
|
|
|
|
|
idx = 1 |
|
|
idx = 1 |
|
|
for membro in evento.equipe_set.all(): |
|
|
for membro in evento.equipe_set.all(): |
|
|
reg.update( |
|
|
reg.update( |
|
@ -350,17 +341,14 @@ def export_csv(request): |
|
|
} |
|
|
} |
|
|
) |
|
|
) |
|
|
idx += 1 |
|
|
idx += 1 |
|
|
idx = 1 |
|
|
|
|
|
for convite in evento.convite_set.all(): |
|
|
for convite in evento.convite_set.all(): |
|
|
reg.update( |
|
|
reg.update( |
|
|
{ |
|
|
{f.verbose_name.encode('utf8'): serialize(convite, f) |
|
|
"{0}_{1}".format(f.verbose_name.encode('utf8'), idx): |
|
|
for f in Convite._meta.fields |
|
|
serialize(convite, f) for f in Convite._meta.fields |
|
|
if f.name not in ('id', 'evento')} |
|
|
if f.name not in ('id', 'evento') |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
) |
|
|
reg['total_participantes'] += convite.qtde_participantes |
|
|
writer.writerow(reg) |
|
|
idx += 1 |
|
|
if evento.convite_set.count() == 0: |
|
|
writer.writerow(reg) |
|
|
writer.writerow(reg) |
|
|
|
|
|
|
|
|
return response |
|
|
return response |
|
|