コード例 #1
0
ファイル: views.py プロジェクト: CommanderStorm/settool-v2
def _gather_batch_parameters(
    request: WSGIRequest,
) -> tuple[Semester, QuerySet[Tutor], dict[int, int],
           QuerySet[SubjectTutorCountAssignment], bool]:
    semester: Semester = get_object_or_404(Semester, pk=get_semester(request))
    # tutor specific parameters
    all_tutors: QuerySet[Tutor] = Tutor.objects.filter(semester=semester)
    tutors_active: QuerySet[Tutor] = all_tutors.filter(
        status=Tutor.STATUS_ACTIVE)
    tutors_accepted_cnt: dict[int, int] = {
        tutor_acc_count["subject"]: tutor_acc_count["subject_count"]
        for tutor_acc_count in all_tutors.filter(
            status=Tutor.STATUS_ACCEPTED).values("subject").annotate(
                subject_count=Count("subject")).all()
    }
    # preferences
    assignment_wishes: QuerySet[
        SubjectTutorCountAssignment] = SubjectTutorCountAssignment.objects.filter(
            semester=semester, )
    # check if assignment_wishes is valid. shows warnings and errors
    errors: bool = _gen_messages_assignments_wish_counter(
        request,
        assignment_wishes,
        tutors_active,
        tutors_accepted_cnt,
    )
    messages.info(
        request,
        _("Batch actions do not send mails. They only change the status of the students."
          ))
    return semester, tutors_active, tutors_accepted_cnt, assignment_wishes, errors
コード例 #2
0
def signup_internal(request: WSGIRequest) -> HttpResponse:
    semester: Semester = get_object_or_404(Semester, pk=get_semester(request))
    curr_settings: Setting = Setting.objects.get_or_create(semester=semester)[0]
    tours = semester.tour_set.order_by("date")

    if not tours:
        return redirect("guidedtours:add_tour")

    form = ParticipantForm(request.POST or None, tours=tours, semester=semester)
    if form.is_valid():
        participant: Participant = form.save()
        if curr_settings.mail_registration:
            mail: TourMail = curr_settings.mail_registration
            if not mail.send_mail_participant(participant):
                messages.error(
                    request,
                    _(
                        "Could not send the participant the registration email. "
                        "The Participant is registered, but did not receave the confirmation-email. "
                        "The email may be invalid or no Registration-mail may have been set.",
                    ),
                )

        return redirect("guidedtours:view_tour", participant.tour.id)

    context = {
        "semester": semester,
        "form": form,
    }
    return render(request, "guidedtours/signup/signup_internal.html", context)
コード例 #3
0
ファイル: views.py プロジェクト: CommanderStorm/settool-v2
def view_task(request: WSGIRequest, uid: UUID) -> HttpResponse:
    semester: Semester = get_object_or_404(Semester, pk=get_semester(request))
    task = get_object_or_404(Task, pk=uid)

    if not request.user.has_perm("tutors.edit_tutors"):
        return render(request, "tutors/task/view.html", {"task": task})

    form = TaskAssignmentForm(request.POST or None,
                              semester=task.semester,
                              instance=task)
    if form.is_valid():
        form.save()
        task.log(request.user, "Task Assignment edited")
        messages.success(request, f"Saved Task Assignment {task.name}.")

    assigned_tutors = task.tutors.all().order_by("last_name")
    parallel_task_tutors = Tutor.objects.filter(
        Q(task__begin__gte=task.begin) | Q(task__end__lte=task.end),
        Q(task__end__gt=task.begin),
        Q(task__begin__lt=task.end),
    )
    unassigned_tutors = (Tutor.objects.filter(
        semester=semester, status=Tutor.STATUS_ACCEPTED).exclude(
            id__in=assigned_tutors.values("id")).exclude(
                id__in=parallel_task_tutors.values("id")).order_by("last_name")
                         )
    context = {
        "task": task,
        "assigned_tutors": assigned_tutors,
        "unassigned_tutors": unassigned_tutors,
        "assignment_form": form,
    }
    return render(request, "tutors/task/view.html", context)
コード例 #4
0
ファイル: views.py プロジェクト: CommanderStorm/settool-v2
def send_mail(request: WSGIRequest, mail_pk: int) -> HttpResponse:
    mail = get_object_or_404(BagMail, pk=mail_pk)
    selected_companies = request.session["selected_companies"]
    semester: Semester = get_object_or_404(Semester, pk=get_semester(request))
    companies = semester.company_set.filter(
        id__in=selected_companies, ).order_by("name")

    subject, text, from_email = mail.get_mail_company()

    form = forms.Form(request.POST or None)
    if form.is_valid():
        company: Company
        for company in companies:
            company.email_sent_success = mail.send_mail_company(company)
            company.email_sent = True
            company.save()
        return redirect("bags:main_index")

    context = {
        "companies": companies,
        "subject": subject,
        "text": text,
        "from_email": from_email,
        "form": form,
    }

    return render(request, "bags/maintenance/mail/send_mail.html", context)
コード例 #5
0
ファイル: views.py プロジェクト: CommanderStorm/settool-v2
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
コード例 #6
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")
コード例 #7
0
ファイル: views.py プロジェクト: CommanderStorm/settool-v2
def general_settings(request: WSGIRequest) -> HttpResponse:
    semester: Semester = get_object_or_404(Semester, pk=get_semester(request))
    all_tutor_settings = Settings.objects.filter(semester=semester)
    if all_tutor_settings.count() == 0:
        settings = None
    else:
        settings = all_tutor_settings.first()

    form = SettingsAdminForm(request.POST or None,
                             semester=semester,
                             instance=settings)
    if form.is_valid():
        settings = form.save()
        if settings:
            settings.log(request.user, "Settings edited")
            messages.success(request, "Saved Settings.")
        else:
            messages.error(request, "The Settings do not exist.")

        return redirect("tutors:general_settings")

    return render(
        request,
        "tutors/settings/general.html",
        {
            "form": form,
        },
    )
コード例 #8
0
def filter_participants(request: WSGIRequest) -> HttpResponse:
    semester: Semester = get_object_or_404(Semester, pk=get_semester(request))
    try:
        fahrt: Fahrt = semester.fahrt
    except ObjectDoesNotExist:
        messages.error(
            request,
            _("You have to create Fahrt Settings to manage the fahrt"))
        return redirect("fahrt:settings")
    participants = Participant.objects.filter(
        semester=semester).order_by("surname")

    filterform = FilterParticipantsForm(request.POST or None)
    if filterform.is_valid():
        set_request_session_filtered_participants(filterform, participants,
                                                  request, fahrt)
        return redirect("fahrt:filtered_participants")

    context = {
        "participants": participants,
        "filterform": filterform,
    }
    return render(request,
                  "fahrt/maintinance/mail/filter_participants_send_mail.html",
                  context)
コード例 #9
0
def signup_internal(request: WSGIRequest) -> HttpResponse:
    semester: Semester = get_object_or_404(Semester, pk=get_semester(request))

    try:
        semester.fahrt
    except ObjectDoesNotExist:
        messages.error(request, _("Please setup the SETtings for the Fahrt"))
        return redirect("fahrt:settings")

    form = ParticipantForm(request.POST or None, semester=semester)
    if form.is_valid():
        participant: Participant = form.save()
        participant.log(request.user, "Signed up")
        mail = participant.semester.fahrt.mail_registration
        if mail:
            non_liability = get_non_liability(request, participant.pk)
            if not mail.send_mail_registration(participant, non_liability):
                messages.warning(
                    request,
                    _("Could not send the registration email. Make shure you configured the Registration-Mail."
                      ),
                )

        return redirect("fahrt:list_registered")

    context = {
        "semester": semester,
        "form": form,
        "management_view": True,
    }
    return render(request, "fahrt/participants/signup/signup_internal.html",
                  context)
コード例 #10
0
ファイル: views.py プロジェクト: CommanderStorm/settool-v2
def add_giveaway_for_company(request: WSGIRequest,
                             company_pk: int) -> HttpResponse:
    semester: Semester = get_object_or_404(Semester, pk=get_semester(request))
    company: Company = get_object_or_404(Company, id=company_pk)
    form = GiveawayForCompanyForm(request.POST or None,
                                  semester=semester,
                                  company=company)
    if form.is_valid():
        form.save()
        return redirect("bags:list_companys")

    messages.warning(
        request,
        _(
            "The Giveaway-title/group/tag Input does create a new title/group/tag if you choose not to choose one of "
            "the suggested choices.", ),
    )
    context = {
        "form": form,
        "groups": semester.giveawaygroup_set.all(),
        "for_company": True,
    }
    return render(request,
                  "bags/giveaways/giveaway/add_giveaway.html",
                  context=context)
コード例 #11
0
def send_mail(request: WSGIRequest, mail_pk: int) -> HttpResponse:
    mail: FahrtMail = get_object_or_404(FahrtMail, pk=mail_pk)
    selected_participants = request.session["selected_participants"]
    semester: Semester = get_object_or_404(Semester, pk=get_semester(request))
    participants = Participant.objects.filter(
        semester=semester, id__in=selected_participants).order_by("surname")

    subject, text, from_email = mail.get_mail_participant()

    form = forms.Form(request.POST or None)
    failed_participants = []
    if form.is_valid():
        for participant in participants:
            success = mail.send_mail_participant(participant)
            if success:
                participant.log(request.user, f"Mail '{mail}' sent")
            else:
                failed_participants.append(participant)
        if not failed_participants:
            return redirect("fahrt:filter")

    context = {
        "participants": participants,
        "failed_participants": failed_participants,
        "subject": subject,
        "text": text,
        "from_email": from_email,
        "form": form,
    }

    if failed_participants:
        return render(request, "fahrt/maintinance/mail/send_mail_failure.html",
                      context)
    return render(request, "fahrt/maintinance/mail/send_mail.html", context)
コード例 #12
0
ファイル: views.py プロジェクト: CommanderStorm/settool-v2
def list_giveaway_group(request: WSGIRequest) -> HttpResponse:
    semester: Semester = get_object_or_404(Semester, pk=get_semester(request))
    context = {
        "giveaway_groups": semester.giveawaygroup_set.all(),
    }
    return render(request,
                  "bags/giveaways/giveaway_group/list_giveaways_group.html",
                  context=context)
コード例 #13
0
def transport_participant(request: WSGIRequest, participant_uuid: UUID) -> HttpResponse:
    semester: Semester = get_object_or_404(Semester, pk=get_semester(request))
    participant: Participant = get_object_or_404(Participant, pk=participant_uuid, status="confirmed")
    context = {
        "transport_types": get_transport_types(semester.fahrt),
        "calling_participant": participant,
    }
    return render(request, "fahrt/transportation/participant/list_transports.html", context)
コード例 #14
0
ファイル: views.py プロジェクト: CommanderStorm/settool-v2
def task_mail(request: WSGIRequest,
              uid: UUID,
              mail_pk: Optional[int] = None) -> HttpResponse:
    semester: Semester = get_object_or_404(Semester, pk=get_semester(request))
    settings = get_object_or_404(Settings, semester=semester)
    task = get_object_or_404(Task, pk=uid)

    if mail_pk is None:
        mail = settings.mail_task
        if mail is None:
            messages.error(
                request,
                _("The mail_task is not set in the settings. Please choose one option to continue"
                  ))
            return redirect("tutors:general_settings")
    else:
        mail = get_object_or_404(TutorMail, pk=mail_pk)

    tutor_data = extract_tutor_data()
    tutor = Tutor(**tutor_data)
    form = TutorMailAdminForm(
        request.POST or None,
        tutors=task.tutors.all(),
        template=mail,
        semester=semester,
    )
    if form.is_valid():
        tutors = form.cleaned_data["tutors"]
        mail_template: TutorMail = form.cleaned_data["mail_template"]

        for tutor in tutors:
            if mail_template.send_mail_task(tutor, task):
                MailTutorTask.objects.create(tutor=tutor,
                                             mail=mail_template,
                                             task=task)
                task.log(request.user, f"Send mail to {tutor}.")
            else:
                messages.error(
                    request,
                    _("Could not send email to {first_name} {last_name} ({email})."
                      ).format(
                          first_name=tutor.first_name,
                          last_name=tutor.last_name,
                          email=tutor.email,
                      ),
                )

        messages.success(request, f"Send email for {task.name}.")
        return redirect("tutors:list_task")
    subject, text, sender = mail.get_mail_task(tutor, task)
    context = {
        "task": task,
        "from": sender,
        "subject": subject,
        "body": text,
        "form": form,
    }
    return render(request, "tutors/task/mail.html", context)
コード例 #15
0
ファイル: views.py プロジェクト: CommanderStorm/settool-v2
def send_mail(
    request: WSGIRequest,
    status: str = "all",
    mail_pk: Optional[int] = None,
    uid: Optional[UUID] = None,
) -> HttpResponse:
    semester: Semester = get_object_or_404(Semester, pk=get_semester(request))
    settings = get_object_or_404(Settings, semester=semester)
    template = default_tutor_mail(settings, status, mail_pk)

    if template is None:
        raise Http404

    if uid is None:
        if status == "all":
            tutors: QuerySet[Tutor] = Tutor.objects.filter(semester=semester)
        else:
            tutors = Tutor.objects.filter(semester=semester, status=status)
        tutor_data = extract_tutor_data()
        tutor: Tutor = Tutor(**tutor_data)
    else:
        tutors = Tutor.objects.filter(pk=uid)
        tutor = get_object_or_404(Tutor, pk=uid)

    mail_context = Context({
        "tutor": tutor,
    }, )

    subject = Template(template.subject).render(mail_context)
    body = Template(template.text).render(mail_context)

    form = TutorMailAdminForm(
        request.POST or None,
        tutors=tutors,
        template=template,
        semester=semester,
    )
    if form.is_valid():
        tutors = form.cleaned_data["tutors"]
        listed_tutors = list(tutors)
        mail_template = form.cleaned_data["mail_template"]

        send_email_to_all_tutors(mail_template, listed_tutors, request)

        return redirect(f"tutors:list_status_{status}")

    context: dict[str, Any] = {
        "from": template.sender,
        "subject": subject,
        "body": body,
        "form": form,
        "status": status,
        "template": template,
        "tutor": tutor,
    }
    return render(request, "tutors/tutor/mail.html", context)
コード例 #16
0
def list_waitinglist(request: WSGIRequest) -> HttpResponse:
    semester: Semester = get_object_or_404(Semester, pk=get_semester(request))
    participants = Participant.objects.filter(
        semester=semester, status="waitinglist").order_by("-registration_time")

    context = {
        "participants": participants,
    }
    return render(request, "fahrt/participants/list/list_waitinglist.html",
                  context)
コード例 #17
0
def list_cancelled(request: WSGIRequest) -> HttpResponse:
    semester: Semester = get_object_or_404(Semester, pk=get_semester(request))
    participants = Participant.objects.filter(
        semester=semester, status="cancelled").order_by("surname")

    context = {
        "participants": participants,
    }
    return render(request, "fahrt/participants/list/list_cancelled.html",
                  context)
コード例 #18
0
def finanz_simple(request: WSGIRequest) -> HttpResponse:
    semester: Semester = get_object_or_404(Semester, pk=get_semester(request))
    fahrt: Fahrt = get_object_or_404(Fahrt, semester=semester)
    participants: list[Participant] = list(
        Participant.objects.filter(semester=semester,
                                   status="confirmed").all())

    select_participant_form_set = formset_factory(SelectParticipantSwitchForm,
                                                  extra=0)
    participantforms = select_participant_form_set(
        request.POST or None,
        initial=[{
            "id": p.id,
            "selected": p.paid is not None
        } for p in participants],
    )

    if participantforms.is_valid():
        new_paid_participants: list[int] = []
        new_unpaid_participants: list[int] = []
        for participant in participantforms:
            try:
                participant_id = participant.cleaned_data["id"]
            except KeyError:
                continue
            try:
                selected = participant.cleaned_data["selected"]
            except KeyError:
                selected = False
            if selected:
                if Participant.objects.filter(id=participant_id,
                                              paid__isnull=True).exists():
                    new_paid_participants.append(participant_id)
            else:
                if Participant.objects.filter(id=participant_id,
                                              paid__isnull=False).exists():
                    new_unpaid_participants.append(participant_id)
        if new_paid_participants or new_unpaid_participants:
            request.session["new_paid_participants"] = new_paid_participants
            request.session[
                "new_unpaid_participants"] = new_unpaid_participants
            return redirect("fahrt:finanz_confirm")

    participants_and_select = []
    for participant in participants:
        for participant_form in participantforms:
            if participant_form.initial["id"] == participant.id:
                participants_and_select.append((participant, participant_form))
                break
    context = {
        "fahrt": fahrt,
        "participants_and_select": participants_and_select,
        "participantforms": participantforms,
    }
    return render(request, "fahrt/finanz/simple_finanz.html", context)
コード例 #19
0
ファイル: views.py プロジェクト: CommanderStorm/settool-v2
def list_giveaways_arrivals(request: WSGIRequest) -> HttpResponse:
    semester: Semester = get_object_or_404(Semester, pk=get_semester(request))
    giveaways: list[Giveaway] = list(
        Giveaway.objects.filter(company__semester=semester).all())

    select_giveaway_form_set = formset_factory(SelectGiveawaySwitchForm,
                                               extra=0)
    giveawayforms = select_giveaway_form_set(
        request.POST or None,
        initial=[{
            "id": g.id,
            "selected": g.arrived
        } for g in giveaways],
    )

    if giveawayforms.is_valid():
        new_arrived_giveaways: list[int] = []
        new_unarrived_giveaways: list[int] = []
        for giveaway in giveawayforms:
            try:
                giveaway_id = giveaway.cleaned_data["id"]
            except KeyError:
                continue
            try:
                selected = giveaway.cleaned_data["selected"]
            except KeyError:
                selected = False
            if selected:
                if Giveaway.objects.filter(id=giveaway_id,
                                           arrived=False).exists():
                    new_arrived_giveaways.append(giveaway_id)
            else:
                if Giveaway.objects.filter(id=giveaway_id,
                                           arrived=True).exists():
                    new_unarrived_giveaways.append(giveaway_id)
        if new_arrived_giveaways or new_unarrived_giveaways:
            request.session["new_arrived_giveaways"] = new_arrived_giveaways
            request.session[
                "new_unarrived_giveaways"] = new_unarrived_giveaways
            return redirect("bags:confirm_giveaways_arrivals")

    giveaways_and_select = []
    for giveaway in giveaways:
        for giveaway_form in giveawayforms:
            if giveaway_form.initial["id"] == giveaway.id:
                giveaways_and_select.append((giveaway, giveaway_form))
                break
    context = {
        "giveaways_and_select": giveaways_and_select,
        "giveawayforms": giveawayforms,
    }
    return render(
        request,
        "bags/giveaways/giveaway/list/arrival/list_giveaways_arrivals.html",
        context)
コード例 #20
0
ファイル: views.py プロジェクト: CommanderStorm/settool-v2
def add_company(request: WSGIRequest) -> HttpResponse:
    semester: Semester = get_object_or_404(Semester, pk=get_semester(request))

    form = CompanyForm(request.POST or None, semester=semester)
    if form.is_valid():
        company = form.save()

        return redirect("bags:view_company", company.id)

    context = {"form": form}
    return render(request, "bags/company/add_company.html", context)
コード例 #21
0
def filtered_list(request: WSGIRequest) -> HttpResponse:
    filtered_participants = request.session["filtered_participants"]
    semester: Semester = get_object_or_404(Semester, pk=get_semester(request))
    participants = Participant.objects.filter(
        semester=semester, id__in=filtered_participants).order_by("surname")

    form = SelectMailForm(request.POST or None)
    select_participant_form_set = formset_factory(
        SelectParticipantForm,
        extra=0,
    )
    participantforms = select_participant_form_set(
        request.POST or None,
        initial=[{
            "id": p.id,
            "selected": True
        } for p in participants],
    )

    if form.is_valid() and participantforms.is_valid():
        mail = form.cleaned_data["mail"]

        selected_participants = []
        for participant in participantforms:
            try:
                participant_id = participant.cleaned_data["id"]
            except KeyError:
                continue
            try:
                selected = participant.cleaned_data["selected"]
            except KeyError:
                selected = False
            if selected:
                selected_participants.append(participant_id)

        request.session["selected_participants"] = selected_participants
        return redirect("fahrt:send_mail", mail.id)

    participants_and_select = []
    for participant in participants:
        for participant_form in participantforms:
            if participant_form.initial["id"] == participant.id:
                participants_and_select.append((participant, participant_form))
                break

    context = {
        "participants": participants_and_select,
        "form": form,
        "participantforms": participantforms,
    }
    return render(
        request,
        "fahrt/maintinance/mail/list_filtered_participants_send_mail.html",
        context)
コード例 #22
0
ファイル: views.py プロジェクト: CommanderStorm/settool-v2
def tutor_settings(request: WSGIRequest) -> HttpResponse:
    semester: Semester = get_object_or_404(Semester, pk=get_semester(request))

    subject_count = Subject.objects.all().count()
    subjects_existing = SubjectTutorCountAssignment.objects.filter(
        semester=semester)
    subjects_new = []
    if len(subjects_existing) != subject_count:
        for subject in Subject.objects.all():
            if subjects_existing.filter(subject=subject).count() == 0:
                subjects_new.append(
                    SubjectTutorCountAssignment(subject=subject))

    # pylint: disable=invalid-name
    CountFormSet = modelformset_factory(
        SubjectTutorCountAssignment,
        form=SubjectTutorCountAssignmentAdminForm,
        min_num=subject_count,
        validate_min=False,
        max_num=subject_count,
        validate_max=True,
        can_delete=False,
        can_order=False,
    )

    initial_data = [{
        "subject": tutor_subject_assignment.subject.id,
        "wanted": tutor_subject_assignment.wanted,
    } for tutor_subject_assignment in subjects_new]
    answer_formset = CountFormSet(
        request.POST or None,
        queryset=subjects_existing,
        initial=initial_data,
        form_kwargs={"semester": semester},
    )
    if answer_formset.is_valid():
        answer: AnswerForm
        for answer in answer_formset:
            res = answer.save(commit=False)
            res.semester = semester
            res.save()
            res.log(request.user, "Settings for tutor-subject counts edited")
        messages.success(request, "Saved Settings.")

        return redirect("tutors:tutor_settings")

    return render(
        request,
        "tutors/settings/tutors.html",
        {
            "form_set": answer_formset,
        },
    )
コード例 #23
0
ファイル: views.py プロジェクト: CommanderStorm/settool-v2
def import_csv(request: WSGIRequest) -> HttpResponse:
    semester: Semester = get_object_or_404(Semester, pk=get_semester(request))
    file_upload_form = CSVFileUploadForm(request.POST or None, request.FILES)
    if file_upload_form.is_valid():
        import_company_csv_to_db(request.FILES["file"], semester)
        messages.success(request, _("The File was successfully uploaded"))
        return redirect("bags:main_index")
    return render(
        request,
        "bags/import-export/import_csv.html",
        {"form": file_upload_form},
    )
コード例 #24
0
ファイル: views.py プロジェクト: CommanderStorm/settool-v2
def list_grouped_giveaways(request: WSGIRequest) -> HttpResponse:
    semester: Semester = get_object_or_404(Semester, pk=get_semester(request))
    context = {
        "giveaway_groups":
        [(ggroup, ggroup.giveaway_set.filter(company__semester=semester).all())
         for ggroup in semester.giveawaygroup_set.all()],
        "ungrouped_giveaways":
        Giveaway.objects.filter(Q(group=None) & Q(company__semester=semester)),
    }
    return render(request,
                  "bags/giveaways/giveaway/list/list_grouped_giveaways.html",
                  context=context)
コード例 #25
0
ファイル: views.py プロジェクト: CommanderStorm/settool-v2
def add_giveaway_group(request: WSGIRequest) -> HttpResponse:
    semester: Semester = get_object_or_404(Semester, pk=get_semester(request))
    form = GiveawayGroupForm(request.POST or None, semester=semester)
    if form.is_valid():
        form.save()
        return redirect("bags:list_grouped_giveaways")

    context = {
        "form": form,
    }
    return render(request,
                  "bags/giveaways/giveaway_group/add_giveaway_group.html",
                  context)
コード例 #26
0
def transport_mangagement(request: WSGIRequest) -> HttpResponse:
    semester: Semester = get_object_or_404(Semester, pk=get_semester(request))
    try:
        fahrt: Fahrt = semester.fahrt
    except ObjectDoesNotExist:
        messages.error(request, _("You have to create Fahrt Settings to manage the fahrt"))
        return redirect("fahrt:settings")
    context = {"transport_types": get_transport_types(fahrt)}
    return render(
        request,
        "fahrt/transportation/management/list_transports.html",
        context,
    )
コード例 #27
0
def add_tour(request: WSGIRequest) -> HttpResponse:
    semester: Semester = get_object_or_404(Semester, pk=get_semester(request))

    form = TourForm(request.POST or None, semester=semester)

    if form.is_valid():
        form.save()

        return redirect("guidedtours:list_tours")

    context = {
        "form": form,
    }
    return render(request, "guidedtours/tours/add_tour.html", context)
コード例 #28
0
def add_transport_option(request: WSGIRequest, participant_uuid: UUID, transport_type: int) -> HttpResponse:
    semester: Semester = get_object_or_404(Semester, pk=get_semester(request))

    try:
        fahrt: Fahrt = semester.fahrt
    except ObjectDoesNotExist:
        messages.error(
            request,
            _(
                "The Admins have not created a Fahrt for the Semester you are in. "
                "Please contact them with this error message.",
            ),
        )
        return redirect("fahrt:transport_participant", participant_uuid)

    participant: Participant = get_object_or_404(Participant, pk=participant_uuid, status="confirmed")
    if transport_type not in [Transportation.CAR, Transportation.TRAIN]:
        raise Http404()
    transport: Optional[Transportation] = participant.transportation
    if transport and transport.creator == participant:
        if transport.transport_type == transport_type:
            messages.error(request, _("You can not create a new Transport-option of the same type"))
            return redirect("fahrt:transport_participant", participant_uuid)
        if transport.participant_set.count() != 1:
            messages.error(
                request,
                _("A Transportation-option cannot be without creator, if it has people depending upon it."),
            )
            return redirect("fahrt:transport_participant", participant_uuid)

    form = TransportOptionForm(
        request.POST or None,
        transport_type=transport_type,
        creator=participant,
        fahrt=fahrt,
    )
    if form.is_valid():
        if transport and transport.creator == participant:
            transport.delete()  # we checked before that we are the only participant of this Transport option
        form.save(commit=True)
        participant.log(
            None,
            _("created Transport Option {transport} and assigned him/herself").format(transport=transport),
        )
        return redirect("fahrt:transport_participant", participant_uuid)
    context = {
        "form": form,
        "calling_participant": participant,
    }
    return render(request, "fahrt/transportation/participant/add_transport.html", context)
コード例 #29
0
ファイル: views.py プロジェクト: CommanderStorm/settool-v2
def list_companys(request: WSGIRequest) -> HttpResponse:
    semester: Semester = get_object_or_404(Semester, pk=get_semester(request))
    filterform = FilterCompaniesForm(request.POST or None)
    companies = get_possibly_filtered_companies(filterform, semester)

    mailform = SelectMailForm(request.POST if "mailform" in
                              request.POST else None)
    select_company_form_set = formset_factory(SelectCompanyForm, extra=0)
    companyforms = select_company_form_set(
        request.POST if "mailform" in request.POST else None,
        initial=[{
            "id": c.id,
            "selected": True
        } for c in companies],
    )

    if "mailform" in request.POST and mailform.is_valid(
    ) and companyforms.is_valid():
        mail = mailform.cleaned_data["mail"]

        selected_companies = []
        for company in companyforms:
            try:
                company_id = company.cleaned_data["id"]
            except KeyError:
                continue
            try:
                selected = company.cleaned_data["selected"]
            except KeyError:
                selected = False
            if selected:
                selected_companies.append(company_id)

        request.session["selected_companies"] = selected_companies
        return redirect("bags:send_mail", mail.id)

    companies_and_select = []
    for company in companies:
        for company_form in companyforms:
            if company_form.initial["id"] == company.id:
                companies_and_select.append((company, company_form))
                break

    context = {
        "companies_and_select": companies_and_select,
        "filterform": filterform,
        "mailform": mailform,
        "companyforms": companyforms,
    }
    return render(request, "bags/company/list_companys.html", context)
コード例 #30
0
def dashboard(request: WSGIRequest) -> HttpResponse:
    tours = (
        Tour.objects.filter(Q(semester=get_semester(request)) & Q(date__gte=date.today()))
        .values("capacity", "name", "date")
        .annotate(registered=Count("participant"))
        .order_by("date")
    )

    context = {
        "tour_labels": [f"{tour['name']} {tour['date'].strftime('%d.%m %H')}Uhr" for tour in tours],
        "tour_registrations": [tour["registered"] for tour in tours],
        "tour_capacity": [tour["capacity"] for tour in tours],
    }
    return render(request, "guidedtours/tour_dashboard.html", context)