forked from gergely/calendar-social
[Refactor] Rename the app module to calsocial
Just for clarity
This commit is contained in:
15
calsocial/calendar_system/__init__.py
Normal file
15
calsocial/calendar_system/__init__.py
Normal file
@@ -0,0 +1,15 @@
|
||||
class CalendarSystem:
|
||||
__has_months__ = False
|
||||
__has_weeks__ = False
|
||||
|
||||
@property
|
||||
def day_names(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
@property
|
||||
def month(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
@property
|
||||
def days(self):
|
||||
raise NotImplementedError()
|
64
calsocial/calendar_system/gregorian.py
Normal file
64
calsocial/calendar_system/gregorian.py
Normal file
@@ -0,0 +1,64 @@
|
||||
from datetime import datetime, timedelta
|
||||
from flask_babel import lazy_gettext as _
|
||||
|
||||
from . import CalendarSystem
|
||||
|
||||
|
||||
class GregorianCalendar(CalendarSystem):
|
||||
__name__ = _('Gregorian')
|
||||
|
||||
__has_months__ = True
|
||||
|
||||
START_DAY = 0
|
||||
END_DAY = 7
|
||||
|
||||
day_names = (
|
||||
_('Monday'),
|
||||
_('Tuesday'),
|
||||
_('Wednesday'),
|
||||
_('Thursday'),
|
||||
_('Friday'),
|
||||
_('Saturday'),
|
||||
_('Sunday'),
|
||||
)
|
||||
|
||||
def __init__(self, timestamp):
|
||||
self.timestamp = datetime.utcfromtimestamp(timestamp)
|
||||
|
||||
@property
|
||||
def month(self):
|
||||
return self.timestamp.strftime("%B, %Y")
|
||||
|
||||
@property
|
||||
def days(self):
|
||||
day_list = []
|
||||
|
||||
start_day = self.timestamp.replace(day=1)
|
||||
|
||||
while start_day.weekday() > self.START_DAY:
|
||||
start_day -= timedelta(days=1)
|
||||
|
||||
day_list.append(start_day)
|
||||
current_day = start_day
|
||||
|
||||
while current_day.weekday() < self.END_DAY and current_day.month <= self.timestamp.month:
|
||||
current_day += timedelta(days=1)
|
||||
day_list.append(current_day)
|
||||
|
||||
return day_list
|
||||
|
||||
def day_events(self, date, user=None):
|
||||
from ..models import Event
|
||||
|
||||
events = Event.query
|
||||
|
||||
if user:
|
||||
events = events.filter(Event.user == user)
|
||||
|
||||
start_timestamp = date.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
end_timestamp = start_timestamp + timedelta(days=1)
|
||||
|
||||
events = events.filter(((Event.start_time >= start_timestamp) & (Event.start_time < end_timestamp)) |
|
||||
((Event.end_time >= start_timestamp) & (Event.end_time < end_timestamp)))
|
||||
|
||||
return events
|
Reference in New Issue
Block a user