Browse Source

finishing adding linked resources to edit pages on tool path

joel
Simon Bowie 2 years ago
parent
commit
f786438f84
2 changed files with 13 additions and 8 deletions
  1. +5
    -2
      web/app/templates/edit.html
  2. +8
    -6
      web/app/tool.py

+ 5
- 2
web/app/templates/edit.html View File

<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>

+ 8
- 6
web/app/tool.py View File

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)

Loading…
Cancel
Save