Skip to content

Commit

Permalink
feat: field_relevance accept minimal promotion level
Browse files Browse the repository at this point in the history
  • Loading branch information
smotornyuk committed Nov 12, 2024
1 parent aef3213 commit 800db76
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<form id="dataset-edit" class="dataset-form" method="post" action="{{ action }}" data-module="basic-form" novalidate>

{% call form.input_block(field_name, _("Promotion level"), errors[field_name], classes=["search-tweaks-label-with-value"]) %}
<input data-module="search-tweaks-reflect-range-in-label" data-module-format=" (%d)" id="{{ field_name }}" type="range" name="{{ field_name }}" value="{{ data[field_name] }}" max="{{ max_promotion }}" />
<input data-module="search-tweaks-reflect-range-in-label" data-module-format=" (%d)" id="{{ field_name }}" type="range" name="{{ field_name }}" value="{{ data[field_name] }}" min="{{ min_promotion }}" max="{{ max_promotion }}" />
{% endcall %}

{% block form_actions %}
Expand Down
10 changes: 9 additions & 1 deletion ckanext/search_tweaks/field_relevance/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"ckanext.search_tweaks.field_relevance.blueprint.promotion.enabled"
)
CONFIG_PROMOTION_PATH = "ckanext.search_tweaks.field_relevance.blueprint.promotion.path"
CONFIG_MIN_PROMOTION = (
"ckanext.search_tweaks.field_relevance.blueprint.promotion.min_value"
)
CONFIG_MAX_PROMOTION = (
"ckanext.search_tweaks.field_relevance.blueprint.promotion.max_value"
)
Expand All @@ -21,6 +24,7 @@

DEFAULT_ENABLE_PROMOTION_ROUTE = False
DEFAULT_PROMOTION_PATH = "/dataset/promote/<id>"
DEFAULT_MIN_PROMOTION = 0
DEFAULT_MAX_PROMOTION = 100
DEFAULT_PROMOTION_FIELD = "promotion_level"

Expand All @@ -40,7 +44,7 @@ def post(self, id):
schema = {
field: [
tk.get_validator("convert_int"),
tk.get_validator("natural_number_validator"),
tk.get_validator("int_validator"),
tk.get_validator("limit_to_configured_maximum")(
CONFIG_MAX_PROMOTION, DEFAULT_MAX_PROMOTION,
),
Expand Down Expand Up @@ -79,6 +83,10 @@ def get(
"pkg_dict": pkg_dict,
"errors": errors or {},
"data": data or pkg_dict,
"min_promotion": tk.asint(
tk.config.get(CONFIG_MIN_PROMOTION, DEFAULT_MIN_PROMOTION),
),

"max_promotion": tk.asint(
tk.config.get(CONFIG_MAX_PROMOTION, DEFAULT_MAX_PROMOTION),
),
Expand Down

0 comments on commit 800db76

Please sign in to comment.