def load_offices(apps, schema_editor): from catalog.models import Office root = Office.add_root(name='Україна', order_id=0) get = lambda node: Office.objects.get(pk=node.pk) with open("catalog/migrations/offices.csv", "r") as fp: r = csv.reader(fp) prev_filled_row = -1 levels = {} for i, l, in enumerate(r): if not any(l): continue filled_row = None for j, r in enumerate(l): if r: prev_filled_row = filled_row filled_row = j break if prev_filled_row is not None and filled_row is not None: if filled_row > prev_filled_row: if filled_row != prev_filled_row + 1: print(l) if filled_row == 0: levels[filled_row] = get(root).add_child(name=l[filled_row], order_id=i + 1) else: levels[filled_row] = get(levels[filled_row - 1]).add_child( name=l[filled_row], order_id=i + 1)
def load_offices(apps, schema_editor): from catalog.models import Office root = Office.add_root(name='Україна', order_id=0) get = lambda node: Office.objects.get(pk=node.pk) with open("catalog/migrations/offices.csv", "r") as fp: r = csv.reader(fp) prev_filled_row = -1 levels = {} for i, l, in enumerate(r): if not any(l): continue filled_row = None for j, r in enumerate(l): if r: prev_filled_row = filled_row filled_row = j break if prev_filled_row is not None and filled_row is not None: if filled_row > prev_filled_row: if filled_row != prev_filled_row + 1: print(l) if filled_row == 0: levels[filled_row] = get(root).add_child( name=l[filled_row].strip(), order_id=i + 1) else: levels[filled_row] = get(levels[filled_row - 1]).add_child( name=l[filled_row].strip(), order_id=i + 1)
def offices_home(request): return render(request, "offices.jinja", {"offices": Office.dump_bulk()})