ingestFormats = request.form.get('ingestFormats') | ingestFormats = request.form.get('ingestFormats') | ||||
outputFormats = request.form.get('outputFormats') | outputFormats = request.form.get('outputFormats') | ||||
status = request.form.get('status') | status = request.form.get('status') | ||||
practice_id = request.form.get('linked_practice_id') | |||||
if not name: | if not name: | ||||
flash('Name is required!') | flash('Name is required!') | ||||
return redirect(url_for('create.create_resource')) | return redirect(url_for('create.create_resource')) | ||||
# create a new tool with the form data | # create a new tool with the form data | ||||
new_tool = Tool(name=name, description=description, projectUrl=projectUrl, repositoryUrl=repositoryUrl, expertiseToUse=expertiseToUse, expertiseToHost=expertiseToHost, dependencies=dependencies, ingestFormats=ingestFormats, outputFormats=outputFormats, status=status) | |||||
new_tool = Tool(name=name, description=description, projectUrl=projectUrl, repositoryUrl=repositoryUrl, expertiseToUse=expertiseToUse, expertiseToHost=expertiseToHost, dependencies=dependencies, ingestFormats=ingestFormats, outputFormats=outputFormats, status=status, practice_id=practice_id) | |||||
# add the new tool to the database | # add the new tool to the database | ||||
db.session.add(new_tool) | db.session.add(new_tool) | ||||
db.session.add(new_reference) | db.session.add(new_reference) | ||||
db.session.commit() | db.session.commit() | ||||
return render_template('create.html') | |||||
practice_dropdown = Practice.query | |||||
return render_template('create.html', practice_dropdown=practice_dropdown) |
<label for="status">Platform status</label> | <label for="status">Platform status</label> | ||||
<input class="form-control" type="text" name="status" placeholder="Platform status" autofocus=""> | <input class="form-control" type="text" name="status" placeholder="Platform status" autofocus=""> | ||||
</div> | </div> | ||||
<div class="mb-3 mt-3"> | |||||
<label for="linked_practice_id">Linked practices</label> | |||||
<select class="form-select" aria-label="Linked practices" name="linked_practice_id"> | |||||
<option selected>Select a linked practice</option> | |||||
{% for practice_dropdown in practice_dropdown %} | |||||
<option value="{{ practice_dropdown['id'] }}">{{ practice_dropdown['name'] }}</option> | |||||
{% endfor %} | |||||
</select> | |||||
</div> | |||||
</div> | </div> | ||||
<div id="resource_type_practice" class="resource_type_input" style="display: none;"> | <div id="resource_type_practice" class="resource_type_input" style="display: none;"> | ||||
<div class="mb-3 mt-3"> | <div class="mb-3 mt-3"> |
<div class="row"> | <div class="row"> | ||||
{% for practice in practices %} | {% for practice in practices %} | ||||
<div class="col-md-4 col-sm-6 py-3"> | <div class="col-md-4 col-sm-6 py-3"> | ||||
<div class="card"> | |||||
<div class="card-header"> | |||||
<div class="card text-dark bg-warning mb-3"> | |||||
<div class="card-body"> | |||||
<a href="{{ url_for('practice.show_practice', practice_id=practice['id']) }}"> | <a href="{{ url_for('practice.show_practice', practice_id=practice['id']) }}"> | ||||
<h2 class="card-title">{{ practice['name'] }}</h2> | |||||
<h3 class="card-title text-center text-dark">{{ practice['name'] }}</h3> | |||||
</a> | </a> | ||||
</div> | |||||
<div class="card-body"> | |||||
<p class="card-text"> | <p class="card-text"> | ||||
{{ practice['description']|truncate(100) }} | {{ practice['description']|truncate(100) }} | ||||
</p> | </p> | ||||
<span class="badge bg-secondary">{{ practice['created'].strftime("%Y-%m-%d %H:%M") }} UTC</span> | |||||
{% if current_user.is_authenticated %} | {% if current_user.is_authenticated %} | ||||
<a href="{{ url_for('practice.edit_practice', practice_id=practice['id']) }}"> | <a href="{{ url_for('practice.edit_practice', practice_id=practice['id']) }}"> | ||||
<span class="badge bg-dark">Edit</span> | <span class="badge bg-dark">Edit</span> |
</table> | </table> | ||||
</div> | </div> | ||||
</div> | </div> | ||||
<div class="row"> | |||||
<div class="col"> | |||||
<h2 class="text-center">Linked practices:</h2> | |||||
</div> | |||||
</div> | |||||
<div class="row"> | |||||
<div class="col-md-4 col-sm-6 py-3"> | |||||
<div class="card text-dark bg-warning mb-3"> | |||||
<div class="card-body"> | |||||
<a href="{{ url_for('practice.show_practice', practice_id=practice['id']) }}"> | |||||
<h3 class="card-title text-center text-dark">{{ practice['name'] }}</h3> | |||||
</a> | |||||
<p class="card-text"> | |||||
{{ practice['description']|truncate(100) }} | |||||
</p> | |||||
</div> | |||||
</div> | |||||
</div> | |||||
</div> | |||||
{% endblock %} | {% endblock %} |
from flask import Blueprint, render_template, request, flash, redirect, url_for | from flask import Blueprint, render_template, request, flash, redirect, url_for | ||||
from flask_login import login_required, current_user | from flask_login import login_required, current_user | ||||
from .models import Tool | from .models import Tool | ||||
from .models import Practice | |||||
from werkzeug.exceptions import abort | from werkzeug.exceptions import abort | ||||
from . import db | from . import db | ||||
abort(404) | abort(404) | ||||
return tool | return tool | ||||
# function to retrieve linked practices | |||||
def get_practice(practice_id): | |||||
practice = Practice.query.filter_by(id=practice_id).first() | |||||
return practice | |||||
# route for displaying all tools in database | # route for displaying all tools in database | ||||
@tool.route('/tools') | @tool.route('/tools') | ||||
def get_tools(): | def get_tools(): | ||||
@tool.route('/tools/<int:tool_id>') | @tool.route('/tools/<int:tool_id>') | ||||
def show_tool(tool_id): | def show_tool(tool_id): | ||||
tool = get_tool(tool_id) | tool = get_tool(tool_id) | ||||
return render_template('tool.html', tool=tool) | |||||
practice = get_practice(tool.practice_id) | |||||
return render_template('tool.html', tool=tool, practice=practice) | |||||
# route for editing a single tool based on the ID in the database | # route for editing a single tool based on the ID in the database | ||||
@tool.route('/tools/<int:tool_id>/edit', methods=('GET', 'POST')) | @tool.route('/tools/<int:tool_id>/edit', methods=('GET', 'POST')) | ||||
tool.ingestFormats = ingest | tool.ingestFormats = ingest | ||||
tool.outputFormats = output | tool.outputFormats = output | ||||
tool.status = status | tool.status = status | ||||
tool.practice_id = practice_id | |||||
db.session.commit() | db.session.commit() | ||||
return redirect(url_for('tool.get_tools')) | return redirect(url_for('tool.get_tools')) | ||||