Skip to content

Commit

Permalink
rename variables after review
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaetan Semet committed Mar 19, 2018
1 parent f4d97f7 commit e7c4735
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions kubespawner/spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,34 +794,34 @@ def _hub_connect_port_default(self):
)

form_template = Unicode(
"""<label for="profile">Please select a profile for your Jupyter:</label>
"""<label for="profile">Please select a profile for your environment:</label>
<select class="form-control" name="profile" required autofocus>
{input_template}
{inputs}
</select>
""",
config = True,
help = """Template to use to construct options_form text. {input_template} is replaced with
the result of formatting input_template against each item in the profiles list."""
help = """Template to use to construct options_form text. {inputs} is replaced with
the result of formatting inputs against each item in the profiles list."""
)

input_template = Unicode("""
inputs = Unicode("""
<option value="{key}" {first}>{display}</option>""",
config = True,
help = """Template to construct {input_template} in form_template. This text will be formatted
help = """Template to construct {inputs} in form_template. This text will be formatted
against each item in the profiles list, in order, using the following key names:
( display, key, type ) for the first three items in the tuple, and additionally
first = "checked" (taken from first_template) for the first item in the list, so that
first = "checked" (taken from first_input) for the first item in the list, so that
the first item starts selected."""
)

first_template = Unicode('selected',
first_input = Unicode('selected',
config=True,
help="Text to substitute as {first} in input_template"
help="Text to substitute as {first} in inputs"
)

options_form = Unicode()

single_user_profile_list = List(
profile_list = List(
trait = Dict(),
default_value = None,
minlen = 0,
Expand Down Expand Up @@ -1147,27 +1147,28 @@ def get_args(self):
return args

def _options_form_default(self):
if not self.single_user_profile_list:
if not self.profile_list:
return
temp_keys = [
{
'display': p.get('display_name', self.UNDEFINED_DISPLAY_NAME),
'key': i,
'first': '',
} for i, p in enumerate(self.single_user_profile_list)]
temp_keys[0]['first'] = self.first_template
text = ''.join([ self.input_template.format(**tk) for tk in temp_keys ])
return self.form_template.format(input_template=text)
} for i, p in enumerate(self.profile_list)]
temp_keys[0]['first'] = self.first_input
text = ''.join([ self.inputs.format(**tk) for tk in temp_keys ])
return self.form_template.format(inputs=text)

def options_from_form(self, formdata):
if not self.single_user_profile_list:
return form_data
if not self.profile_list:
return formdata
# Default to first profile if somehow none is provided
selected_profile = int(formdata.get('profile',[0])[0])
options = self.single_user_profile_list[selected_profile]
options = self.profile_list[selected_profile]
self.log.debug("Applying KubeSpawner override for profile '%s'",
options.get('display_name', self.UNDEFINED_DISPLAY_NAME))
kubespawner_override = options.get('kubespawner_override', {})
for k, v in kubespawner_override.items():
self.log.debug(".. overriding KubeSpawner value %s=%s", k, v)
setattr(self, k, v)
return options

0 comments on commit e7c4735

Please sign in to comment.