auto handle events

This commit is contained in:
Dominic DiTaranto 2024-11-17 17:15:18 -05:00
parent c76633eb69
commit b7385a3c68
3 changed files with 53 additions and 3 deletions

35
scripts/bp_create.py Normal file
View File

@ -0,0 +1,35 @@
import datetime
from django.utils import timezone
from web.models import Event
start_date = timezone.now() # This should always be the first of a month or the day after the last event's end date
end_date = None
event_duration = 7
events_to_create = 100
participants = 5
current_month = start_date.strftime('%B')
current_month_count = 1 # change this to +1 of whatever the last band practice is
for i in range(events_to_create):
if start_date.strftime('%B') != current_month:
current_month = start_date.strftime('%B')
current_month_count = 1
end_date = start_date + datetime.timedelta(days=event_duration)
name = f'[BP] {current_month} {current_month_count}'
e = Event(
start_date=start_date,
end_date=end_date,
name=name,
participants=participants
)
e.save()
start_date = end_date + datetime.timedelta(days=1)
current_month_count += 1

15
scripts/bp_deactivate.py Normal file
View File

@ -0,0 +1,15 @@
from django.utils import timezone
from web.models import Event
def deactivate():
today = timezone.now()
active_events = Event.objects.filter(active=True).all()
for event in active_events:
if 'BP' in event.name:
if event.end_date < today:
event.active = False
event.save()

View File

@ -2,17 +2,17 @@ from datetime import timedelta
from django.contrib.auth import update_session_auth_hash
from django.contrib.auth.decorators import login_required
from django.contrib.auth.forms import PasswordChangeForm
from django.contrib.auth.views import PasswordChangeView
from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse_lazy
from scripts.bp_deactivate import deactivate
from web.models import Event, Availability
@login_required()
def index(request):
deactivate()
parsed_events = []
for active_event in Event.objects.filter(active=True).order_by('start_date'):
for active_event in Event.objects.filter(active=True).order_by('start_date')[:10]:
data = {
'id': active_event.id,
'name': active_event.name,