diff --git a/.github/workflows/automated-testing.yaml b/.github/workflows/automated-testing.yaml index 27458181c..d80deb6c8 100644 --- a/.github/workflows/automated-testing.yaml +++ b/.github/workflows/automated-testing.yaml @@ -79,9 +79,16 @@ jobs: uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} + - name: Cache pip + uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- - name: Install python dependencies run: | - python -m pip install --upgrade pip + python -m pip install --upgrade pip 'setuptools<72.0.0' wheel pip install -r requirements.txt pip install tox - name: Add schemas for testing diff --git a/modelview/views.py b/modelview/views.py index de53e9248..96a3c6cbf 100644 --- a/modelview/views.py +++ b/modelview/views.py @@ -34,14 +34,19 @@ def getClasses(sheettype): """ Returns the model and form class w.r.t sheettype. """ + allowed_sheet_types = ["model", "framework"] c = None f = None - if sheettype == "model": - c = Energymodel - f = EnergymodelForm - elif sheettype == "framework": - c = Energyframework - f = EnergyframeworkForm + + if isinstance(sheettype, str): + if sheettype in allowed_sheet_types: + if sheettype == "model": + c = Energymodel + f = EnergymodelForm + elif sheettype == "framework": + c = Energyframework + f = EnergyframeworkForm + return c, f @@ -187,6 +192,12 @@ def model_to_csv(request, sheettype): match = re.match(r"^select_(?P\d+)$", label) tags.append(int(match.group("tid"))) c, f = getClasses(sheettype) + + if not c: + raise Http404( + "We dropped the scenario factsheets in favor of scenario bundles." + ) + header = list( field.attname for field in c._meta.get_fields() @@ -203,6 +214,7 @@ def model_to_csv(request, sheettype): for model in c.objects.all().order_by("id"): if all(tid in model.tags for tid in tags): writer.writerow([printable(model, col) for col in header]) + return response