Skip to content
Snippets Groups Projects
Commit 2de28227 authored by Remco Tukker's avatar Remco Tukker
Browse files

easy way to exclude some data when not previewing

parent f8eb1c09
No related branches found
No related tags found
1 merge request!71Create a preview mode for publishing survey data
......@@ -2,9 +2,7 @@ import logging
from typing import Any
from flask import Blueprint, jsonify
from sqlalchemy import select
from compendium_v2.db import db
from compendium_v2.db.model import BudgetEntry
from compendium_v2.routes import common
......@@ -57,7 +55,7 @@ def budget_view() -> Any:
}
entries = sorted(
[_extract_data(entry) for entry in db.session.scalars(select(BudgetEntry))],
[_extract_data(entry) for entry in common.get_data(BudgetEntry)],
key=lambda d: (d['year'], d['nren'])
)
return jsonify(entries)
......@@ -2,9 +2,7 @@ import logging
from typing import Any
from flask import Blueprint, jsonify
from sqlalchemy import select
from compendium_v2.db import db
from compendium_v2.db.model import ChargingStructure
from compendium_v2.routes import common
......@@ -57,7 +55,7 @@ def charging_structure_view() -> Any:
}
entries = sorted(
[_extract_data(entry) for entry in db.session.scalars(select(ChargingStructure))],
[_extract_data(entry) for entry in common.get_data(ChargingStructure)],
key=lambda d: (d['nren'], d['year'])
)
return jsonify(entries)
......@@ -3,8 +3,11 @@ Utilities used by multiple route blueprints.
"""
import functools
import logging
from compendium_v2 import db
from compendium_v2.db.model import NREN
from flask import Response, request
from sqlalchemy import select
logger = logging.getLogger(__name__)
......@@ -56,3 +59,11 @@ def after_request(response):
data,
str(response.status_code)))
return response
def get_data(table_class):
select_statement = select(table_class).join(NREN).order_by(NREN.name.asc(), table_class.year.desc())
preview = request.args.get('preview') is not None
if not preview:
select_statement = select_statement.where(table_class.year.not_in([2022]))
return db.session.scalars(select_statement)
......@@ -2,9 +2,7 @@ import logging
from typing import Any
from flask import Blueprint, jsonify
from sqlalchemy import select
from compendium_v2.db import db
from compendium_v2.db.model import ECProject
from compendium_v2.routes import common
......@@ -58,7 +56,7 @@ def ec_projects_view() -> Any:
}
result = sorted(
[_extract_project(project) for project in db.session.scalars(select(ECProject))],
[_extract_project(project) for project in common.get_data(ECProject)],
key=lambda d: (d['nren'], d['year'], d['project'])
)
return jsonify(result)
import logging
from flask import Blueprint, jsonify
from sqlalchemy import select
from compendium_v2.routes import common
from compendium_v2.db import db
from compendium_v2.db.model import FundingSource
from typing import Any
......@@ -66,7 +64,7 @@ def funding_source_view() -> Any:
}
entries = sorted(
[_extract_data(entry) for entry in db.session.scalars(select(FundingSource))],
[_extract_data(entry) for entry in common.get_data(FundingSource)],
key=lambda d: (d['nren'], d['year'])
)
return jsonify(entries)
......@@ -2,9 +2,7 @@ import logging
from typing import Any
from flask import Blueprint, jsonify
from sqlalchemy import select
from compendium_v2.db import db
from compendium_v2.db.model import ParentOrganization, SubOrganization
from compendium_v2.routes import common
......@@ -75,7 +73,7 @@ def parent_organization_view() -> Any:
}
result = sorted(
[_extract_parent(org) for org in db.session.scalars(select(ParentOrganization))],
[_extract_parent(org) for org in common.get_data(ParentOrganization)],
key=lambda d: (d['nren'], d['year'], d['name'])
)
......@@ -107,7 +105,7 @@ def sub_organization_view() -> Any:
}
result = sorted(
[_extract_sub(org) for org in db.session.scalars(select(SubOrganization))],
[_extract_sub(org) for org in common.get_data(SubOrganization)],
key=lambda d: (d['nren'], d['year'], d['name'])
)
return jsonify(result)
......@@ -2,9 +2,7 @@ import logging
from typing import Any
from flask import Blueprint, jsonify
from sqlalchemy import select
from compendium_v2.db import db
from compendium_v2.db.model import Policy, NREN
from compendium_v2.db.model import Policy
from compendium_v2.routes import common
routes = Blueprint('policy', __name__)
......@@ -67,6 +65,5 @@ def policy_view() -> Any:
'data_protection': entry.data_protection,
}
entries = [_extract_data(entry) for entry in db.session.scalars(
select(Policy).join(NREN).order_by(NREN.name.asc(), Policy.year.desc()))]
entries = [_extract_data(entry) for entry in common.get_data(Policy)]
return jsonify(entries)
import logging
from flask import Blueprint, jsonify
from sqlalchemy import select
from compendium_v2.db import db
from compendium_v2.db.model import NREN, NrenStaff
from compendium_v2.db.model import NrenStaff
from compendium_v2.routes import common
from typing import Any
......@@ -63,6 +61,5 @@ def staff_view() -> Any:
'non_technical_fte': float(entry.non_technical_fte)
}
entries = [_extract_data(entry) for entry in db.session.scalars(
select(NrenStaff).join(NREN).order_by(NREN.name.asc(), NrenStaff.year.desc()))]
entries = [_extract_data(entry) for entry in get_data(NrenStaff)]
return jsonify(entries)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment