summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2022-05-23 10:29:21 +0200
committerJavier Sánchez Parra <jsanchez@soleta.eu>2022-05-24 09:28:51 +0200
commitd9d3d2ad5f7245eef3c990dbdeeacede2b4bf36c (patch)
tree5368a02d21c3994b572338f1e103420b98924326
parentb74820a84c7c0b14d421a271a0494fa6103ba031 (diff)
Add repository field to "Create image" form
Let users choose which repository want to use to save the image.
-rw-r--r--ogcp/forms/action_forms.py2
-rw-r--r--ogcp/views.py14
2 files changed, 15 insertions, 1 deletions
diff --git a/ogcp/forms/action_forms.py b/ogcp/forms/action_forms.py
index a60115c..b94ad09 100644
--- a/ogcp/forms/action_forms.py
+++ b/ogcp/forms/action_forms.py
@@ -140,6 +140,8 @@ class ImageCreateForm(FlaskForm):
name = StringField(label=_l('Image name'),
validators=[InputRequired()])
description = StringField(label=_l('Description'))
+ repository = SelectField(label=_l('Repository'), choices=[],
+ validators=[InputRequired()])
create = SubmitField(label=_l('Create'))
diff --git a/ogcp/views.py b/ogcp/views.py
index d68ce25..9f3d217 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -121,6 +121,13 @@ def get_clients(state_filter=None):
return filter(clients.items(), lambda c: c.state == state_filter)
return clients
+
+def get_repositories():
+ r = g.server.get('/repositories')
+ repositories = r.json()['repositories']
+ return repositories
+
+
def parse_scopes_from_tree(tree, scope_type):
scopes = []
for scope in tree['scope']:
@@ -956,7 +963,7 @@ def action_image_create():
"partition": partition,
"code": code,
"name": form.name.data,
- "repository": g.server.ip,
+ "repository": form.repository.data,
"id": "0", # This is ignored by the server.
"description": form.description.data,
"group_id": 0, # Default group.
@@ -987,6 +994,11 @@ def action_image_create():
f"{_('Partition')} {part_id} | "
f"{_('FS')} {FS_CODES[fs_id]}")
form.os.choices.append((choice_value, choice_name))
+
+ repositories = get_repositories()
+ for repo in repositories:
+ form.repository.choices.append((repo['ip'], repo['name']))
+
scopes, clients = get_scopes(set(ips))
return render_template('actions/image_create.html', form=form,
scopes=scopes)