Merge branch 'feature/infected_people_max' into 'master'
Total number of infected people limit Closes #286 See merge request cara/caimira!399
This commit is contained in:
commit
1624f855a5
4 changed files with 46 additions and 19 deletions
|
|
@ -189,9 +189,12 @@ class FormData:
|
|||
return form_dict
|
||||
|
||||
def validate(self):
|
||||
# Validate number of infected people == 1 when activity is Conference/Training.
|
||||
if self.activity_type == 'training' and self.infected_people > 1:
|
||||
raise ValueError('Conference/Training activities are limited to 1 infected.')
|
||||
# Validate number of infected <= number of total people
|
||||
if self.infected_people > self.total_people:
|
||||
raise ValueError('Number of infected people cannot be more than number of total people.')
|
||||
elif self.infected_people >= self.total_people:
|
||||
raise ValueError('Number of infected people cannot be more or equal than number of total people.')
|
||||
|
||||
# Validate time intervals selected by user
|
||||
time_intervals = [
|
||||
|
|
|
|||
|
|
@ -195,16 +195,26 @@ function set_disabled_status(id, option) {
|
|||
$(id).removeClass("disabled");
|
||||
}
|
||||
|
||||
function setMaxInfectedPeople() {
|
||||
$("#training_limit_error").hide();
|
||||
var max = $("#total_people").val()
|
||||
function validateMaxInfectedPeople() {
|
||||
let infected_people = document.getElementById("infected_people");
|
||||
removeErrorFor(infected_people);
|
||||
$(infected_people).removeClass("red_border");
|
||||
|
||||
let infected = infected_people.valueAsNumber;
|
||||
let max = document.getElementById("total_people").valueAsNumber;
|
||||
|
||||
if ($("#activity_type").val() === "training") {
|
||||
max = 1;
|
||||
$("#training_limit_error").show();
|
||||
if ($("#activity_type").val() === "training" && infected > 1) {
|
||||
insertErrorFor(infected_people, "Conference/Training activities limited to 1 infected person.");
|
||||
$(infected_people).addClass("red_border");
|
||||
return false;
|
||||
}
|
||||
else if (infected >= max) {
|
||||
insertErrorFor(infected_people, "Value is equal or higher than the total number of occupants.");
|
||||
$(infected_people).addClass("red_border");
|
||||
return false;
|
||||
}
|
||||
|
||||
$("#infected_people").attr("max", max);
|
||||
return true;
|
||||
}
|
||||
|
||||
function removeInvalid(id) {
|
||||
|
|
@ -497,6 +507,9 @@ function validate_form(form) {
|
|||
}
|
||||
}
|
||||
|
||||
//Validate number of infected people
|
||||
if (!validateMaxInfectedPeople()) submit = false;
|
||||
|
||||
//Validate all non zero values
|
||||
$("input[required].non_zero").each(function() {
|
||||
if (!validateValue(this)) {
|
||||
|
|
@ -876,9 +889,11 @@ $(document).ready(function () {
|
|||
|
||||
// Setup the maximum number of people at page load (to handle back/forward),
|
||||
// and update it when total people is changed.
|
||||
setMaxInfectedPeople();
|
||||
$("#total_people").change(setMaxInfectedPeople);
|
||||
$("#activity_type").change(setMaxInfectedPeople);
|
||||
validateMaxInfectedPeople();
|
||||
$("#total_people").change(validateMaxInfectedPeople);
|
||||
$("#activity_type").change(validateMaxInfectedPeople);
|
||||
$("#total_people").change(validateMaxInfectedPeople);
|
||||
$("#infected_people").change(validateMaxInfectedPeople);
|
||||
|
||||
//Validate all non zero values
|
||||
$("input[required].non_zero").each(function() {validateValue(this)});
|
||||
|
|
|
|||
|
|
@ -313,11 +313,10 @@
|
|||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<div class="col-sm-4"><label class="col-form-label">Number of infected people: </label></div>
|
||||
<div class="col-sm-6 align-self-center"><input type="number" id="infected_people" class="form-control" name="infected_people" min=1 value=1 required></div>
|
||||
<div class="col-sm-4" style="top: -2px"><label>Number of infected people: </label></div>
|
||||
<div class="col-sm-6"><input type="number" id="infected_people" class="form-control" name="infected_people" min=1 value=1 required></div>
|
||||
</div>
|
||||
|
||||
<span id="training_limit_error" class="red_text" hidden>Conference/Training activities limited to 1 infected<br></span>
|
||||
<hr width="80%">
|
||||
|
||||
<div class="form-group row">
|
||||
|
|
|
|||
|
|
@ -167,10 +167,20 @@ def test_ventilation_window_hepa(baseline_form: model_generator.FormData):
|
|||
assert ventilation == baseline_vent
|
||||
|
||||
|
||||
def test_infected_less_than_total_people(baseline_form: model_generator.FormData):
|
||||
baseline_form.total_people = 10
|
||||
baseline_form.infected_people = 11
|
||||
with pytest.raises(ValueError, match='Number of infected people cannot be more than number of total people.'):
|
||||
@pytest.mark.parametrize(
|
||||
["activity", "total_people", "infected_people", "error"],
|
||||
[
|
||||
['office', 10, 11, "Number of infected people cannot be more or equal than number of total people."],
|
||||
['office', 10, 10, "Number of infected people cannot be more or equal than number of total people."],
|
||||
['training', 10, 2, "Conference/Training activities are limited to 1 infected."],
|
||||
]
|
||||
)
|
||||
def test_infected_less_than_total_people(activity, total_people, infected_people, error,
|
||||
baseline_form: model_generator.FormData):
|
||||
baseline_form.activity_type = activity
|
||||
baseline_form.total_people = total_people
|
||||
baseline_form.infected_people = infected_people
|
||||
with pytest.raises(ValueError, match=error):
|
||||
baseline_form.validate()
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue