Ejemplo n.º 1
0
def export(request: WSGIRequest,
           file_type: str,
           status: str = "all") -> Union[HttpResponse, PDFResponse]:
    semester: Semester = get_object_or_404(Semester, pk=get_semester(request))

    if status == "all":
        tutors = Tutor.objects.filter(semester=semester)
    else:
        tutors = Tutor.objects.filter(semester=semester, status=status)
    tutors = tutors.order_by("last_name", "first_name")

    filename = f"tutors_{time.strftime('%Y%m%d-%H%M')}"

    if file_type == "pdf":
        return render_to_pdf(request, "tutors/tex/tutors.tex",
                             {"tutors": tutors}, f"{filename}.pdf")
    if file_type == "csv":
        return utils.download_csv(
            [
                "last_name", "first_name", "subject", "matriculation_number",
                "birthday"
            ],
            f"{filename}.csv",
            list(tutors),
        )
    if file_type == "tshirt":
        return render_to_pdf(request, "tutors/tex/tshirts.tex",
                             {"tutors": tutors}, f"{filename}.pdf")

    raise Http404
Ejemplo n.º 2
0
def export(request: WSGIRequest,
           file_format: str = "csv") -> Union[HttpResponse, PDFResponse]:
    semester: Semester = get_object_or_404(Semester, pk=get_semester(request))
    try:
        fahrt = semester.fahrt
    except ObjectDoesNotExist:
        messages.error(request, _("Please setup the SETtings for the Fahrt"))
        return redirect("fahrt:settings")
    participants = Participant.objects.filter(semester=semester).order_by(
        "surname", "firstname")
    filename = f"fahrt_participants_{fahrt.semester}_{fahrt.date}_{time.strftime('%Y%m%d-%H%M')}"
    context = {"participants": participants, "fahrt": fahrt}
    if file_format == "csv":
        return utils.download_csv(
            [
                "surname",
                "firstname",
                "birthday",
                "email",
                "phone",
                "mobile",
                "subject",
                "nutrition",
                "allergies",
            ],
            f"{filename}.csv",
            participants,
        )
    return render_to_pdf(request, "fahrt/tex/participants.tex", context,
                         f"{filename}.pdf")
Ejemplo n.º 3
0
def export_tour(request: WSGIRequest, file_format: str, tour_pk: int) -> Union[HttpResponse, PDFResponse]:
    tour = get_object_or_404(Tour, pk=tour_pk)
    participants = tour.participant_set.order_by("time")
    confirmed_participants = participants[: tour.capacity]
    filename = f"participants_{tour.name}_{tour.date}_{time.strftime('%Y%m%d-%H%M')}"
    context = {"participants": confirmed_participants, "tour": tour}
    if file_format == "csv":
        return utils.download_csv(
            ["surname", "firstname", "time", "email", "phone", "subject"],
            f"{filename}.csv",
            confirmed_participants,
        )
    return render_to_pdf(request, "guidedtours/tex/tour.tex", context, f"{filename}.pdf")
Ejemplo n.º 4
0
def export_mail(request: WSGIRequest) -> HttpResponse:
    mail_klass_lut = {
        "bags": BagMail,
        "fahrt": FahrtMail,
        "guidedtours": TourMail,
        "settool_common": Mail,
        "tutors": TutorMail,
    }
    mails: list[dict[str, str]] = []
    for source, klass in mail_klass_lut.items():
        mails += [_clean_mail(mail, source) for mail in klass.objects.all()]

    filename = f"emails_{time.strftime('%Y%m%d-%H%M')}.csv"
    return utils.download_csv(
        ["source", "sender", "subject", "text", "comment"], filename, mails)
Ejemplo n.º 5
0
def export_csv(request: WSGIRequest) -> HttpResponse:
    semester: Semester = get_object_or_404(Semester, pk=get_semester(request))
    companies = semester.company_set.order_by("name")
    return utils.download_csv(
        [
            "name",
            "contact_gender",
            "contact_firstname",
            "contact_lastname",
            "email",
            "email_sent",
            "email_sent_success",
            "promise",
            "comment",
            "last_year",
            "contact_again",
        ],
        f"companies_{time.strftime('%Y%m%d-%H%M')}.csv",
        companies,
    )