@ -25,11 +25,26 @@ def import_calendar(calendar):
events = { }
events = { }
for event in cal . walk ( " vevent " ) :
for event in cal . walk ( " vevent " ) :
uid = event . decoded ( " uid " ) . decode ( )
uid = event . decoded ( " uid " ) . decode ( )
room = (
summary = event . decoded ( " summary " ) . decode ( )
event . decoded ( " location " , None ) or event . decoded ( " summary " )
) . decode ( )
start = event . decoded ( " dtstart " ) . astimezone ( timezone . utc )
start = event . decoded ( " dtstart " ) . astimezone ( timezone . utc )
end = event . decoded ( " dtend " ) . astimezone ( timezone . utc )
end = event . decoded ( " dtend " ) . astimezone ( timezone . utc )
location = event . decoded ( " location " , None )
if location is not None :
location = location . decode ( )
if location :
room = location
try :
required_helpers = int ( summary )
except ValueError :
required_helpers = 0
else :
try :
room , required_helpers = tuple ( summary . split ( ) )
required_helpers = int ( required_helpers )
except ValueError :
room = summary
required_helpers = 0
if not uid or not room :
if not uid or not room :
return False
return False
@ -40,6 +55,7 @@ def import_calendar(calendar):
{
{
" start_at " : start ,
" start_at " : start ,
" duration " : end - start ,
" duration " : end - start ,
" required_helpers " : required_helpers ,
" uuid " : uid ,
" uuid " : uid ,
" calendar " : calendar ,
" calendar " : calendar ,
} ,
} ,
@ -52,7 +68,7 @@ def import_calendar(calendar):
if r == None :
if r == None :
rooms [ room ] = Room (
rooms [ room ] = Room (
name = room , required_helpers = 0
name = room , required_helpers = 0
) # required_helpers=0 ensures a shift in a new room is not displayed un ti l the correct number of required helpers is set
) # required_helpers=0 ensures a shift in a new room is not displayed un less the correct number of required helpers is set or the shift itself specifies i t
rooms [ room ] . save ( )
rooms [ room ] . save ( )
for e in Event . objects . filter ( calendar = calendar , uuid__in = events ) :
for e in Event . objects . filter ( calendar = calendar , uuid__in = events ) :
@ -62,6 +78,7 @@ def import_calendar(calendar):
e . room = rooms [ room ]
e . room = rooms [ room ]
e . start_at = event [ " start_at " ]
e . start_at = event [ " start_at " ]
e . duration = event [ " duration " ]
e . duration = event [ " duration " ]
e . required_helpers = event [ " required_helpers " ]
e . save ( )
e . save ( )
events [ uuid ] = ( room , e )
events [ uuid ] = ( room , e )