Basic error handling in icalendar event upload
This commit is contained in:
		
							parent
							
								
									079847ae4e
								
							
						
					
					
						commit
						06c5c485f7
					
				
					 1 changed files with 15 additions and 4 deletions
				
			
		| 
						 | 
					@ -1,3 +1,4 @@
 | 
				
			||||||
 | 
					import logging
 | 
				
			||||||
from typing import List, Tuple, Optional
 | 
					from typing import List, Tuple, Optional
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import caldav
 | 
					import caldav
 | 
				
			||||||
| 
						 | 
					@ -74,8 +75,10 @@ class CalDAVCalendar(models.Model):
 | 
				
			||||||
        :return Amount of events added, updated, and deleted
 | 
					        :return Amount of events added, updated, and deleted
 | 
				
			||||||
        :rtype Tuple[int, int, int]
 | 
					        :rtype Tuple[int, int, int]
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
 | 
					        logger = logging.getLogger("davinci.icalendar.ICalSync.upload_events")
 | 
				
			||||||
        calendar = self.get_calendar()
 | 
					        calendar = self.get_calendar()
 | 
				
			||||||
        if calendar is None:
 | 
					        if calendar is None:
 | 
				
			||||||
 | 
					            logger.error(f"No calendar found on url '{self.calendar_url}'")
 | 
				
			||||||
            raise ValueError(f"No calendar found on url '{self.calendar_url}'")
 | 
					            raise ValueError(f"No calendar found on url '{self.calendar_url}'")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Keep track of which events were already in the calendar
 | 
					        # Keep track of which events were already in the calendar
 | 
				
			||||||
| 
						 | 
					@ -97,16 +100,24 @@ class CalDAVCalendar(models.Model):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if event.uid in purge_uids:
 | 
					            if event.uid in purge_uids:
 | 
				
			||||||
                # Need to overwrite
 | 
					                # Need to overwrite
 | 
				
			||||||
 | 
					                try:
 | 
				
			||||||
                    cevent = calendar.event_by_uid(event.uid)
 | 
					                    cevent = calendar.event_by_uid(event.uid)
 | 
				
			||||||
                    cevent.data = vcal.fix(ev)
 | 
					                    cevent.data = vcal.fix(ev)
 | 
				
			||||||
                    cevent.save()
 | 
					                    cevent.save()
 | 
				
			||||||
 | 
					                except Exception as e:
 | 
				
			||||||
 | 
					                    logger.error(f"Error during saving of event {event.uid}: {e}")
 | 
				
			||||||
 | 
					                    logger.error(f"======EVENT======\n{ev}\n=================")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                purge_uids.remove(event.uid)
 | 
					                purge_uids.remove(event.uid)
 | 
				
			||||||
                updated += 1
 | 
					                updated += 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
 | 
					                try:
 | 
				
			||||||
                    calendar.save_event(ev)
 | 
					                    calendar.save_event(ev)
 | 
				
			||||||
 | 
					                except Exception as e:
 | 
				
			||||||
 | 
					                    logger.error(f"Error during saving of event {event.uid}: {e}")
 | 
				
			||||||
 | 
					                    logger.error(f"======EVENT======\n{ev}\n=================")
 | 
				
			||||||
                added += 1
 | 
					                added += 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Purge old events
 | 
					        # Purge old events
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue