'Updates the state of the given course for this Action with the given data.
If allow_not_found is True, automatically creates an entry if it doesn\'t exist.
Raises CourseActionStateException if allow_not_found is False and an entry for the given course
for this Action doesn\'t exist.'

@transaction.atomic
def update_state(self, course_key, new_state, should_display=True, message='', user=None, allow_not_found=False, **kwargs):

    (state_object, created) = self.get_or_create(course_key=course_key, action=self.ACTION)
    if created:
        if allow_not_found:
            state_object.created_user = user
        else:
            raise CourseActionStateItemNotFoundError('Cannot    update    non-existent    entry    for    course_key    {course_key}    and    action    {action}'.format(action=self.ACTION, course_key=course_key))
    if user:
        state_object.updated_user = user
    state_object.state = new_state
    state_object.should_display = should_display
    state_object.message = message
    if kwargs:
        for (key, value) in kwargs.iteritems():
            setattr(state_object, key, value)
    state_object.save()
    return state_object
