diff options
author | Dominic DiTaranto <domdit@gmail.com> | 2024-11-17 17:15:18 -0500 |
---|---|---|
committer | Dominic DiTaranto <domdit@gmail.com> | 2024-11-17 17:15:18 -0500 |
commit | b7385a3c68789d3b77eb4a03868c9185fd1d4e8e (patch) | |
tree | 498f9664ff2f77922631794b22b46a3a0a66f516 /scripts | |
parent | c76633eb69cc31d7d1827dd6fd1b1bcb2a3f1c4b (diff) |
auto handle events
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/bp_create.py | 35 | ||||
-rw-r--r-- | scripts/bp_deactivate.py | 15 |
2 files changed, 50 insertions, 0 deletions
diff --git a/scripts/bp_create.py b/scripts/bp_create.py new file mode 100644 index 0000000..41d53b6 --- /dev/null +++ b/scripts/bp_create.py @@ -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 + + diff --git a/scripts/bp_deactivate.py b/scripts/bp_deactivate.py new file mode 100644 index 0000000..1a125d5 --- /dev/null +++ b/scripts/bp_deactivate.py @@ -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() + |