def get_available_slug(title, new_slug=None):
 slug = (new_slug or title.slug)
 title.slug = slug
 title.update_path()
 path = title.path
 if (not is_valid_page_slug(title.page, title.page.parent, title.language, slug, title.page.site, path)):
  match = COPY_SLUG_REGEX.match(slug)
  if match:
   try:
    next_id = (int(match.groups()[0]) + 1)
    slug = ('-'.join(slug.split('-')[:(-1)]) + ('-%d' % next_id))
   except TypeError:
    slug += '-2'
  else:
   slug += APPEND_TO_SLUG
  return get_available_slug(title, slug)
 else:
  return slug

def get_available_slug ( title , new_slug = None ) : slug = ( new_slug or title . slug ) title . slug = slug title . update_path ( ) path = title . path if ( not is_valid_page_slug ( title . page , title . page . parent , title . language , slug , title . page . site , path ) ) : match = COPY_SLUG_REGEX . match ( slug ) if match : try : next_id = ( int ( match . groups ( ) [ 0 ] ) + 1 ) slug = ( '-' . join ( slug . split ( '-' ) [ : ( - 1 ) ] ) + ( '-%d' % next_id ) ) except TypeError : slug += '-2' else : slug += APPEND_TO_SLUG return get_available_slug ( title , slug ) else : return slug
smart function generates slug for title if current title slug cannot be used .