Compare commits

..

5 commits

Author SHA1 Message Date
5f1e9d07d9 another fix 2025-03-05 19:49:48 +01:00
c1df250a46 multiple fields support added, prazdne params 2025-03-05 19:48:19 +01:00
eb41008261 pridani custom checkboxu 2025-03-05 19:14:11 +01:00
96b66f4019 link na odkazy se soustredeni 2025-03-05 18:44:32 +01:00
c780e7e35f pridano ucastnici 2025-03-05 18:33:06 +01:00
3 changed files with 64 additions and 12 deletions

View file

@ -5,12 +5,27 @@
<h2><strong>Export lidí</strong></h2> <h2><strong>Export lidí</strong></h2>
<p>Vyberte pole, které chcete exportovat</p>
<!-- for loop zde neni pouzit proto, aby se mohlo napsat
data-value="email telefon mesto"
a zabalit tak vice parametru do jednoho checkboxu -->
<p>
<label>( Jméno: <input class="field-check" data-value="jmeno" type="checkbox" checked>)</label>
<label>( Příjmení: <input class="field-check" data-value="prijmeni" type="checkbox" checked>)</label>
<label>( E-mail <input class="field-check" data-value="email" type="checkbox" checked>)</label>
<label>( Telefon <input class="field-check" data-value="telefon" type="checkbox" checked>)</label>
<label>( Ulice <input class="field-check" data-value="ulice" type="checkbox">)</label>
<label>( Město <input class="field-check" data-value="mesto" type="checkbox">)</label>
<label>( PSČ <input class="field-check" data-value="psc" type="checkbox">)</label>
</p>
<select name="select-one" id="select-one"> <select name="select-one" id="select-one">
<option value="0">---</option> <option value="0">---</option>
<option value="1">Řešitelé čísla</option> <option value="1">Řešitelé čísla</option>
<option value="2">Řešitelé ročníku</option> <option value="2">Řešitelé ročníku</option>
<option value="3">Všichni řešitelé, kteří ještě neodmaturovali</option> <option value="3">Všichni řešitelé, kteří ještě neodmaturovali</option>
<option value="4">Organizátoři soustředění</option> <option value="4">Organizátoři soustředění</option>
<option value="5">Účastníci soustředění</option>
</select> </select>
<select name="select-two" id="select-two"> <select name="select-two" id="select-two">
@ -76,12 +91,22 @@
}) })
download_button.addEventListener('click', (e) => { download_button.addEventListener('click', (e) => {
if (select_two.innerHTML == '') { // uzivatele vybrana pole
window.location.href = "/profil/exporty_lidi/get_csv_only_one_step/" + select_one.value fields = Array.from(document.getElementsByClassName('field-check'))
} else { .filter(e => e.checked)
window.location.href = "/profil/exporty_lidi/get_csv/" + select_one.value + "/" + select_two.value .map(e => e.getAttribute('data-value'));
params = ""
for (let val of fields) {
for(let s of val.split(' ')) {
params += s + ","
}
}
params = params.slice(0, -1)
if (select_two.innerHTML == '') {
window.location.href = "/profil/exporty_lidi/get_csv_only_one_step/" + select_one.value + "?fields=" + params
} else {
window.location.href = "/profil/exporty_lidi/get_csv/" + select_one.value + "/" + select_two.value + "?fields=" + params
} }
}) })
</script> </script>

View file

@ -147,7 +147,9 @@ class OrgoRozcestnikView(TemplateView):
class PrvniTypExportu(Enum): class PrvniTypExportu(Enum):
CISLA = 1 CISLA = 1
ROCNIKU = 2 ROCNIKU = 2
SOUSTREDENI = 4 SOUSTREDENI_ORG = 4
SOUSTREDENI_UCASTNICI = 5
class ExportLidiView(TemplateView): class ExportLidiView(TemplateView):
template_name = 'personalni/profil/export_lidi.html' template_name = 'personalni/profil/export_lidi.html'
@ -163,35 +165,59 @@ def get_export_options(request, type):
data = [{"id": c.id, "display": str(c)} for c in Cislo.objects.all()] data = [{"id": c.id, "display": str(c)} for c in Cislo.objects.all()]
if type == PrvniTypExportu.ROCNIKU.value: if type == PrvniTypExportu.ROCNIKU.value:
data = [{"id": r.id, "display": str(r)} for r in Rocnik.objects.all()] data = [{"id": r.id, "display": str(r)} for r in Rocnik.objects.all()]
if type == PrvniTypExportu.SOUSTREDENI.value: if type == PrvniTypExportu.SOUSTREDENI_ORG.value:
data = [{"id": s.id, "display": str(s)} for s in Soustredeni.objects.all()]
if type == PrvniTypExportu.SOUSTREDENI_UCASTNICI.value:
data = [{"id": s.id, "display": str(s)} for s in Soustredeni.objects.all()] data = [{"id": s.id, "display": str(s)} for s in Soustredeni.objects.all()]
return HttpResponse(json.dumps(data), content_type='application/json') return HttpResponse(json.dumps(data), content_type='application/json')
def getFieldsForExport(request):
if 'fields' not in request.GET or request.GET.get('fields') == '':
return ["jmeno", "prijmeni", "email", "telefon"]
fields = request.GET.get('fields').split(',')
return fields
def download_export_csv_only_first_step(request, type): def download_export_csv_only_first_step(request, type):
fields = getFieldsForExport(request)
if type == 3: if type == 3:
response = dataResiteluCsvResponse(tvorba_utils.resitele_co_neodmaturovali()) resitele = tvorba_utils.resitele_co_neodmaturovali()
resiteleOsoby = Osoba.objects.filter(resitel__in=resitele)
response = dataOsobCsvResponse(resiteleOsoby, columns=fields)
response['Content-Disposition'] = 'attachment; filename="resitele_co_neodmaturovali.csv"' response['Content-Disposition'] = 'attachment; filename="resitele_co_neodmaturovali.csv"'
return response return response
def download_export_csv(request, type, id): def download_export_csv(request, type, id):
fields = getFieldsForExport(request)
if type == PrvniTypExportu.CISLA.value: if type == PrvniTypExportu.CISLA.value:
response = dataResiteluCsvResponse(tvorba_utils.resi_cislo(Cislo.objects.get(id=id))) resitele = tvorba_utils.resi_cislo(Cislo.objects.get(id=id))
resiteleOsoby = Osoba.objects.filter(resitel__in=resitele)
response = dataOsobCsvResponse(resiteleOsoby, columns=fields)
name = str(Cislo.objects.get(id=id)).replace(" ", "_") + "_resitele_cisla.csv" name = str(Cislo.objects.get(id=id)).replace(" ", "_") + "_resitele_cisla.csv"
response['Content-Disposition'] = 'attachment; filename="' + name + '"' response['Content-Disposition'] = 'attachment; filename="' + name + '"'
return response return response
if type == PrvniTypExportu.ROCNIKU.value: if type == PrvniTypExportu.ROCNIKU.value:
response = dataResiteluCsvResponse(tvorba_utils.resi_v_rocniku(Rocnik.objects.get(id=id))) resitele = tvorba_utils.resi_v_rocniku(Rocnik.objects.get(id=id))
resiteleOsoby = Osoba.objects.filter(resitel__in=resitele)
response = dataOsobCsvResponse(resiteleOsoby, columns=fields)
name = str(Rocnik.objects.get(id=id)).replace(" ", "_") + "_resitele_rocniku.csv" name = str(Rocnik.objects.get(id=id)).replace(" ", "_") + "_resitele_rocniku.csv"
response['Content-Disposition'] = 'attachment; filename="' + name + '"' response['Content-Disposition'] = 'attachment; filename="' + name + '"'
return response return response
if type == PrvniTypExportu.SOUSTREDENI.value: if type == PrvniTypExportu.SOUSTREDENI_ORG.value:
soustredeni = Soustredeni.objects.get(id=id) soustredeni = Soustredeni.objects.get(id=id)
organizatori = soustredeni.organizatori.all() organizatori = soustredeni.organizatori.all()
organizatoriOsoby = Osoba.objects.filter(org__in=organizatori) organizatoriOsoby = Osoba.objects.filter(org__in=organizatori)
response = dataOsobCsvResponse(organizatoriOsoby, columns=("jmeno", "prijmeni", "email", "telefon",)) response = dataOsobCsvResponse(organizatoriOsoby, columns=fields)
name = str(soustredeni).replace(" ", "_") + "_organizatori_soustredeni.csv" name = str(soustredeni).replace(" ", "_") + "_organizatori_soustredeni.csv"
response['Content-Disposition'] = 'attachment; filename="' + name + '"' response['Content-Disposition'] = 'attachment; filename="' + name + '"'
return response return response
if type == PrvniTypExportu.SOUSTREDENI_UCASTNICI.value:
soustredeni = Soustredeni.objects.get(id=id)
ucastnici = soustredeni.ucastnici.all()
ucastniciOsoby = Osoba.objects.filter(resitel__in=ucastnici)
response = dataOsobCsvResponse(ucastniciOsoby, columns=fields)
name = str(soustredeni).replace(" ", "_") + "_ucastnici_soustredeni.csv"
response['Content-Disposition'] = 'attachment; filename="' + name + '"'
return response
class ResitelView(LoginRequiredMixin,generic.DetailView): class ResitelView(LoginRequiredMixin,generic.DetailView):
model = m.Resitel model = m.Resitel

View file

@ -57,6 +57,7 @@
<a href="../{{soustredeni.pk}}/seznam_ucastniku">HTML tabulka pro tisk</a>, <a href="../{{soustredeni.pk}}/seznam_ucastniku">HTML tabulka pro tisk</a>,
<a href="../{{soustredeni.pk}}/export_ucastniku">CSV</a>, <a href="../{{soustredeni.pk}}/export_ucastniku">CSV</a>,
<a href="../{{soustredeni.pk}}/maily_ucastniku">E-maily</a><br> <a href="../{{soustredeni.pk}}/maily_ucastniku">E-maily</a><br>
Exporty pro soustředění: <a href="{% url 'exporty_lidi' %}">exporty</a><br>
<a href="../{{soustredeni.pk}}/stvrzenky.pdf">Stvrzenky</a> <a href="../{{soustredeni.pk}}/stvrzenky.pdf">Stvrzenky</a>
</div> </div>
{% endif %} {% endif %}