|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
-
-
-
-
-
-
-
-
- from flask import Blueprint, render_template, request, flash, redirect, url_for
- from flask_login import login_required, current_user
- from .models import Resource
- from .resources import *
- from .relationships import *
- from werkzeug.exceptions import abort
- from . import db
- import os
-
- tool = Blueprint('tool', __name__)
-
-
- @tool.route('/tools')
- def get_tools():
- tools = Resource.query.filter_by(type='tool')
- return render_template('resources.html', resources=tools, type='tool')
-
-
- @tool.route('/tools/<int:tool_id>')
- def show_tool(tool_id):
- tool = get_resource(tool_id)
- relationships = get_relationships(tool_id)
- return render_template('resource.html', resource=tool, relationships=relationships)
-
-
- @tool.route('/tools/<int:tool_id>/edit', methods=('GET', 'POST'))
- @login_required
- def edit_tool(tool_id):
- tool = get_resource(tool_id)
- resource_dropdown = Resource.query
- existing_relationships = get_relationships(tool_id)
-
- if request.method == 'POST':
- if not request.form['name']:
- flash('Name is required!')
- else:
- tool = Resource.query.get(tool_id)
- tool.name = request.form['name']
- tool.description = request.form['description']
- tool.developer = request.form['developer']
- tool.developerUrl = request.form['developerUrl']
- tool.projectUrl = request.form['projectUrl']
- tool.repositoryUrl = request.form['repositoryUrl']
- tool.license = request.form['license']
- tool.scriptingLanguage = request.form['scriptingLanguage']
- tool.expertiseToUse = request.form['expertiseToUse']
- tool.expertiseToHost = request.form['expertiseToHost']
- tool.dependencies = request.form['dependencies']
- tool.ingestFormats = request.form['ingestFormats']
- tool.outputFormats = request.form['outputFormats']
- tool.status = request.form['status']
- db.session.commit()
- linked_resources = request.form.getlist('linked_resources')
- remove_linked_resources = request.form.getlist('remove_linked_resources')
-
- edit_relationships(tool_id, linked_resources, remove_linked_resources, existing_relationships)
-
- return redirect(url_for('tool.get_tools',_external=True,_scheme=os.environ.get('SSL_SCHEME')))
-
- return render_template('edit.html', resource=tool, resource_dropdown=resource_dropdown, links=existing_relationships)
-
-
- @tool.route('/tools/<int:tool_id>/delete', methods=('POST',))
- @login_required
- def delete_tool(tool_id):
- delete_resource(tool_id)
- return redirect(url_for('tool.get_tools',_external=True,_scheme=os.environ.get('SSL_SCHEME')))
|