瀏覽代碼

WIP: adding linked resources to edit pages

joel
Simon Bowie 2 年之前
父節點
當前提交
4fc7473b82
共有 6 個文件被更改,包括 36 次插入9 次删除
  1. +2
    -2
      web/app/create.py
  2. +0
    -1
      web/app/static/js/main.js
  3. +2
    -0
      web/app/templates/base.html
  4. +6
    -5
      web/app/templates/create.html
  5. +13
    -0
      web/app/templates/edit.html
  6. +13
    -1
      web/app/tool.py

+ 2
- 2
web/app/create.py 查看文件

db.session.add(new_reference) db.session.add(new_reference)
db.session.commit() db.session.commit()


practice_dropdown = Resource.query.filter_by(type='practice')
return render_template('create.html', practice_dropdown=practice_dropdown)
resource_dropdown = Resource.query
return render_template('create.html', resource_dropdown=resource_dropdown)

+ 0
- 1
web/app/static/js/main.js 查看文件

# @author: Simon Bowie <ad7588@coventry.ac.uk> # @author: Simon Bowie <ad7588@coventry.ac.uk>
# @purpose: JavaScript functions for various functions # @purpose: JavaScript functions for various functions
# @acknowledgements: # @acknowledgements:
# https://stackoverflow.com/questions/67942546/bootstrap-5-select-dropdown-with-the-multiple-attribute-collapsed
*/ */


// Dynamic HTML forms based on dropdown menu // Dynamic HTML forms based on dropdown menu

+ 2
- 0
web/app/templates/base.html 查看文件

# https://www.digitalocean.com/community/tutorials/how-to-make-a-web-application-using-flask-in-python-3 # https://www.digitalocean.com/community/tutorials/how-to-make-a-web-application-using-flask-in-python-3
# Bootstrap 5.1.3: https://getbootstrap.com/ # Bootstrap 5.1.3: https://getbootstrap.com/
# Flask-Moment: https://flask-moment.readthedocs.io/en/latest/ # Flask-Moment: https://flask-moment.readthedocs.io/en/latest/
# Boostrap select: https://stackoverflow.com/questions/67942546/bootstrap-5-select-dropdown-with-the-multiple-attribute-collapsed

--> -->


<!DOCTYPE html> <!DOCTYPE html>

+ 6
- 5
web/app/templates/create.html 查看文件



<div class="mb-3 mt-3"> <div class="mb-3 mt-3">
<label for="linked_practice_id">Linked resources</label> <label for="linked_practice_id">Linked resources</label>
<!--<select class="form-select" aria-label="Linked practices" name="linked_practice_id" multiple="multiple" id="linked_practice_id">-->
</div>
<div class="mb-3 mt-3">
<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>
<optgroup label="Practices">
{% for practice_dropdown in practice_dropdown %}
<option value="{{ practice_dropdown['id'] }}">{{ practice_dropdown['name'] }}</option>
{% for resource_dropdown in resource_dropdown %}
{% if resource_dropdown['type'] != 'tool' %}
<option value="{{ resource_dropdown['id'] }}">{{ resource_dropdown['name'] }}</option>
{% endif %}
{% endfor %} {% endfor %}
</optgroup>
</select> </select>
</div> </div>
</div> </div>

+ 13
- 0
web/app/templates/edit.html 查看文件

value="{{ request.form['status'] or resource['status'] }}"> value="{{ request.form['status'] or resource['status'] }}">
</input> </input>
</div> </div>
<div class="mb-3 mt-3">
<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>
{% endif %}
{% endfor %}
</select>
</div>
{% endif %} {% endif %}


<div class="mb-3 mt-3"> <div class="mb-3 mt-3">

+ 13
- 1
web/app/tool.py 查看文件

@login_required @login_required
def edit_tool(tool_id): def edit_tool(tool_id):
tool = get_resource(tool_id) tool = get_resource(tool_id)
resource_dropdown = Resource.query
links = get_linked_resources(tool_id)


if request.method == 'POST': if request.method == 'POST':
name = request.form['name'] name = request.form['name']
ingestFormats = request.form['ingestFormats'] ingestFormats = request.form['ingestFormats']
outputFormats = request.form['outputFormats'] outputFormats = request.form['outputFormats']
status = request.form['status'] status = request.form['status']
linked_resource = request.form.getlist('linked_resources')


if not name: if not name:
flash('Name is required!') flash('Name is required!')
tool.outputFormats = outputFormats tool.outputFormats = outputFormats
tool.status = status tool.status = status
db.session.commit() 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)

# 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)
return render_template('edit.html', resource=tool, resource_dropdown=resource_dropdown, links=links)


# route for function to delete a single tool from the edit page # route for function to delete a single tool from the edit page
@tool.route('/tools/<int:tool_id>/delete', methods=('POST',)) @tool.route('/tools/<int:tool_id>/delete', methods=('POST',))

Loading…
取消
儲存