Explorar el Código

finishing adding linked resources to edit pages on tool path

joel
Simon Bowie hace 2 años
padre
commit
f786438f84
Se han modificado 2 ficheros con 13 adiciones y 8 borrados
  1. +5
    -2
      web/app/templates/edit.html
  2. +8
    -6
      web/app/tool.py

+ 5
- 2
web/app/templates/edit.html Ver fichero

@@ -79,11 +79,14 @@
<label for="linked_practice_id">Linked resources</label>
</div>
<div class="mb-3 mt-3">
{{ links }}
<select name="linked_resources" id="linked_resources" aria-label="Linked resources" class="selectpicker" data-live-search="true" multiple>
{% for resource_dropdown in resource_dropdown %}
{% if resource_dropdown['type'] != 'tool' %}
<option value="{{ resource_dropdown['id'] }}">{{ resource_dropdown['name'] }}</option>
{% if resource_dropdown in links %}
<option value="{{ resource_dropdown['id'] }}" selected>{{ resource_dropdown['name'] }}</option>
{% else %}
<option value="{{ resource_dropdown['id'] }}">{{ resource_dropdown['name'] }}</option>
{% endif %}
{% endif %}
{% endfor %}
</select>

+ 8
- 6
web/app/tool.py Ver fichero

@@ -66,13 +66,15 @@ def edit_tool(tool_id):
db.session.commit()
if linked_resource:
for linked_resource in request.form.getlist('linked_resources'):
first_resource_id = tool_id
second_resource_id = linked_resource
new_relationship = Relationship(first_resource_id=first_resource_id, second_resource_id=second_resource_id)
link = Resource.query.get(linked_resource)
if link not in links:
first_resource_id = tool_id
second_resource_id = linked_resource
new_relationship = Relationship(first_resource_id=first_resource_id, second_resource_id=second_resource_id)

# add the new relationship to the database
db.session.add(new_relationship)
db.session.commit()
# add the new relationship to the database
db.session.add(new_relationship)
db.session.commit()
return redirect(url_for('tool.get_tools'))

return render_template('edit.html', resource=tool, resource_dropdown=resource_dropdown, links=links)

Cargando…
Cancelar
Guardar