Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #235 from communitiesuk/FS-3581-Update-Round-defin…
Browse files Browse the repository at this point in the history
…ition-to-cater-optional-or-mandatory-application-feedback

Fs 3581 update round definition to cater optional or mandatory application feedback
  • Loading branch information
RamuniN authored Oct 6, 2023
2 parents 995e1c9 + e8f58a4 commit 88e0f19
Show file tree
Hide file tree
Showing 3 changed files with 253 additions and 48 deletions.
54 changes: 34 additions & 20 deletions db/queries/statuses/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,69 @@
from db.queries.form.queries import get_form
from external_services import get_round
from external_services.data import get_application_sections
from external_services.models.round import FeedbackSurveyConfig


def _is_all_feedback_complete(application_id, fund_id, round_id, language: str):
def _is_all_sections_feedback_complete(
application_id, fund_id, round_id, language: str
):
sections = get_application_sections(fund_id, round_id, language)
sections_feedbacks_completed = all(
all_feedback_completed = all(
get_feedback(application_id, str(s["id"]))
for s in sections
if s.get("requires_feedback")
)
end_of_feedback_survey_completed = all(
return all_feedback_completed


def _is_feedback_survey_complete(application_id):
is_survey_completed = all(
retrieve_end_of_application_survey_data(application_id, pn) for pn in "1234"
)
all_feedback_completed = (
sections_feedbacks_completed and end_of_feedback_survey_completed
)
return all_feedback_completed
return is_survey_completed


def update_application_status(
application_with_forms: Applications, round_requires_feedback: bool
application_with_forms: Applications, feedback_survey_config: FeedbackSurveyConfig
) -> str:
"""
Updates the status of the supplied application based on the status of all
forms with that application, and the status of feedback forms (if the round requires feedback)
forms with that application, and the status of all sections feedback and
survey status (if the round requires feedback)
Parameters:
application_with_forms (`Applications`): Application record to update, with the form jsons populated
This object should be within a db context as the function updates it.
round_requires_feedback (`bool`): Whether or not this round needs feedback
feedback_survey_config (`FeedbackSurveyConfig`): feedback_survey_config of the round
"""

all_feedback_completed = True
if round_requires_feedback:
all_feedback_completed = _is_all_feedback_complete(
application_with_forms.id,
application_with_forms.fund_id,
application_with_forms.round_id,
application_with_forms.language.name,
all_feedback_and_survey_completed = True
if feedback_survey_config.has_section_feedback:
all_feedback_and_survey_completed = (
feedback_survey_config.is_section_feedback_optional
or _is_all_sections_feedback_complete(
application_with_forms.id,
application_with_forms.fund_id,
application_with_forms.round_id,
application_with_forms.language.name,
)
)

if feedback_survey_config.has_feedback_survey:
all_feedback_and_survey_completed = all_feedback_and_survey_completed and (
feedback_survey_config.is_feedback_survey_optional
or _is_feedback_survey_complete(application_with_forms.id)
)

form_statuses = [form.status.name for form in application_with_forms.forms]
if "IN_PROGRESS" in form_statuses:
status = "IN_PROGRESS"
elif "COMPLETED" in form_statuses and (
"NOT_STARTED" in form_statuses or not all_feedback_completed
"NOT_STARTED" in form_statuses or not all_feedback_and_survey_completed
):
status = "IN_PROGRESS"
elif "COMPLETED" in form_statuses and all_feedback_completed:
elif "COMPLETED" in form_statuses and all_feedback_and_survey_completed:
status = "COMPLETED"
elif "SUBMITTED" in form_statuses:
status = "SUBMITTED"
Expand Down Expand Up @@ -231,5 +245,5 @@ def update_statuses(
)
db.session.commit()

update_application_status(application, round.requires_feedback)
update_application_status(application, round.feedback_survey_config)
db.session.commit()
33 changes: 31 additions & 2 deletions external_services/models/round.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
import inspect
from dataclasses import dataclass
from typing import Optional


@dataclass
class FeedbackSurveyConfig:
has_feedback_survey: bool = False
is_feedback_survey_optional: bool = True
has_section_feedback: bool = False
is_section_feedback_optional: bool = True

@staticmethod
def from_json(d: dict):
# Filter unknown fields from JSON dictionary
return FeedbackSurveyConfig(
**{
k: v
for k, v in d.items()
if k in inspect.signature(FeedbackSurveyConfig).parameters
}
)


@dataclass
class Round:
id: str
Expand All @@ -12,9 +32,17 @@ class Round:
title: str
short_name: str
contact_email: str
requires_feedback: bool = False
project_name_field_id: Optional[str] = None
mark_as_complete_enabled: bool = False
feedback_survey_config: FeedbackSurveyConfig = None

def __post_init__(self):
if isinstance(self.feedback_survey_config, dict):
self.feedback_survey_config = FeedbackSurveyConfig.from_json(
self.feedback_survey_config
)
elif self.feedback_survey_config is None:
self.feedback_survey_config = FeedbackSurveyConfig()

@staticmethod
def from_json(data: dict):
Expand All @@ -28,6 +56,7 @@ def from_json(data: dict):
assessment_deadline=data["assessment_deadline"],
project_name_field_id=data.get("project_name_field_id", None),
contact_email=data.get("contact_email", None),
requires_feedback=data.get("requires_feedback") or False,
feedback_survey_config=data.get("feedback_survey_config")
or FeedbackSurveyConfig(),
mark_as_complete_enabled=data.get("mark_as_complete_enabled") or False,
)
Loading

0 comments on commit 88e0f19

Please sign in to comment.