From d9d3d2ad5f7245eef3c990dbdeeacede2b4bf36c Mon Sep 17 00:00:00 2001 From: Javier Sánchez Parra Date: Mon, 23 May 2022 10:29:21 +0200 Subject: Add repository field to "Create image" form Let users choose which repository want to use to save the image. --- ogcp/forms/action_forms.py | 2 ++ ogcp/views.py | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'ogcp') 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) -- cgit v1.2.3-18-g5258