Skip to content

Commit

Permalink
FS-4941 - Manually fix remaining issues highlighted by ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
wjrm500 committed Dec 23, 2024
1 parent 3e3d08c commit dd5fb7d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
26 changes: 13 additions & 13 deletions app/blueprints/fund_builder/forms/round.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def validate_json_field(form, field):
try:
json.loads(str_content)
except Exception as ex:
raise ValidationError(f"Content is not valid JSON. Underlying error: [{str(ex)}]")
raise ValidationError(f"Content is not valid JSON. Underlying error: [{str(ex)}]") from ex


def validate_flexible_url(form, field):
Expand Down Expand Up @@ -69,8 +69,8 @@ def get_datetime(form_field):
try:
form_field_datetime = datetime.datetime(year, month, day, hour=hour, minute=minute).strftime("%m-%d-%Y %H:%M")
return form_field_datetime
except ValueError:
raise ValidationError(f"Invalid date entered for {form_field}")
except ValueError as ex:
raise ValidationError(f"Invalid date entered for {form_field}") from ex


class DateInputForm(Form):
Expand All @@ -85,38 +85,38 @@ def validate_day(self, field):
day = int(field.data)
if day < 1 or day > 31:
raise ValidationError("Day must be between 1 and 31 inclusive.")
except ValueError:
raise ValidationError("Invalid Day")
except ValueError as ex:
raise ValidationError("Invalid Day") from ex

def validate_month(self, field):
try:
month = int(field.data)
if month < 1 or month > 12:
raise ValidationError("Month must be between 1 and 12")
except ValueError:
raise ValidationError("Invalid month")
except ValueError as ex:
raise ValidationError("Invalid month") from ex

def validate_year(self, field):
try:
int(field.data)
except ValueError:
raise ValidationError("Invalid Year")
except ValueError as ex:
raise ValidationError("Invalid Year") from ex

def validate_hour(self, field):
try:
hour = int(field.data)
if hour < 0 or hour > 23:
raise ValidationError("Hour must be between 0 and 23 inclusive.")
except ValueError:
raise ValidationError("Invalid Day")
except ValueError as ex:
raise ValidationError("Invalid Day") from ex

def validate_minute(self, field):
try:
minute = int(field.data)
if minute < 0 or minute >= 60:
raise ValidationError("Minute must be between 0 and 59 inclusive.")
except ValueError:
raise ValidationError("Invalid Day")
except ValueError as ex:
raise ValidationError("Invalid Day") from ex


class RoundForm(FlaskForm):
Expand Down
4 changes: 2 additions & 2 deletions app/db/queries/fund.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ def add_organisation(organisation: Organisation) -> Organisation:
def add_fund(fund: Fund) -> Fund:
db.session.add(fund)
db.session.commit()
current_app.logger.info(f"Fund added with fund_id: '{fund.fund_id}.")
current_app.logger.info("Fund added with fund_id: '%s'.", fund.fund_id)
return fund


def update_fund(fund: Fund) -> Fund:
db.session.commit()
current_app.logger.info(f"Fund updated with fund_id: '{fund.fund_id}.")
current_app.logger.info("Fund updated with fund_id: '%s'.", fund.fund_id)
return fund


Expand Down
4 changes: 2 additions & 2 deletions app/db/queries/round.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
def add_round(round: Round) -> Round:
db.session.add(round)
db.session.commit()
current_app.logger.info(f"Round added with round_id: '{round.round_id}.")
current_app.logger.info("Round added with round_id: '%s'.", round.round_id)
return round


def update_round(round: Round) -> Round:
db.session.commit()
current_app.logger.info(f"Round updated with round_id: '{round.round_id}.")
current_app.logger.info("Round updated with round_id: '%s'.", round.round_id)
return round


Expand Down
6 changes: 3 additions & 3 deletions app/export_config/generate_fund_round_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def generate_application_display_config(round_id):
TEMPLATE_FUND_ROUND_EXPORT["base_path"] = round_base_path
"sort by Section.index"
sections = db.session.query(Section).filter(Section.round_id == round_id).order_by(Section.index).all()
current_app.logger.info(f"Generating application display config for round {round_id}")
current_app.logger.info("Generating application display config for round %s", round_id)

for original_section in sections:
section = copy.deepcopy(original_section)
Expand Down Expand Up @@ -84,7 +84,7 @@ def generate_fund_config(round_id):
round = get_round_by_id(round_id)
fund_id = round.fund_id
fund = get_fund_by_id(fund_id)
current_app.logger.info(f"Generating fund config for fund {fund_id}")
current_app.logger.info("Generating fund config for fund %s", fund_id)

fund_export = FundExport(
id=str(fund.fund_id),
Expand All @@ -104,7 +104,7 @@ def generate_fund_config(round_id):

def generate_round_config(round_id):
round = get_round_by_id(round_id)
current_app.logger.info(f"Generating round config for round {round_id}")
current_app.logger.info("Generating round config for round %s", round_id)

round_export = RoundExport(
id=str(round.round_id),
Expand Down
4 changes: 2 additions & 2 deletions app/export_config/generate_fund_round_form_jsons.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def generate_form_jsons_for_round(round_id, base_output_dir=None):
raise ValueError("Round ID is required to generate form JSONs.")
round = get_round_by_id(round_id)
fund = get_fund_by_id(round.fund_id)
current_app.logger.info(f"Generating form JSONs for round {round_id}.")
current_app.logger.info("Generating form JSONs for round %s", round_id)
for section in round.sections:
for form in section.forms:
result = build_form_json(form=form, fund_title=fund.title_json["en"])
Expand All @@ -99,4 +99,4 @@ def generate_form_jsons_for_round(round_id, base_output_dir=None):
if valid_json:
write_config(form_json, form.runner_publish_name, round.short_name, "form_json", base_output_dir)
else:
current_app.logger.error(f"Form JSON for {form.runner_publish_name} is invalid.")
current_app.logger.error("Form JSON for %s is invalid.", form.runner_publish_name)
2 changes: 1 addition & 1 deletion app/export_config/generate_fund_round_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def generate_all_round_html(round_id, base_output_dir=None):
"""
if not round_id:
raise ValueError("Round ID is required to generate HTML.")
current_app.logger.info(f"Generating HTML for round {round_id}.")
current_app.logger.info("Generating HTML for round %s", round_id)
round = get_round_by_id(round_id)
fund = get_fund_by_id(round.fund_id)
sections_in_round = round.sections
Expand Down

0 comments on commit dd5fb7d

Please sign in to comment.