def anonymize_fahrt(semester: Semester, log_name: str) -> bool: current_fahrt: Optional[m_fahrt.Fahrt] = get_or_none(m_fahrt.Fahrt, semester=semester) if current_fahrt and date_is_too_old(current_fahrt.date, log_name): # fahrt is save to anonymize for this semester m_fahrt.Transportation.objects.filter( fahrt__semester=semester).delete() m_fahrt.TransportationComment.objects.filter( sender__semester=semester).delete() semester_participants = m_fahrt.Participant.objects.filter( semester=semester) semester_participants.exclude( status=m_fahrt.Participant.STATUS_CONFIRMED).delete() participant: m_fahrt.Participant for participant in semester_participants.all(): participant.registration_time = timezone.now() participant.firstname = f"f {participant.pk}" participant.surname = f"l {participant.pk}" participant.birthday = timezone.now().date() participant.email = f"{participant.pk}@example.com" participant.phone = "" participant.mobile = "" participant.allergies = "" participant.publish_contact_to_other_paricipants = False participant.mailinglist = False participant.comment = "" participant.save() return True return False
def fahrt_date_reminder(semester: Semester, today: date) -> None: current_fahrt: m_fahrt.Fahrt = get_or_none(m_fahrt.Fahrt, semester=semester) if current_fahrt and current_fahrt.mail_reminder: lookup_day = today + timedelta( days=max(current_fahrt.reminder_tour_days_count, 0)) if current_fahrt.date == lookup_day: participant: m_fahrt.Participant for participant in m_fahrt.Participant.objects.filter( semester=semester, status="confirmed"): current_fahrt.mail_reminder.send_mail_participant(participant)
def tutor_reminder(semester: Semester, today: date) -> None: tutor_settings: m_tutors.Settings = get_or_none(m_tutors.Settings, semester=semester) if tutor_settings and tutor_settings.mail_reminder: lookup_day = today + timedelta( days=max(tutor_settings.reminder_tour_days_count, 0)) task: m_tutors.Task for task in m_tutors.Task.objects.filter( Q(semester=semester) & Q(begin__day=lookup_day.day) # begin is datetime & Q(begin__month=lookup_day.month) & Q(begin__year=lookup_day.year), ): tutor: m_tutors.Tutor for tutor in list(task.tutors.all()): tutor_settings.mail_reminder.send_mail_task(tutor, task)
def guidedtour_reminder(semester: Semester, today: date) -> None: setting: m_guidedtours.Setting = get_or_none(m_guidedtours.Setting, semester=semester) if setting and setting.mail_reminder: lookup_day = today + timedelta( days=max(setting.reminder_tour_days_count, 0)) tour: m_guidedtours.Tour for tour in semester.tour_set.filter( Q(date__day=lookup_day.day) # date is datetime & Q(date__month=lookup_day.month) & Q(date__year=lookup_day.year), ): tour_participants: list[m_guidedtours.Participant] = list( tour.participant_set.all()) for participant in tour_participants: if participant.on_the_tour: setting.mail_reminder.send_mail_participant(participant)
def dashboard(request: WSGIRequest) -> HttpResponse: semester: Semester = get_object_or_404(Semester, pk=get_semester(request)) companies: QuerySet[Company] = Company.objects.filter(semester=semester) g_companies: QuerySet[Company] = companies.filter(giveaway__isnull=False) giveaways: QuerySet[Giveaway] = Giveaway.objects.filter( company__semester=semester) g_by_group = list( giveaways.filter(group__isnull=False).values("group").annotate( group_count=Count("group"))) g_by_group.append( { "group": None, "group_count": giveaways.filter(group__isnull=True).count(), }, ) g_by_item_count_labels: list[str] = [] g_by_item_count_data: list[int] = [] g_item_count_max = giveaways.order_by("-item_count").first() g_item_count_min = giveaways.order_by("item_count").first() if g_item_count_max and g_item_count_min: # do giveaways exist? item_count_max_range = math.ceil( g_item_count_max.item_count / 100) * 100 item_count_min_range = math.floor( g_item_count_min.item_count / 100) * 100 for i in range(item_count_min_range, item_count_max_range, 100): g_by_item_count_labels.append(f"{i} - {i + 99}") g_by_item_count_data.append( giveaways.filter(item_count__gte=i, item_count__lte=i + 99).count()) context = { "c_by_giveaway_data": [ companies.filter(giveaway__isnull=False).count(), companies.filter(giveaway__isnull=True).count(), ], "c_by_contact_again_data": [ companies.filter(contact_again=True).count(), companies.filter(contact_again=False).count(), ], "c_by_last_year_data": [ companies.filter(last_year=True).count(), companies.filter(last_year=False).count(), ], "c_by_promise_data": [ companies.filter(promise=True).count(), companies.filter(promise=False).count(), ], "c_by_email_sent_data": [ companies.filter(email_sent=True, email_sent_success=False).count(), companies.filter(email_sent=True, email_sent_success=True).count(), companies.filter(email_sent=False).count(), ], "gc_by_contact_again_data": [ g_companies.filter(contact_again=True).count(), g_companies.filter(contact_again=False).count(), ], "gc_by_last_year_data": [ g_companies.filter(last_year=True).count(), g_companies.filter(last_year=False).count(), ], "gc_by_promise_data": [ g_companies.filter(promise=True).count(), g_companies.filter(promise=False).count(), ], "gc_by_email_sent_data": [ g_companies.filter(email_sent=True, email_sent_success=False).count(), g_companies.filter(email_sent=True, email_sent_success=True).count(), g_companies.filter(email_sent=False).count(), ], "gc_by_giveaway_arrived_data": [ g_companies.filter(giveaway__arrived=True).count(), g_companies.filter(giveaway__arrived=False).count(), ], "g_by_group_labels": [ str( get_or_none(GiveawayGroup, id=group["group"]) or _("NOT assigned to a giveaway-group")) for group in g_by_group ], "g_by_group_data": [group["group_count"] for group in g_by_group], "g_by_item_count_labels": g_by_item_count_labels, "g_by_item_count_data": g_by_item_count_data, } return render(request, "bags/bags_dashboard.html", context=context)