@@ -151,7 +151,7 @@ def fromVEvents(cls, events_list, ref=None, **kwargs):
151
151
@classmethod
152
152
def fromString (cls , event_str , ref = None , ** kwargs ):
153
153
calendar_collection = cal_from_ics (event_str )
154
- events = [item for item in calendar_collection .walk () if item .name == 'VEVENT' ]
154
+ events = [item for item in calendar_collection .walk () if item .name in [ 'VEVENT' , 'VTODO' ] ]
155
155
return cls .fromVEvents (events , ref , ** kwargs )
156
156
157
157
def __lt__ (self , other ):
@@ -277,7 +277,8 @@ def symbol_strings(self):
277
277
'range' : '\N{Left right arrow} ' ,
278
278
'range_end' : '\N{Rightwards arrow to bar} ' ,
279
279
'range_start' : '\N{Rightwards arrow from bar} ' ,
280
- 'right_arrow' : '\N{Rightwards arrow} '
280
+ 'right_arrow' : '\N{Rightwards arrow} ' ,
281
+ 'task' : '\N{Pencil} ' ,
281
282
}
282
283
else :
283
284
return {
@@ -286,7 +287,8 @@ def symbol_strings(self):
286
287
'range' : '<->' ,
287
288
'range_end' : '->|' ,
288
289
'range_start' : '|->' ,
289
- 'right_arrow' : '->'
290
+ 'right_arrow' : '->' ,
291
+ 'task' : '(T)' ,
290
292
}
291
293
292
294
@property
@@ -304,6 +306,24 @@ def start(self):
304
306
"""this should return the start date(time) as saved in the event"""
305
307
return self ._start
306
308
309
+ @property
310
+ def task (self ):
311
+ """this should return whether or not we are representing a task"""
312
+ return self ._vevents [self .ref ].name == 'VTODO'
313
+
314
+ @property
315
+ def task_status (self ):
316
+ """nice representation of a task status"""
317
+ vstatus = self ._vevents [self .ref ].get ('STATUS' , 'NEEDS-ACTION' )
318
+ status = ' '
319
+ if vstatus == 'COMPLETED' :
320
+ status = 'X'
321
+ elif vstatus == 'IN-PROGRESS' :
322
+ status = '/'
323
+ elif vstatus == 'CANCELLED' :
324
+ status = '-'
325
+ return status
326
+
307
327
@property
308
328
def end (self ):
309
329
"""this should return the end date(time) as saved in the event or
@@ -427,7 +447,10 @@ def summary(self):
427
447
name = name , number = number , suffix = suffix , desc = description , leap = leap ,
428
448
)
429
449
else :
430
- return self ._vevents [self .ref ].get ('SUMMARY' , '' )
450
+ summary = self ._vevents [self .ref ].get ('SUMMARY' , '' )
451
+ if self .task :
452
+ summary = '[{state}] {summary}' .format (state = self .task_status , summary = summary )
453
+ return summary
431
454
432
455
def update_summary (self , summary ):
433
456
self ._vevents [self .ref ]['SUMMARY' ] = summary
@@ -516,6 +539,14 @@ def _alarm_str(self):
516
539
alarmstr = ''
517
540
return alarmstr
518
541
542
+ @property
543
+ def _task_str (self ):
544
+ if self .task :
545
+ taskstr = ' ' + self .symbol_strings ['task' ]
546
+ else :
547
+ taskstr = ''
548
+ return taskstr
549
+
519
550
def format (self , format_string , relative_to , env = None , colors = True ):
520
551
"""
521
552
:param colors: determines if colors codes should be printed or not
@@ -642,6 +673,7 @@ def format(self, format_string, relative_to, env=None, colors=True):
642
673
attributes ["repeat-symbol" ] = self ._recur_str
643
674
attributes ["repeat-pattern" ] = self .recurpattern
644
675
attributes ["alarm-symbol" ] = self ._alarm_str
676
+ attributes ["task-symbol" ] = self ._task_str
645
677
attributes ["title" ] = self .summary
646
678
attributes ["organizer" ] = self .organizer .strip ()
647
679
attributes ["description" ] = self .description .strip ()
0 commit comments