def article_course_wiki_root_slug(article):
 try:
  urlpath = article.urlpath_set.get()
 except ObjectDoesNotExist:
  return None
 ancestors = urlpath.cached_ancestors
 course_wiki_root_urlpath = None
 if (len(ancestors) == 0):
  course_wiki_root_urlpath = None
 elif (len(ancestors) == 1):
  course_wiki_root_urlpath = urlpath
 else:
  course_wiki_root_urlpath = ancestors[1]
 if (course_wiki_root_urlpath is not None):
  return course_wiki_root_urlpath.slug
 return None

def article_course_wiki_root_slug ( article ) : try : urlpath = article . urlpath_set . get ( ) except ObjectDoesNotExist : return None ancestors = urlpath . cached_ancestors course_wiki_root_urlpath = None if ( len ( ancestors ) == 0 ) : course_wiki_root_urlpath = None elif ( len ( ancestors ) == 1 ) : course_wiki_root_urlpath = urlpath else : course_wiki_root_urlpath = ancestors [ 1 ] if ( course_wiki_root_urlpath is not None ) : return course_wiki_root_urlpath . slug return None
we assume the second level ancestor is the course wiki root .