Skip to content

Commit

Permalink
fixes: questionnaire ui fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
saladgg committed Jan 11, 2022
1 parent d82d906 commit 77c7317
Show file tree
Hide file tree
Showing 16 changed files with 6,007 additions and 5,511 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ jobs:
- name: mypy
run: |
sudo apt-get update && sudo apt-get upgrade
mypy .
pytest:
Expand Down Expand Up @@ -105,6 +106,7 @@ jobs:
- name: Set up Django
run: |
sudo apt-get update && sudo apt-get upgrade
python manage.py migrate
python manage.py createcachetable
python manage.py collectstatic --noinput
Expand Down
Binary file modified data/all_mfl_facilities.xlsx
Binary file not shown.
Binary file added data/updated_fyj_facilities.xlsx
Binary file not shown.
1 change: 1 addition & 0 deletions fahari/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"Mowlem",
"Umoja I",
"Umoja II",
"Utawala",
),
"Kamukunji": (
"Airbase",
Expand Down
2 changes: 1 addition & 1 deletion fahari/common/tests/test_administrative_unit_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_get_wards():
assert ("Ziwani/Kariokor", "Ziwani/Kariokor") in wards
assert ("Landimawe", "Landimawe") in wards
assert ("Nairobi South", "Nairobi South") in wards
assert len(wards) == 109
assert len(wards) == 110


def test_get_wards_for_sub_county_with_missing_sub_county():
Expand Down
2 changes: 1 addition & 1 deletion fahari/common/views/mixins/drf_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_excel_io(self, **kwargs) -> EIO:
excel_io_class = self.get_excel_io_class()
default_kwargs = self.get_excel_io_kwargs()
default_kwargs.update(kwargs)
return excel_io_class(**default_kwargs) # type: ignore
return excel_io_class(**default_kwargs)

def get_excel_io_kwargs(self) -> Dict[str, Any]:
"""Return kwargs to be used when initializing an excel io instance."""
Expand Down
2 changes: 1 addition & 1 deletion fahari/misc/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ class ProcessGoogleSheetRowError(RuntimeError):
def __init__(self, row: Sequence[str], row_index: int, *args, **kwargs):
self.row: Sequence[str] = tuple(row)
self.row_index: int = row_index
super().__init__(*args, **kwargs) # type: ignore
super().__init__(*args, **kwargs)
15 changes: 11 additions & 4 deletions fahari/sims/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,13 +828,17 @@ def is_complete(self) -> bool:
.exists()
)

@property
def total_questions(self) -> float:
"""Return the total questions in the questionnaire"""
return Question.objects.for_questionnaire(self.questionnaire).count()

@property
def progress(self) -> float:
"""Return the completion status of the given questionnaire as a percentage."""

total_questions = Question.objects.for_questionnaire(self.questionnaire).count()
answered_count = self.answers.filter(_IS_VALID_ANSWER).count() # noqa
return answered_count / total_questions
return answered_count / self.total_questions

@property
def questions(self) -> QuestionQuerySet:
Expand All @@ -843,8 +847,11 @@ def questions(self) -> QuestionQuerySet:
return Question.objects.for_questionnaire(questionnaire=self.questionnaire)

def get_absolute_url(self):
update_url = reverse_lazy("sims:questionnaire_responses_update", kwargs={"pk": self.pk})
return update_url
is_complete = bool(self.finish_date is not None)
if is_complete:
return reverse_lazy("sims:questionnaire_responses_capture", kwargs={"pk": self.pk})
else:
return reverse_lazy("sims:questionnaire_responses_update", kwargs={"pk": self.pk})

def __str__(self) -> str:
return "Facility: %s, Questionnaire: %s, Submitted: %s" % (
Expand Down
1 change: 0 additions & 1 deletion fahari/sims/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ def get_context_data(self, **kwargs):
context["questionnaire"] = questionnaire_obj
context["questionnaire_is_complete"] = responses.is_complete
context["total_steps"] = 2

return context


Expand Down
2 changes: 1 addition & 1 deletion fahari/templates/pages/sims/questionnaire_responses.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ <h1 class="h3 mb-4 text-gray-800">
<th>Questionnaire</th>
<th>Started On</th>
<th>Progress</th>
<th></th>
<th class="read_submitted"></th>
</tr>
</thead>
</table>
Expand Down
51 changes: 45 additions & 6 deletions fahari/templates/pages/sims/questionnaire_responses_capture.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,46 @@
{% endblock title %}
{% block content %}
{% block page_title %}
<p class="font-weight-bolder">
Step {{ current_step }} of {{ total_steps }}
</p>
<h1 class="h3 text-gray-800"> {{ questionnaire }} </h1>
<h6 class="h6 text-muted text-gray-800 mb-4"> {{ object.facility.name }} </h6>
<div class="col pt-2">

<h3 class"text-gray-800">
{{ questionnaire }}
</h3>

<p class="font-weight-bolder">
Step {{ current_step }} of {{ total_steps }}
</p>
<h6 class="h6 text-muted text-gray-800 mb-4">{{ object.facility.name }} </h6>

{% if questionnaire_is_complete %}
<a data-toggle="collapse" href="#collapseMentorsList"
aria-expanded="false" aria-controls="collapseMentorsList">
<h5>Mentors list</h5>
</a>
{% endif %}
<div class="collapse" id="collapseMentorsList">
<table class="table table-sm table-bordered">
<thead>
<th>#</th>
<th>Name</th>
<th>Phone</th>
<th>Role</th>
<th>Organisation</th>
</thead>
<tbody>
{%for mentor in object.metadata.mentors%}
<tr>
<td>{{forloop.counter}}.</td>
<td>{{mentor.name}}</td>
<td>{{mentor.phone_number}}</td>
<td>{{mentor.role}}</td>
<td>{{mentor.member_org}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endblock page_title %}
{% if perms.sims.change_questionnaireresponses %}
{% block questionnaire_metadata_container %}
Expand All @@ -27,7 +62,11 @@ <h6 class="h6 text-muted text-gray-800 mb-4"> {{ object.facility.name }} </h6>
{% block questionnaire_navigate_container %}
<div class="row align-items-end my-3">
<div class="col">
{% if questionnaire_is_complete %}
<a class="btn btn-secondary px-5" href="{% url 'sims:questionnaire_responses' %}">Back</a>
{% else %}
<a class="btn btn-secondary px-5" href="{% url 'sims:questionnaire_responses_update' object.pk %}">Back</a>
{% endif %}
</div>
<div class="col">
{% if not questionnaire_is_complete %}
Expand Down Expand Up @@ -57,7 +96,7 @@ <h5 class="modal-title">Confirm Questionnaire Submission</h5>
<p id="p_submission_content" class="lead"></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button id="btn_submit_confirm" type="button" class="btn btn-primary">
<span class="text">Proceed</span>
</button>
Expand Down
2 changes: 1 addition & 1 deletion fahari/utils/excel_utils/drf_serializer_excel_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def get_template(self, *args, **kwargs) -> T:
self.get_fields(), self.get_nested_entries_delimiter()
)

return template_class(*args, **kwargs) # type: ignore
return template_class(*args, **kwargs)

def get_template_class(self) -> Type[T]:
"""Return a class to use for the template. Defaults to using `self.template_class`."""
Expand Down
Loading

0 comments on commit 77c7317

Please sign in to comment.