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

add basic templating to survey to reduce nr of required changes in the survey

parent 318f852b
Branches
Tags
1 merge request!52Feature/admin workflow surveys page
...@@ -60,6 +60,8 @@ def list_surveys() -> Any: ...@@ -60,6 +60,8 @@ def list_surveys() -> Any:
for entry in surveys for entry in surveys
] ]
# TODO i suppose we should also add response entries for the nrens that didnt start the survey, with a not started status
# TODO fix the ordering of the responses by nren name, i couldnt convince SA yet.. # TODO fix the ordering of the responses by nren name, i couldnt convince SA yet..
return jsonify(entries) return jsonify(entries)
...@@ -82,8 +84,27 @@ def open_survey(nren_name) -> Any: ...@@ -82,8 +84,27 @@ def open_survey(nren_name) -> Any:
with p.open('r') as f: with p.open('r') as f:
survey = json.load(f) survey = json.load(f)
# TODO add some magic strings in the json (like the year, url validation regex, maybe countries list) replacements = {
# and interpolate them here "[%websiteurlregex%]": r"^(https?:\/\/)?([\da-zA-Z\.-]+\.[a-zA-Z\.]{2,6}|[\d\.]+)([\/:?=&#%]{1}[\d_a-zA-Z\.-]+)*[\/\?]?$",
"[%lastyear%]": str(last_year),
"[%surveyyear%]": str(year)
}
def replacer(string):
for key, replacement in replacements.items():
string = string.replace(key, replacement)
return string
def visitor(object, items):
for key, value in items:
if type(value) == dict:
visitor(value, value.items())
elif type(value) == list:
visitor(value, enumerate(value))
elif type(value) == str:
object[key] = replacer(value)
visitor(survey, survey.items())
data: Optional[dict] = None data: Optional[dict] = None
page = 0 page = 0
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
{ {
"type": "text", "type": "text",
"name": "budget", "name": "budget",
"title": "What is your NRENs budget for 2022 or 2022/2023 in million euro?", "title": "What is your NRENs budget for [%lastyear%] or [%lastyear%]/[%surveyyear%] in million euro?",
"description": "If your budget is not per calendar year, please provide figures for the budget that covers the largest part of 2022 including GEANT subsidy.", "description": "If your budget is not per calendar year, please provide figures for the budget that covers the largest part of [%lastyear%] including GEANT subsidy.",
"validators": [ "validators": [
{ {
"type": "numeric", "type": "numeric",
...@@ -25,13 +25,13 @@ ...@@ -25,13 +25,13 @@
{ {
"type": "multipletext", "type": "multipletext",
"name": "income_sources", "name": "income_sources",
"title": "Estimate (in % of income) the sources of your NREN-related income for 2022 or 2022/2023.", "title": "Estimate (in % of income) the sources of your NREN-related income for [%lastyear%] or [%lastyear%]/[%surveyyear%].",
"description": "European Funding should include GÉANT funding.", "description": "European Funding should include GÉANT funding.",
"validators": [ "validators": [
{ {
"type": "expression", "type": "expression",
"text": "The percentages should add up to 100", "text": "The percentages should add up to 100",
"expression": "({income_sources.client_institutions} + {income_sources.gov_public_bodies} + {income_sources.european_funding} + {income_sources.commercial} + {income_sources.other} = 100) or ({income_sources} empty)" "expression": "(sum({income_sources.client_institutions}, {income_sources.gov_public_bodies}, {income_sources.european_funding}, {income_sources.commercial}, {income_sources.other}) = 100) or ({income_sources} empty)"
} }
], ],
"items": [ "items": [
...@@ -344,7 +344,7 @@ ...@@ -344,7 +344,7 @@
{ {
"type": "regex", "type": "regex",
"text": "Please provide a single valid url", "text": "Please provide a single valid url",
"regex": "^(https?:\\/\\/)?([\\da-zA-Z\\.-]+\\.[a-zA-Z\\.]{2,6}|[\\d\\.]+)([\\/:?=&#%]{1}[\\d_a-zA-Z\\.-]+)*[\\/\\?]?$" "regex": "[%websiteurlregex%]"
} }
] ]
} }
...@@ -385,7 +385,7 @@ ...@@ -385,7 +385,7 @@
{ {
"type": "regex", "type": "regex",
"text": "Please provide a single valid url", "text": "Please provide a single valid url",
"regex": "^(https?:\\/\\/)?([\\da-zA-Z\\.-]+\\.[a-zA-Z\\.]{2,6}|[\\d\\.]+)([\\/:?=&#%]{1}[\\d_a-zA-Z\\.-]+)*[\\/\\?]?$" "regex": "[%websiteurlregex%]"
} }
] ]
}, },
...@@ -416,7 +416,7 @@ ...@@ -416,7 +416,7 @@
{ {
"type": "regex", "type": "regex",
"text": "Please provide a single valid url", "text": "Please provide a single valid url",
"regex": "^(https?:\\/\\/)?([\\da-zA-Z\\.-]+\\.[a-zA-Z\\.]{2,6}|[\\d\\.]+)([\\/:?=&#%]{1}[\\d_a-zA-Z\\.-]+)*[\\/\\?]?$" "regex": "[%websiteurlregex%]"
} }
] ]
} }
...@@ -469,7 +469,7 @@ ...@@ -469,7 +469,7 @@
"name": "central_procurement_amount", "name": "central_procurement_amount",
"visibleIf": "{central_software_procurement} = 'yes'", "visibleIf": "{central_software_procurement} = 'yes'",
"indent": 1, "indent": 1,
"title": "What is the total amount (in Euro) that you procured in 2022 or 2022/2023 on behalf of your customers?", "title": "What is the total amount (in Euro) that you procured in [%lastyear%] or [%lastyear%]/[%surveyyear%] on behalf of your customers?",
"validators": [ "validators": [
{ {
"type": "numeric", "type": "numeric",
...@@ -791,7 +791,7 @@ ...@@ -791,7 +791,7 @@
{ {
"type": "regex", "type": "regex",
"text": "Please provide a single valid url", "text": "Please provide a single valid url",
"regex": "^(https?:\\/\\/)?([\\da-zA-Z\\.-]+\\.[a-zA-Z\\.]{2,6}|[\\d\\.]+)([\\/:?=&#%]{1}[\\d_a-zA-Z\\.-]+)*[\\/\\?]?$" "regex": "[%websiteurlregex%]"
} }
] ]
} }
...@@ -1565,7 +1565,7 @@ ...@@ -1565,7 +1565,7 @@
{ {
"type": "regex", "type": "regex",
"text": "Please provide a single valid url", "text": "Please provide a single valid url",
"regex": "^(https?:\\/\\/)?([\\da-zA-Z\\.-]+\\.[a-zA-Z\\.]{2,6}|[\\d\\.]+)([\\/:?=&#%]{1}[\\d_a-zA-Z\\.-]+)*[\\/\\?]?$" "regex": "[%websiteurlregex%]"
} }
] ]
} }
...@@ -1667,7 +1667,7 @@ ...@@ -1667,7 +1667,7 @@
{ {
"type": "regex", "type": "regex",
"text": "Please provide a single valid url", "text": "Please provide a single valid url",
"regex": "^(https?:\\/\\/)?([\\da-zA-Z\\.-]+\\.[a-zA-Z\\.]{2,6}|[\\d\\.]+)([\\/:?=&#%]{1}[\\d_a-zA-Z\\.-]+)*[\\/\\?]?$" "regex": "[%websiteurlregex%]"
} }
] ]
} }
...@@ -1727,7 +1727,7 @@ ...@@ -1727,7 +1727,7 @@
{ {
"type": "regex", "type": "regex",
"text": "Please provide a single valid url", "text": "Please provide a single valid url",
"regex": "^(https?:\\/\\/)?([\\da-zA-Z\\.-]+\\.[a-zA-Z\\.]{2,6}|[\\d\\.]+)([\\/:?=&#%]{1}[\\d_a-zA-Z\\.-]+)*[\\/\\?]?$" "regex": "[%websiteurlregex%]"
} }
] ]
}, },
...@@ -1905,7 +1905,7 @@ ...@@ -1905,7 +1905,7 @@
{ {
"type": "multipletext", "type": "multipletext",
"name": "traffic_estimate", "name": "traffic_estimate",
"title": "Please supply an estimate of the total amount of traffic in Terabyte from January to December (2022) for the following: ", "title": "Please supply an estimate of the total amount of traffic in Terabyte from January to December ([%lastyear%]) for the following: ",
"items": [ "items": [
{ {
"name": "from_customers", "name": "from_customers",
...@@ -1957,7 +1957,7 @@ ...@@ -1957,7 +1957,7 @@
{ {
"type": "expression", "type": "expression",
"text": "The percentages should add up to 100", "text": "The percentages should add up to 100",
"expression": "({commodity_vs_r_e.r_e} + {commodity_vs_r_e.commodity} = 100) or ({commodity_vs_r_e} empty)" "expression": "(sum({commodity_vs_r_e.r_e}, {commodity_vs_r_e.commodity}) = 100) or ({commodity_vs_r_e} empty)"
} }
], ],
"items": [ "items": [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment