[Docs] Add/update docstrings and license text in every file

This commit is contained in:
2018-07-03 08:22:58 +02:00
parent a5bf841898
commit 2f66fdb83e
8 changed files with 230 additions and 2 deletions

View File

@@ -1,3 +1,22 @@
# Calendar.social
# Copyright (C) 2018 Gergely Polonkai
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""Gregorian calendar system for Calendar.social
"""
from datetime import datetime, timedelta
from functools import wraps
@@ -7,6 +26,9 @@ from . import CalendarSystem
def to_timestamp(func):
"""Decorator that converts the return value of a function from `datetime` to a UNIX timestamp
"""
@wraps(func)
def decorator(*args, **kwargs):
return func(*args, **kwargs).timestamp()
@@ -15,6 +37,9 @@ def to_timestamp(func):
class GregorianCalendar(CalendarSystem):
"""Gregorian calendar system for Calendar.social
"""
__name__ = _('Gregorian')
__has_months__ = True
@@ -75,15 +100,24 @@ class GregorianCalendar(CalendarSystem):
@property
@to_timestamp
def prev_year(self):
"""Returns the timestamp of the same date in the previous year
"""
return self.timestamp.replace(year=self.timestamp.year - 1)
@property
def prev_year_year(self):
"""The number of the previous year
"""
return self.timestamp.replace(year=self.timestamp.year - 1).year
@property
@to_timestamp
def prev_month(self):
"""Returns the timestamp of the same day in the previous month
"""
if self.timestamp.month == 1:
return self.prev_year.replace(month=12)
@@ -91,6 +125,9 @@ class GregorianCalendar(CalendarSystem):
@property
def prev_month_name(self):
"""The name of the previous month
"""
if self.timestamp.month == 1:
timestamp = self.prev_year.replace(month=12)
else:
@@ -101,6 +138,9 @@ class GregorianCalendar(CalendarSystem):
@property
@to_timestamp
def next_month(self):
"""Returns the timestamp of the same day in the next month
"""
if self.timestamp.month == 12:
return self.next_year.replace(month=1)
@@ -108,6 +148,9 @@ class GregorianCalendar(CalendarSystem):
@property
def next_month_name(self):
"""The name of the next month
"""
if self.timestamp.month == 12:
timestamp = self.prev_year.replace(month=1)
else:
@@ -118,14 +161,23 @@ class GregorianCalendar(CalendarSystem):
@property
@to_timestamp
def next_year(self):
"""Returns the timestamp of the same date in the next year
"""
return self.timestamp.replace(year=self.timestamp.year + 1)
@property
def next_year_year(self):
"""The number of the next year
"""
return self.timestamp.replace(year=self.timestamp.year + 1).year
@property
def has_today(self):
"""``True`` if the set month holds todays date
"""
now = datetime.utcnow()
month_start_timestamp = self.timestamp.replace(day=1,
hour=0,
@@ -144,6 +196,9 @@ class GregorianCalendar(CalendarSystem):
@staticmethod
def day_events(date, user=None):
"""Returns all events for a given day
"""
from ..models import Event
events = Event.query