Skip to content

Commit

Permalink
Merge pull request #29 from lsst-sqre/tickets/DM-29112
Browse files Browse the repository at this point in the history
[DM-29112] Produce the drop down list
  • Loading branch information
cbanek authored Mar 15, 2021
2 parents 9b66d16 + b4eef74 commit 1e216fd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/nublado2/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ async def pre_spawn(self, spawner: Spawner) -> None:
# selected.
size_name = options["size"][0]
image_name = options["image"][0]
image_tag = options["image_tag"][0]

# If the user selected one of the images in the dropdown,
# use image.
if image_name == "image_tag":
image_name = image_tag

# Take size and image names, which are returned as form data,
# look up associated values, and configure the spawner.
Expand Down
22 changes: 18 additions & 4 deletions src/nublado2/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
>
{{ i.name }}<br />
{% endfor %}
<input type="radio" name="image" id="image_tag" value="image_tag">
Select historical image:<br />
<select name="image_tag">
{% for i in all_images %}
<option value="{{ i.image_url }}">{{ i.name }}</option>
{% endfor %}
</select>
</td>
<td width="50%">
Expand Down Expand Up @@ -66,16 +74,22 @@ async def show_options_form(self, spawner: Spawner) -> str:
sizes = options_config["sizes"]

images_url = options_config.get("images_url")
images = await self._get_images_from_url(images_url)

cachemachine_response = await self._get_images_from_url(images_url)

all_images = cachemachine_response["all"]
images = cachemachine_response["images"]
images.extend(options_config["images"])

return options_template.render(images=images, sizes=sizes)
return options_template.render(
all_images=all_images, images=images, sizes=sizes
)

async def _get_images_from_url(
self, url: Optional[str]
) -> List[Dict[str, str]]:
) -> Dict[str, List[Dict[str, str]]]:
if not url:
return []
return {"all": [], "images": []}

r = await session.get(url)
if r.status != 200:
Expand Down

0 comments on commit 1e216fd

Please sign in to comment.