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

Allow dropdown text for unlisted choice to be configurable #777

Merged
merged 12 commits into from
Sep 2, 2023
Merged
10 changes: 9 additions & 1 deletion kubespawner/spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -1543,6 +1543,7 @@ def _validate_image_pull_secrets(self, proposal):
selected "Other" as a choice:
- `enabled`: Boolean, whether the free form input should be enabled
- `display_name`: String, label for input field
- `other_text`: Optional, text to show in Select Dropdown for Other option
consideRatio marked this conversation as resolved.
Show resolved Hide resolved
- `validation_regex`: Optional, regex that the free form input should match - eg. ^pangeo/.*$
- `validation_message`: Optional, validation message for the regex. Should describe the required
input format in a human-readable way.
Expand Down Expand Up @@ -1605,6 +1606,7 @@ def _validate_image_pull_secrets(self, proposal):
'unlisted_choice': {
'enabled': True,
'display_name': 'Other image',
'display_name_in_choices': 'Enter image manually',
'validation_regex': '^jupyter/.+:.+$',
'validation_message': 'Must be an image matching ^jupyter/<name>:<tag>$',
'kubespawner_override': {'image': '{value}'},
Expand Down Expand Up @@ -3242,7 +3244,13 @@ def _get_initialized_profile_list(self, profile_list: list):
# pre-defined choices were provided without a default choice
default_choice = list(option_config['choices'].keys())[0]
option_config['choices'][default_choice]["default"] = True

if option_config.get('unlisted_choice'):
if not 'display_name_in_choices' in option_config.get(
'unlisted_choice'
):
option_config['unlisted_choice'][
'display_name_in_choices'
] = "Other..."
batpad marked this conversation as resolved.
Show resolved Hide resolved
# ensure there is one default profile
if not any(p.get("default") for p in profile_list):
profile_list[0]["default"] = True
Expand Down
2 changes: 1 addition & 1 deletion kubespawner/templates/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h3>{{ profile.display_name }}</h3>
<option value="{{ k }}" {% if choice.default %}selected{% endif %}>{{ choice.display_name }}</option>
{%- endfor %}
{%- if option['unlisted_choice'] and option['unlisted_choice']['enabled'] %}
batpad marked this conversation as resolved.
Show resolved Hide resolved
<option value="unlisted-choice">Other...</option>
<option value="unlisted-choice">{{ option['unlisted_choice']['display_name_in_choices'] }}</option>
{%- endif %}
</select>
</div>
Expand Down
5 changes: 4 additions & 1 deletion tests/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@
},
'only-unlisted': {
'display_name': 'Some option without any choices set',
'unlisted_choice': {'enabled': True},
'unlisted_choice': {
'enabled': True,
'display_name_in_choices': 'Other...',
},
},
'explicit-defaults': {
'display_name': 'Some choice with a default set',
Expand Down