<label for="linked_practice_id">Linked resources</label> | <label for="linked_practice_id">Linked resources</label> | ||||
</div> | </div> | ||||
<div class="mb-3 mt-3"> | <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> | <select name="linked_resources" id="linked_resources" aria-label="Linked resources" class="selectpicker" data-live-search="true" multiple> | ||||
{% for resource_dropdown in resource_dropdown %} | {% for resource_dropdown in resource_dropdown %} | ||||
{% if resource_dropdown['type'] != 'tool' %} | {% 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 %} | {% endif %} | ||||
{% endfor %} | {% endfor %} | ||||
</select> | </select> |
db.session.commit() | db.session.commit() | ||||
if linked_resource: | if linked_resource: | ||||
for linked_resource in request.form.getlist('linked_resources'): | 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 redirect(url_for('tool.get_tools')) | ||||
return render_template('edit.html', resource=tool, resource_dropdown=resource_dropdown, links=links) | return render_template('edit.html', resource=tool, resource_dropdown=resource_dropdown, links=links) |