def update_course_updates(location, update, passed_id=None, user=None):
 try:
  course_updates = modulestore().get_item(location)
 except ItemNotFoundError:
  course_updates = modulestore().create_item(user.id, location.course_key, location.block_type, location.block_id)
 course_update_items = list(reversed(get_course_update_items(course_updates)))
 if (passed_id is not None):
  passed_index = _get_index(passed_id)
  if (0 < passed_index <= len(course_update_items)):
   course_update_dict = course_update_items[(passed_index - 1)]
   course_update_dict['date'] = update['date']
   course_update_dict['content'] = update['content']
   course_update_items[(passed_index - 1)] = course_update_dict
  else:
   return HttpResponseBadRequest(_('Invalid course update id.'))
 else:
  course_update_dict = {'id': (len(course_update_items) + 1), 'date': update['date'], 'content': update['content'], 'status': CourseInfoModule.STATUS_VISIBLE}
  course_update_items.append(course_update_dict)
  enqueue_push_course_update(update, location.course_key)
 save_course_update_items(location, course_updates, course_update_items, user)
 if ('status' in course_update_dict):
  del course_update_dict['status']
 return course_update_dict

def update_course_updates ( location , update , passed_id = None , user = None ) : try : course_updates = modulestore ( ) . get_item ( location ) except ItemNotFoundError : course_updates = modulestore ( ) . create_item ( user . id , location . course_key , location . block_type , location . block_id ) course_update_items = list ( reversed ( get_course_update_items ( course_updates ) ) ) if ( passed_id is not None ) : passed_index = _get_index ( passed_id ) if ( 0 < passed_index <= len ( course_update_items ) ) : course_update_dict = course_update_items [ ( passed_index - 1 ) ] course_update_dict [ 'date' ] = update [ 'date' ] course_update_dict [ 'content' ] = update [ 'content' ] course_update_items [ ( passed_index - 1 ) ] = course_update_dict else : return HttpResponseBadRequest ( _ ( 'Invalid course update id.' ) ) else : course_update_dict = { 'id' : ( len ( course_update_items ) + 1 ) , 'date' : update [ 'date' ] , 'content' : update [ 'content' ] , 'status' : CourseInfoModule . STATUS_VISIBLE } course_update_items . append ( course_update_dict ) enqueue_push_course_update ( update , location . course_key ) save_course_update_items ( location , course_updates , course_update_items , user ) if ( 'status' in course_update_dict ) : del course_update_dict [ 'status' ] return course_update_dict
either add or update the given course update .