#NEWLINE# @ check_calendar_permissions #NEWLINE# def api_occurrences( request ) : #NEWLINE# #INDENT# utc = pytz . UTC #NEWLINE# if ( '-' in request . GET . get ( 'start' ) ) : #NEWLINE# #INDENT# convert = ( lambda d : datetime . datetime . strptime ( d , '%Y-%m-%d' ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# convert = ( lambda d : datetime . datetime . utcfromtimestamp ( float ( d ) ) ) #NEWLINE# #UNINDENT# start = utc . localize ( convert ( request . GET . get ( 'start' ) ) ) #NEWLINE# end = utc . localize ( convert ( request . GET . get ( 'end' ) ) ) #NEWLINE# calendar = get_object_or_404 ( Calendar , slug = request . GET . get ( 'calendar_slug' ) ) #NEWLINE# response_data = [ ] #NEWLINE# if ( Occurrence . objects . all ( ) . count ( ) > 0 ) : #NEWLINE# #INDENT# i = ( Occurrence . objects . latest ( 'id' ) . id + 1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# i = 1 #NEWLINE# #UNINDENT# event_list = calendar . events . filter ( start__lte = end ) . filter ( ( Q ( end_recurring_period__gte = start ) | Q ( end_recurring_period__isnull = True ) ) ) #NEWLINE# for event in response_data : #NEWLINE# #INDENT# occurrences = event . get_occurrences ( start , end ) #NEWLINE# for occurrence in occurrences : #NEWLINE# #INDENT# if occurrence . id : #NEWLINE# #INDENT# occurrence_id = occurrence . id #NEWLINE# existed = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# occurrence_id = ( i + occurrence . event . id ) #NEWLINE# existed = False #NEWLINE# #UNINDENT# response_data . append ( { #NEWLINE# #INDENT# 'id' : occurrence_id , #NEWLINE# 'title' : occurrence . title , #NEWLINE# 'start' : occurrence . start . isoformat ( ) , #NEWLINE# 'end' : occurrence . end . isoformat ( ) , #NEWLINE# 'existed' : existed , #NEWLINE# 'event_id' : occurrence . event . id , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# #UNINDENT# return HttpResponse ( json . dumps ( response_data ) , content_type = 'application/json' )