human
Complete this python program:
def _refresh_course_tabs(request, course_module):
assistant
#Here is the Python code you requested.

    """Automatically adds/removes tabs if changes to the course require them.
    Raises:
    InvalidTabsException: raised if there\s a problem with the new version of the tabs.
    """
    def update_tab(tabs, tab_type, tab_enabled):
        '\n                                Adds    or    removes    a    course    tab    based    upon    whether    it    is    enabled.\n                                '
        tab_panel = {'type': tab_type.type}
        has_tab = (tab_panel in tabs)
        if (tab_enabled and (not has_tab)):
            tabs.append(CourseTab.from_json(tab_panel))
        elif ((not tab_enabled) and has_tab):
            tabs.remove(tab_panel)
    course_tabs = copy.copy(course_module.tabs)
    for tab_type in CourseTabPluginManager.get_tab_types():
        if ((not tab_type.is_dynamic) and tab_type.is_default):
            tab_enabled = tab_type.is_enabled(course_module, user=request.user)
            update_tab(course_tabs, tab_type, tab_enabled)
    CourseTabList.validate_tabs(course_tabs)
    if (course_tabs != course_module.tabs):
        course_module.tabs = course_tabs