Events on calendar

main2
Bob Mottram 2019-10-11 11:28:28 +01:00
parent 940a49fd58
commit 3153e6c53c
2 changed files with 49 additions and 12 deletions

View File

@ -92,8 +92,8 @@ tr:nth-child(even) > .calendar__day__cell:nth-child(even) {
}
.calendar__day__cell[data-event] {
background-color: blue;
color: blue;
background-color: var(--lines-color);
color: var(--main-bg-color);
}
.calendar__day__cell[data-today] {
@ -102,3 +102,11 @@ tr:nth-child(even) > .calendar__day__cell:nth-child(even) {
color: var(--today-circle);
text-align: center;
}
.calendar__day__cell[data-today-event] {
border-radius: 50%;
background-color: var(--lines-color);
border: 4px solid var(--main-bg-color);
color: var(--main-bg-color);
text-align: center;
}

View File

@ -2751,12 +2751,12 @@ def weekDayOfMonthStart(monthNumber: int,year: int) -> int:
firstDayOfMonth=datetime(year, monthNumber, 1, 0, 0)
return int(firstDayOfMonth.strftime("%w"))+1
def getCalendarEvents(baseDir: str,nickname: str,domain: str,year: int,monthNumber: int) -> []:
def getCalendarEvents(baseDir: str,nickname: str,domain: str,year: int,monthNumber: int) -> {}:
"""Retrieves calendar events
Returns a list of lists containing Event and Place activities
Returns a dictionary indexed by day number of lists containing Event and Place activities
"""
calendarFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/calendar/'+str(year)+'/'+str(monthNumber)+'.txt'
events=[]
events={}
if not os.path.isfile(calendarFilename):
return events
calendarPostIds=[]
@ -2776,14 +2776,28 @@ def getCalendarEvents(baseDir: str,nickname: str,domain: str,year: int,monthNumb
if isinstance(postJsonObject['object'], dict):
if postJsonObject['object'].get('tag'):
postEvent=[]
dayOfMonth=None
for tag in postJsonObject['object']['tag']:
if tag.get('type'):
if tag['type']=='Event' or tag['type']=='Place':
postEvent.append(tag)
if postEvent:
if tag['type']=='Event':
# tag is an event
if tag.get('startTime'):
eventTime= \
datetime.strptime(tag['startTime'], \
"%Y-%m-%dT%H:%M:%SZ")
if int(eventTime.strftime("%Y"))==year and \
int(eventTime.strftime("%m"))==monthNumber:
dayOfMonth=str(int(eventTime.strftime("%d")))
postEvent.append(tag)
else:
# tag is a place
postEvent.append(tag)
if postEvent and dayOfMonth:
calendarPostIds.append(postId)
# TODO this should be in a calendar-like format
events.append(postEvent)
if not events.get(dayOfMonth):
events[dayOfMonth]=[]
events[dayOfMonth].append(postEvent)
else:
recreateEventsFile=True
@ -2881,10 +2895,25 @@ def htmlCalendar(translate: {}, \
if currDate.month==monthNumber:
if dayOfMonth==currDate.day:
isToday=True
if not isToday:
calendarStr+=' <td class="calendar__day__cell">'+str(dayOfMonth)+'</td>\n'
if dayOfMonth==5:
events['5']=[{"test": 1},{"test2": 2},{"test3": 3},{"test4": 4}]
if events.get(str(dayOfMonth)):
eventDots=''
for i in range(1,len(events[str(dayOfMonth)])):
eventDots+='.'
if eventDots=='...':
break
# there are events for this day
if not isToday:
calendarStr+=' <td class="calendar__day__cell" data-event="'+eventDots+'">'+str(dayOfMonth)+'</td>\n'
else:
calendarStr+=' <td class="calendar__day__cell" data-today-event="'+eventDots+'">'+str(dayOfMonth)+'</td>\n'
else:
calendarStr+=' <td class="calendar__day__cell" data-today="">'+str(dayOfMonth)+'</td>\n'
# No events today
if not isToday:
calendarStr+=' <td class="calendar__day__cell">'+str(dayOfMonth)+'</td>\n'
else:
calendarStr+=' <td class="calendar__day__cell" data-today="">'+str(dayOfMonth)+'</td>\n'
else:
calendarStr+=' <td class="calendar__day__cell"></td>\n'
calendarStr+=' </tr>\n'