|
|
@@ -10,27 +10,12 @@ |
|
|
|
from flask import Blueprint, render_template, request, flash, redirect, url_for |
|
|
|
from flask_login import login_required, current_user |
|
|
|
from .models import Resource |
|
|
|
from .models import Relationships |
|
|
|
from .resources import * |
|
|
|
from werkzeug.exceptions import abort |
|
|
|
from . import db |
|
|
|
|
|
|
|
tool = Blueprint('tool', __name__) |
|
|
|
|
|
|
|
# function to retrieve data about a single tool from the database |
|
|
|
def get_tool(tool_id): |
|
|
|
tool = Resource.query.filter_by(id=tool_id).first() |
|
|
|
if tool is None: |
|
|
|
abort(404) |
|
|
|
return tool |
|
|
|
|
|
|
|
# function to retrieve linked resources |
|
|
|
def get_linked_resources(tool_id): |
|
|
|
relationships = Relationships.query.filter_by(first_resource_id=tool_id).first() |
|
|
|
if relationships: |
|
|
|
resource_id = relationships.second_resource_id |
|
|
|
resources = Resource.query.filter_by(id=resource_id).all() |
|
|
|
return resources |
|
|
|
|
|
|
|
# route for displaying all tools in database |
|
|
|
@tool.route('/tools') |
|
|
|
def get_tools(): |
|
|
@@ -40,7 +25,7 @@ def get_tools(): |
|
|
|
# route for displaying a single tool based on the ID in the database |
|
|
|
@tool.route('/tools/<int:tool_id>') |
|
|
|
def show_tool(tool_id): |
|
|
|
tool = get_tool(tool_id) |
|
|
|
tool = get_resource(tool_id) |
|
|
|
resources = get_linked_resources(tool_id) |
|
|
|
return render_template('tool.html', tool=tool, resources=resources) |
|
|
|
|
|
|
@@ -48,7 +33,7 @@ def show_tool(tool_id): |
|
|
|
@tool.route('/tools/<int:tool_id>/edit', methods=('GET', 'POST')) |
|
|
|
@login_required |
|
|
|
def edit_tool(tool_id): |
|
|
|
tool = get_tool(tool_id) |
|
|
|
tool = get_resource(tool_id) |
|
|
|
|
|
|
|
if request.method == 'POST': |
|
|
|
name = request.form['name'] |
|
|
@@ -60,14 +45,14 @@ def edit_tool(tool_id): |
|
|
|
tool = Resource.query.get(tool_id) |
|
|
|
tool.name = name |
|
|
|
tool.description = description |
|
|
|
tool.projectUrl = project_url |
|
|
|
tool.repositoryUrl = repository_url |
|
|
|
tool.dependencies = dependencies |
|
|
|
tool.expertiseToUse = expertise |
|
|
|
tool.expertiseToHost = self_host_expertise |
|
|
|
tool.ingestFormats = ingest |
|
|
|
tool.outputFormats = output |
|
|
|
tool.status = status |
|
|
|
# tool.projectUrl = project_url |
|
|
|
# tool.repositoryUrl = repository_url |
|
|
|
# tool.dependencies = dependencies |
|
|
|
# tool.expertiseToUse = expertise |
|
|
|
# tool.expertiseToHost = self_host_expertise |
|
|
|
# tool.ingestFormats = ingest |
|
|
|
# tool.outputFormats = output |
|
|
|
# tool.status = status |
|
|
|
db.session.commit() |
|
|
|
return redirect(url_for('tool.get_tools')) |
|
|
|
|
|
|
@@ -77,9 +62,5 @@ def edit_tool(tool_id): |
|
|
|
@tool.route('/tools/<int:tool_id>/delete', methods=('POST',)) |
|
|
|
@login_required |
|
|
|
def delete_tool(tool_id): |
|
|
|
tool = get_tool(tool_id) |
|
|
|
deletion = Resource.query.get(tool_id) |
|
|
|
db.session.delete(deletion) |
|
|
|
db.session.commit() |
|
|
|
flash('Successfully deleted!') |
|
|
|
delete_resource(tool_id) |
|
|
|
return redirect(url_for('tool.get_tools')) |