| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
import datetime |
| 19 |
|
| 20 |
from EmailReminder.Event import EventModel |
| 21 |
from EmailReminder.Utils import readXMLValue, writeXMLValue |
| 22 |
|
| 23 |
|
| 24 |
def formatDate(year, month, day): |
| 25 |
if not month or not day: |
| 26 |
return '' |
| 27 |
|
| 28 |
try: |
| 29 |
if not year: |
| 30 |
|
| 31 |
return datetime.date(1980, int(month), int(day)).strftime('%m-%d') |
| 32 |
return datetime.date(int(year), int(month), int(day)).isoformat() |
| 33 |
except ValueError: |
| 34 |
return '' |
| 35 |
|
| 36 |
|
| 37 |
def parseDate(dateString): |
| 38 |
try: |
| 39 |
if len(dateString) == 5: |
| 40 |
date = datetime.datetime.strptime(dateString, '%m-%d') |
| 41 |
return {'year': None, 'month': date.month, 'day': date.day} |
| 42 |
date = datetime.datetime.strptime(dateString, '%Y-%m-%d') |
| 43 |
except ValueError: |
| 44 |
date = datetime.datetime.today() |
| 45 |
|
| 46 |
return {'year': date.year, 'month': date.month, 'day': date.day} |
| 47 |
|
| 48 |
|
| 49 |
class YearlyModel(EventModel): |
| 50 |
LABEL = 'Yearly Events' |
| 51 |
TYPE = 'yearly' |
| 52 |
COLUMN_NAMES = ["Event Name", "Event Date"] |
| 53 |
|
| 54 |
def fillNewEvent(self, event): |
| 55 |
super().fillNewEvent(event) |
| 56 |
|
| 57 |
writeXMLValue(self.document, event, 'month', 1) |
| 58 |
writeXMLValue(self.document, event, 'day', 15) |
| 59 |
|
| 60 |
def getDataInternal(self, column, row): |
| 61 |
parentData = super().getDataInternal(column, row) |
| 62 |
if parentData: |
| 63 |
return parentData |
| 64 |
if column == 1: |
| 65 |
event = self.events[row] |
| 66 |
year = readXMLValue(event, 'year') |
| 67 |
month = readXMLValue(event, 'month') |
| 68 |
day = readXMLValue(event, 'day') |
| 69 |
return formatDate(year, month, day) |
| 70 |
|
| 71 |
return None |
| 72 |
|
| 73 |
def setDataInternal(self, column, row, value): |
| 74 |
if column == 1: |
| 75 |
event = self.events[row] |
| 76 |
date = parseDate(value) |
| 77 |
writeXMLValue(self.document, event, 'year', date['year']) |
| 78 |
writeXMLValue(self.document, event, 'month', date['month']) |
| 79 |
writeXMLValue(self.document, event, 'day', date['day']) |
| 80 |
else: |
| 81 |
super().setDataInternal(column, row, value) |