Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add assessment fields: private & hypothetical #280

Merged
merged 2 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions usaon_benefit_tool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def emit(self, record):

app.logger.addHandler(InterceptHandler())

loguru_logger.info("Logging configured.")
loguru_logger.debug("Logging configured.")


def _setup_config(app) -> None:
Expand All @@ -100,7 +100,7 @@ def _setup_config(app) -> None:
# DEV ONLY: Disable login
app.config['LOGIN_DISABLED'] = envvar_is_true("USAON_BENEFIT_TOOL_LOGIN_DISABLED")

loguru_logger.info("App configuration initialized.")
loguru_logger.debug("App configuration initialized.")


def _setup_proxy_support(app) -> None:
Expand Down Expand Up @@ -136,7 +136,7 @@ def before_request():
if time.time() >= token['expires_at']:
del s['google_oauth_token']

loguru_logger.info("Login configured.")
loguru_logger.debug("Login configured.")


def _register_template_helpers(app) -> None:
Expand Down Expand Up @@ -164,7 +164,7 @@ def _register_template_helpers(app) -> None:
dateformat=lambda date: date.strftime("%Y-%m-%d %H:%M%Z"),
)

loguru_logger.info("Template helpers registered.")
loguru_logger.debug("Template helpers registered.")


def _register_blueprints(app) -> None:
Expand Down Expand Up @@ -193,7 +193,7 @@ def _register_blueprints(app) -> None:
app.register_blueprint(nodes_bp)
app.register_blueprint(node_bp)

loguru_logger.info("Blueprints registered.")
loguru_logger.debug("Blueprints registered.")


def _register_custom_error_pages(app) -> None:
Expand All @@ -206,7 +206,7 @@ def _register_custom_error_pages(app) -> None:
),
)

loguru_logger.info("Custom error pages registered.")
loguru_logger.debug("Custom error pages registered.")


def _monkeypatch():
Expand Down
22 changes: 21 additions & 1 deletion usaon_benefit_tool/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class CustomModelConverter(ModelConverter):

@converts("String")
def conv_String(self, field_args, **extra):
"""Automatically use <textarea> over <input> for large string fields."""
self._string_common(field_args=field_args, **extra)
if (
extra['column'].type.length is not None
Expand All @@ -45,6 +46,17 @@ def conv_String(self, field_args, **extra):

return super().conv_String(field_args, **extra)

@converts("Boolean")
def conv_Boolean(self, field_args, **_):
"""Prevent a required checkbox from failing client-side validation when False.

"Unchecked" is a valid value: False!

See: https://github.com/wtforms/wtforms-sqlalchemy/issues/47
"""
field_args["validators"] = []
return fields.BooleanField(**field_args)


def get_node_label(node: Node) -> str:
return f"Object #{node.id} ({node.type.value}): {node.title}"
Expand All @@ -62,7 +74,15 @@ def get_node_label(node: Node) -> str:
BaseModel: DeclarativeMeta = db.Model

FORMS_BY_MODEL: dict[BaseModel, FlaskForm] = {
Assessment: model_form(Assessment, only=['title', 'description']),
Assessment: model_form(
Assessment,
only=[
'title',
'description',
'private',
'hypothetical',
],
),
AssessmentNode: model_form(
AssessmentNode,
only=['node'],
Expand Down
26 changes: 6 additions & 20 deletions usaon_benefit_tool/models/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,27 +86,13 @@ class User(BaseModel, UserMixin):

class Assessment(BaseModel):
__tablename__ = 'assessment'
id = Column(
Integer,
primary_key=True,
autoincrement=True,
)

title = Column(
String(128),
nullable=False,
)
id = Column(Integer, primary_key=True, autoincrement=True)

description = Column(
String(512),
nullable=True,
)
title = Column(String(128), nullable=False)
description = Column(String(512), nullable=True)

private = Column(
Boolean,
nullable=False,
default=False,
)
private = Column(Boolean, nullable=False, default=False)
hypothetical = Column(Boolean, nullable=False, default=False)

status_id = Column(
String,
Expand Down Expand Up @@ -251,7 +237,7 @@ class NodeSubtypeOther(Node):
website = Column(String(256), nullable=True)
contact_information = Column(String(256), nullable=False)
persistent_identifier = Column(String(256), nullable=True)
hypothetical = Column(Boolean)
hypothetical = Column(Boolean, nullable=False, default=False)


class NodeSubtypeSocietalBenefitArea(Node):
Expand Down
2 changes: 2 additions & 0 deletions usaon_benefit_tool/templates/assessments.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ <h2>{% block title %}Assessments{% endblock %}</h1>
<th>Created time</th>
<th>Updated time</th>
<th>Visibility</th>
<th>Hypothetical?</th>
{% endif %}

<th>Status</th>
Expand All @@ -66,6 +67,7 @@ <h2>{% block title %}Assessments{% endblock %}</h1>
<td>{{assessment.created_timestamp | dateformat}}</td>
<td>{{assessment.updated_timestamp | dateformat}}</td>
<td>{{private_badge(assessment.private)}}</td>
<td>{{assessment.hypothetical}}</td>
{% endif %}

<td>{{assessment.status.id}}</td>
Expand Down
Loading