heroweb/lib/webcomponents/calendar/model.py
2024-09-01 20:00:13 +02:00

43 lines
1.4 KiB
Python

from datetime import datetime
class Event:
def __init__(self, title, date, color_from, color_to):
self.title = title
self.date = date
self.color_from = color_from
self.color_to = color_to
class Day:
def __init__(self, date, events=None):
self.date = date
self.number = date.day
self.class = self._get_class(date)
self.events = events or []
def _get_class(self, date):
today = datetime.today().date()
if date < today:
return 'past'
elif date == today:
return 'today'
else:
return 'future'
class Agenda:
def __init__(self):
self.days_of_week = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
self.current_day = datetime.today().strftime('%A')
self.current_year = datetime.today().year
self.calendar = self._generate_calendar()
def _generate_calendar(self):
# Replace this with logic to generate weeks and days for the current month
# This is a simplified example
days = []
for i in range(1, 32):
date = datetime(datetime.today().year, datetime.today().month, i).date()
event_list = [Event("Event {}".format(i), date, "blue-500", "cyan-500")]
days.append(Day(date, events=event_list))
weeks = [days[i:i+7] for i in range(0, len(days), 7)]
return weeks