diff --git a/faerun_calendar/admin.py b/faerun_calendar/admin.py
index 8c38f3f..98c2da3 100644
--- a/faerun_calendar/admin.py
+++ b/faerun_calendar/admin.py
@@ -1,3 +1,8 @@
from django.contrib import admin
+from .models import CalendarData
+from .models import MonthData
+from .models import Event
-# Register your models here.
+admin.site.register(CalendarData)
+admin.site.register(MonthData)
+admin.site.register(Event)
diff --git a/faerun_calendar/models.py b/faerun_calendar/models.py
index 71a8362..50bc577 100644
--- a/faerun_calendar/models.py
+++ b/faerun_calendar/models.py
@@ -1,3 +1,79 @@
from django.db import models
-# Create your models here.
+
+class FaerunDate:
+ LAST_MONTH = 18
+ LEAP_MONTH = 11
+ ONE_DAY_MONTHS = (2, 6, 10, 11, 14, 17)
+ LAST_DAY = 30
+
+ def __init__(self, year: int, month: int, day: int):
+ self.year = year
+ self.month = month
+ self.day = day
+ self.is_leap_year = self._is_leap_year()
+ self.is_valid = self._is_valid()
+
+ def __repr__(self):
+ return f'{type(self).__name__}({self.year}, {self.month}, {self.day})'
+
+ def _is_leap_year(self) -> bool:
+ if self.year == 0:
+ return False
+ elif self.year % 400 == 0:
+ return True
+ elif self.year % 100 == 0:
+ return False
+ elif self.year % 4 == 0:
+ return True
+ return False
+
+ def _is_valid(self) -> bool:
+ if self.year == 0:
+ return False
+
+ if not 0 < self.month <= FaerunDate.LAST_MONTH:
+ return False
+
+ if not self.is_leap_year and self.month == self.__class__.LEAP_MONTH:
+ return False
+
+ if not 0 < self.day <= FaerunDate.LAST_DAY:
+ return False
+
+ if self.day > 1 and self.month in FaerunDate.ONE_DAY_MONTHS:
+ return False
+
+ return True
+
+
+class CalendarData(models.Model):
+ current_year = models.SmallIntegerField('CurrentYear')
+ current_month = models.SmallIntegerField('CurrentMonth')
+ current_day = models.SmallIntegerField('CurrentDay')
+ leap_month = models.SmallIntegerField('LeapMonth')
+
+ def __str__(self):
+ return f'({self.current_year}, {self.current_month}, {self.current_day}, {self.leap_month})'
+
+
+class MonthData(models.Model):
+ number = models.SmallIntegerField('Number', unique=True)
+ name = models.CharField('Name', max_length=64, unique=True)
+ folkname = models.CharField('Folkname', max_length=64, blank=True)
+ is_oneday = models.BooleanField('IsOneday')
+
+ def __str__(self):
+ return f'({self.number}, {self.name}, {self.folkname}, {self.is_oneday})'
+
+
+class Event(models.Model):
+ year = models.SmallIntegerField('Year')
+ month = models.SmallIntegerField('Month')
+ day = models.SmallIntegerField('Day')
+ time = models.TimeField('Time')
+ title = models.CharField('Title', max_length=250)
+ description = models.TextField('Description', max_length=2500)
+
+ def __str__(self):
+ return f'({self.year}, {self.month}, {self.day}, {self.time}, {self.title})'
diff --git a/faerun_calendar/static/faerun_calendar/css/main.css b/faerun_calendar/static/faerun_calendar/css/main.css
index 30960ed..d5f8d36 100644
--- a/faerun_calendar/static/faerun_calendar/css/main.css
+++ b/faerun_calendar/static/faerun_calendar/css/main.css
@@ -12,6 +12,10 @@ table.month, table.month th, table.month td {
background: gainsboro;
}
+table.month th {
+ text-align: center;
+}
+
table.month td {
text-align: right;
}
diff --git a/faerun_calendar/templates/faerun_calendar/calendar.html b/faerun_calendar/templates/faerun_calendar/calendar.html
deleted file mode 100644
index 992e9c8..0000000
--- a/faerun_calendar/templates/faerun_calendar/calendar.html
+++ /dev/null
@@ -1,22 +0,0 @@
-
- {% include 'faerun_calendar/month.html' with title="Хаммер" subtitle="Глубокозимье" %}
- {% include 'faerun_calendar/month.html' with title="Зимний солнцеворот" subtitle="Мертвозимье" oneday=1 %}
- {% include 'faerun_calendar/month.html' with title="Альтурик" subtitle="Коготь зимы" %}
- {% include 'faerun_calendar/month.html' with title="Чез" subtitle="Коготь закатов" %}
- {% include 'faerun_calendar/month.html' with title="Тарсак" subtitle="Коготь бурь" %}
- {% include 'faerun_calendar/month.html' with title="Зеленотравье" oneday=1 %}
-
- {% include 'faerun_calendar/month.html' with title="Миртул" subtitle="Таяние" %}
- {% include 'faerun_calendar/month.html' with title="Кайторн" subtitle="Время цветов" %}
- {% include 'faerun_calendar/month.html' with title="Флеймрул" subtitle="Разгар лета" %}
- {% include 'faerun_calendar/month.html' with title="Летний солнцеворот" oneday=1 %}
- {% include 'faerun_calendar/month.html' with title="Шильдмит*" oneday=1 %}
- {% include 'faerun_calendar/month.html' with title="Элесис" subtitle="Солнцестояние" %}
-
- {% include 'faerun_calendar/month.html' with title="Элейнт" subtitle="Увядание" %}
- {% include 'faerun_calendar/month.html' with title="Праздник урожая" oneday=1 %}
- {% include 'faerun_calendar/month.html' with title="Марпенот" subtitle="Листопад" %}
- {% include 'faerun_calendar/month.html' with title="Уктар" subtitle="Перегной" %}
- {% include 'faerun_calendar/month.html' with title="Пир луны" oneday=1 %}
- {% include 'faerun_calendar/month.html' with title="Найтал" subtitle="Спячка" %}
-
diff --git a/faerun_calendar/templates/faerun_calendar/index.html b/faerun_calendar/templates/faerun_calendar/index.html
index cc3a8f3..904fb96 100644
--- a/faerun_calendar/templates/faerun_calendar/index.html
+++ b/faerun_calendar/templates/faerun_calendar/index.html
@@ -13,7 +13,14 @@
{% block content %}
Календарь
- {% include 'faerun_calendar/calendar.html' %}
+
{{year}}
+
+ {% for month in month_data %}
+ {% if month.number != calendar_data.leap_month or is_leap_year %}
+ {% include 'faerun_calendar/month.html' with month=month month_days=month_days %}
+ {% endif %}
+ {% endfor %}
+
{% endblock %}
diff --git a/faerun_calendar/templates/faerun_calendar/month.html b/faerun_calendar/templates/faerun_calendar/month.html
index 9dd9a39..b424da8 100644
--- a/faerun_calendar/templates/faerun_calendar/month.html
+++ b/faerun_calendar/templates/faerun_calendar/month.html
@@ -1,53 +1,32 @@
- | {{title}} |
+ {{month.name}} |
- {% if subtitle %}
- {{subtitle}} |
+ {% if month.folkname %}
+ {{month.folkname}} |
{% endif %}
- {% if oneday != 1 %}
-
- | 1 |
- 2 |
- 3 |
- 4 |
- 5 |
- 6 |
- 7 |
- 8 |
- 9 |
- 10 |
-
-
- | 11 |
- 12 |
- 13 |
- 14 |
- 15 |
- 16 |
- 17 |
- 18 |
- {% if title == "Миртул" %}
- 19 |
- {% else %}
- 19 |
- {% endif %}
- 20 |
-
-
- | 21 |
- 22 |
- 23 |
- 24 |
- 25 |
- 26 |
- 27 |
- 28 |
- 29 |
- 30 |
-
+ {% if not month.is_oneday %}
+ {% for day in month_days %}
+ {% if forloop.counter0|divisibleby:10 %}
+
+ {% endif %}
+
+ {% if year == calendar_data.current_year and month.number == calendar_data.current_month and day == calendar_data.current_day %}
+ |
+ {% else %}
+ |
+ {% endif %}
+
+ {{day}}
+
+ |
+
+ {% if forloop.counter|divisibleby:10 %}
+
+ {% endif %}
+ {% endfor %}
{% endif %}
diff --git a/faerun_calendar/tests.py b/faerun_calendar/tests.py
index 7ce503c..aca85a5 100644
--- a/faerun_calendar/tests.py
+++ b/faerun_calendar/tests.py
@@ -1,3 +1,43 @@
from django.test import TestCase
+from .models import FaerunDate
+
+
+class FaerunDateTestCase(TestCase):
+ class TestDate:
+ def __init__(self, date: FaerunDate, repr: str, is_leap_year: bool, is_valid: bool):
+ self.date = date
+ self.repr = repr
+ self.is_leap_year = is_leap_year
+ self.is_valid = is_valid
+
+ def setUp(self):
+ self.dates = (
+ FaerunDateTestCase.TestDate(FaerunDate(0, 0, 0), 'FaerunDate(0, 0, 0)', False, False),
+ FaerunDateTestCase.TestDate(FaerunDate(1, -1, 1), 'FaerunDate(1, -1, 1)', False, False),
+ FaerunDateTestCase.TestDate(FaerunDate(1, 1, 1), 'FaerunDate(1, 1, 1)', False, True),
+ FaerunDateTestCase.TestDate(FaerunDate(4, 1, 1), 'FaerunDate(4, 1, 1)', True, True),
+ FaerunDateTestCase.TestDate(FaerunDate(4, -1, 1), 'FaerunDate(4, -1, 1)', True, False),
+ FaerunDateTestCase.TestDate(FaerunDate(4, 0, 1), 'FaerunDate(4, 0, 1)', True, False),
+ FaerunDateTestCase.TestDate(FaerunDate(4, 19, 1), 'FaerunDate(4, 19, 1)', True, False),
+ FaerunDateTestCase.TestDate(FaerunDate(4, 1, -1), 'FaerunDate(4, 1, -1)', True, False),
+ FaerunDateTestCase.TestDate(FaerunDate(4, 1, 0), 'FaerunDate(4, 1, 0)', True, False),
+ FaerunDateTestCase.TestDate(FaerunDate(4, 1, 31), 'FaerunDate(4, 1, 31)', True, False),
+ FaerunDateTestCase.TestDate(FaerunDate(4, 2, 2), 'FaerunDate(4, 2, 2)', True, False),
+ FaerunDateTestCase.TestDate(FaerunDate(4, 1, 2), 'FaerunDate(4, 1, 2)', True, True),
+ FaerunDateTestCase.TestDate(FaerunDate(1, 11, 1), 'FaerunDate(1, 11, 1)', False, False),
+ FaerunDateTestCase.TestDate(FaerunDate(4, 11, 1), 'FaerunDate(4, 11, 1)', True, True),
+ )
+
+ def test_repr(self):
+ for date in self.dates:
+ self.assertEqual(date.date.__repr__(), date.repr)
+
+ def test_leap(self):
+ for date in self.dates:
+ self.assertEqual(date.date.is_leap_year, date.is_leap_year, date.date.__repr__())
+
+ def test_valid(self):
+ for date in self.dates:
+ self.assertEqual(date.date.is_valid, date.is_valid, date.date.__repr__())
+
-# Create your tests here.
diff --git a/faerun_calendar/views.py b/faerun_calendar/views.py
index 7436291..2dc4efc 100644
--- a/faerun_calendar/views.py
+++ b/faerun_calendar/views.py
@@ -1,6 +1,31 @@
from django.shortcuts import render
+from .models import CalendarData
+from .models import MonthData
def index(request):
- return render(request, 'faerun_calendar/index.html')
+ def is_leap_year(year) -> bool:
+ if year == 0:
+ return False
+ elif year % 400 == 0:
+ return True
+ elif year % 100 == 0:
+ return False
+ elif year % 4 == 0:
+ return True
+ return False
+ calendar_data = CalendarData.objects.first()
+ month_data = MonthData.objects.all()
+
+ year = 1492
+
+ params = {
+ 'calendar_data': calendar_data,
+ 'month_data': month_data,
+ 'month_days': tuple(i+1 for i in range(30)),
+ 'year': year,
+ 'is_leap_year': is_leap_year(year),
+ }
+
+ return render(request, 'faerun_calendar/index.html', params)
diff --git a/links/views.py b/links/views.py
index 58d2aa4..f03a8a1 100644
--- a/links/views.py
+++ b/links/views.py
@@ -5,4 +5,4 @@ from .models import Link
def index(request):
links = Link.objects.order_by('order')
- return render(request, 'links/index.html', {'links': links})
\ No newline at end of file
+ return render(request, 'links/index.html', {'links': links})