def create_basename(input_string, blog): ''' Generate a basename from a given input string. Checks across the entire blog in question for a basename collision. Basenames need to be unique to the filesystem for where the target files are to be written. By default this is enforced in the database by way of a unique column constraint. ''' if not input_string: input_string = "page" basename = input_string basename_test = create_basename_core(basename) from core.models import Page n = 0 while True: try: Page.get(Page.basename == basename_test, Page.blog == blog) except Page.DoesNotExist: return (basename_test[:MAX_BASENAME_LENGTH]) n += 1 basename_test = basename + "-" + str(n)
def api_hi(): from core.models import PageRevision, Page pages = [] for n in PageRevision.select(): try: Page.get(Page.id == n.page) except: pages.append(n.page) n.delete() return "Deleted: {}".format(pages)
def create_basename(input_string, blog): ''' Generate a basename from a given input string. Checks across the entire blog in question for a basename collision. Basenames need to be unique to the filesystem for where the target files are to be written. By default this is enforced in the database by way of a unique column constraint. ''' from core.models import Page if not input_string: input_string = "page" basename = input_string.replace(' ', '-') try: basename = basename.casefold() except BaseException: basename = basename.lower() basename = re.sub(r'[^a-z0-9\-]', r'', basename) basename = re.sub(r'\-\-', r'-', basename) basename = urllib.parse.quote_plus(basename) basename_test = basename n = 0 while True: try: Page.get(Page.basename == basename_test, Page.blog == blog) except Page.DoesNotExist: return (basename_test[:MAX_BASENAME_LENGTH]) n += 1 basename_test = basename + "-" + str(n)