From 5f234fc9a527425b8a26a39be7378d628f67c46c Mon Sep 17 00:00:00 2001 From: Taka Date: Thu, 25 Jul 2019 10:15:16 +0000 Subject: [PATCH] Tightened up how capability theater/nationality superscripts are parsed. --- vasl_templates/webapp/static/snippets.js | 46 ++++++++----------- .../webapp/tests/test_capabilities.py | 2 - 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/vasl_templates/webapp/static/snippets.js b/vasl_templates/webapp/static/snippets.js index bd3b5c2..2320d24 100644 --- a/vasl_templates/webapp/static/snippets.js +++ b/vasl_templates/webapp/static/snippets.js @@ -878,6 +878,11 @@ function make_capabilities( raw, vo_entry, vo_type, nat, elite, scenario_theater } // check if we should return the raw capability, or select the one for the scenario date if ( ! scenario_year ) { + // NOTE: We should really check for theater/nationality flags here (e.g. perhaps by calling + // _check_capability_timestamp()), but at this stage (just before the v1.0 release), + // it's not worth the risk. The superscripts will still appear in the UI/snippets, + // so we're not completely doing the wrong thing, and in practice, the scenario date + // will always be set. indeterminate_caps.push( key ) ; raw = true ; } @@ -1016,35 +1021,24 @@ function _check_capability_timestamp( capabilities, timestamp, nat, scenario_the var MONTH_NAMES = { F:2, J:6, A:8, S:9, N:11 } ; // check for a theater flag - if ( timestamp.substring( timestamp.length-1 ) === "E" ) { - if ( scenario_theater != "ETO" ) - return "" ; - timestamp = timestamp.substring( 0, timestamp.length-1 ) ; - } - if ( timestamp.substring( timestamp.length-1 ) === "P" ) { - if ( scenario_theater != "PTO" ) - return "" ; + THEATER_FLAGS = { E: "ETO", P: "PTO", B: "BURMA" } ; + var required_theater = THEATER_FLAGS[ timestamp.substring( timestamp.length-1 ) ] ; + if ( required_theater ) { timestamp = timestamp.substring( 0, timestamp.length-1 ) ; - } - if ( timestamp.substring( timestamp.length-1 ) === "B" ) { - if ( scenario_theater != "BURMA" ) + if ( scenario_theater !== required_theater ) return "" ; - timestamp = timestamp.substring( 0, timestamp.length-1 ) ; } - if ( timestamp.substring( timestamp.length-1 ) === "R" ) { - if ( nat != "romanian" ) - return "" ; - timestamp = timestamp.substring( 0, timestamp.length-1 ) ; - } - if ( timestamp.substring( timestamp.length-2 ) === "CS" ) { - if ( nat != "croatian" && nat != "slovakian" ) - return "" ; - timestamp = timestamp.substring( 0, timestamp.length-2 ) ; - } - if ( timestamp.substring( timestamp.length-1 ) === "S" ) { - if ( nat != "slovakian" ) - return "" ; - timestamp = timestamp.substring( 0, timestamp.length-1 ) ; + + // check for a nationality flag + NAT_FLAGS = { R: ["romanian"], S: ["slovakian"], CS: ["croatian","slovakian"] } ; + for ( var i=2 ; i >= 1 ; --i ) { + var required_nats = NAT_FLAGS[ timestamp.substring( timestamp.length-i ) ]; + if ( required_nats ) { + timestamp = timestamp.substring( 0, timestamp.length-i ) ; + if ( required_nats.indexOf( nat ) === -1 ) + return "" ; + break ; + } } // remove any trailing "+" (FIXME! What does it even mean? Doesn't make sense :-/) diff --git a/vasl_templates/webapp/tests/test_capabilities.py b/vasl_templates/webapp/tests/test_capabilities.py index 9b4e37a..0cca6e4 100644 --- a/vasl_templates/webapp/tests/test_capabilities.py +++ b/vasl_templates/webapp/tests/test_capabilities.py @@ -467,7 +467,6 @@ def test_nationality_capabilities( webapp, webdriver ): ordnance = [ "romanian", "ordnance", "G obr. 38" ] val = _get_capabilities( webdriver, webapp, *ordnance, "ETO", "01/1940", merge_common=True ) assert "s5[!]" not in val - ordnance = [ "romanian", "ordnance", "G obr. 38" ] val = _get_capabilities( webdriver, webapp, *ordnance, "ETO", "01/1941", merge_common=True ) assert "s5[!]" in val ordnance = [ "slovakian", "ordnance", "G obr. 38" ] @@ -489,7 +488,6 @@ def test_nationality_capabilities( webapp, webdriver ): ordnance = [ "slovakian", "ordnance", "Kanon PUV vz. 37(t)" ] val = _get_capabilities( webdriver, webapp, *ordnance, "ETO", "01/1940", merge_common=True ) assert "A4" not in val - ordnance = [ "slovakian", "ordnance", "Kanon PUV vz. 37(t)" ] val = _get_capabilities( webdriver, webapp, *ordnance, "ETO", "01/1941", merge_common=True ) assert "A4" in val ordnance = [ "croatian", "ordnance", "Kanon PUV vz. 37(t)" ]