|
-
-
-
-
-
-
-
-
- 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 Relationship
- from .resources import *
- from .relationships import *
- from . import db
- import os
-
- create = Blueprint('create', __name__)
-
-
- @create.route('/create', methods=('GET', 'POST'))
- @login_required
- def create_resource():
- if request.method == 'POST':
- if request.form.get('resource_type') == 'tool':
- type = 'tool'
- name = request.form.get('tool_name')
- description = request.form.get('description')
- developer = request.form.get('developer')
- developerUrl = request.form.get('developerUrl')
- projectUrl = request.form.get('projectUrl')
- repositoryUrl = request.form.get('repositoryUrl')
- license = request.form.get('license')
- scriptingLanguage = request.form.get('scriptingLanguage')
- expertiseToUse = request.form.get('expertiseToUse')
- expertiseToHost = request.form.get('expertiseToHost')
- dependencies = request.form.get('dependencies')
- ingestFormats = request.form.get('ingestFormats')
- outputFormats = request.form.get('outputFormats')
- status = request.form.get('status')
-
- if not name:
- flash('Name is required!')
- else:
- tool = Resource.query.filter_by(type='tool').filter_by(name=name).first()
-
- if tool:
- flash('Tool with same name already exists')
- return redirect(url_for('create.create_resource',_external=True,_scheme=os.environ.get('SSL_SCHEME')))
-
-
- new_tool = Resource(type=type, name=name, description=description, developer=developer, developerUrl=developerUrl, projectUrl=projectUrl, repositoryUrl=repositoryUrl, license=license, scriptingLanguage=scriptingLanguage, expertiseToUse=expertiseToUse, expertiseToHost=expertiseToHost, dependencies=dependencies, ingestFormats=ingestFormats, outputFormats=outputFormats, status=status)
-
-
- db.session.add(new_tool)
- db.session.commit()
-
- if request.form.getlist('linked_resources'):
- for linked_resource in request.form.getlist('linked_resources'):
- tool = Resource.query.filter_by(type='tool').filter_by(name=name).first()
- add_relationship(tool.id, linked_resource)
-
- elif request.form.get('resource_type') == 'practice':
- type = 'practice'
- name = request.form.get('practice_name')
- description = request.form.get('description')
-
- if not name:
- flash('Name is required!')
- else:
- practice = Resource.query.filter_by(type='practice').filter_by(name=name).first()
-
- if practice:
- flash('Practice with same name already exists')
- return redirect(url_for('create.create_resource',_external=True,_scheme=os.environ.get('SSL_SCHEME')))
-
-
- new_practice = Resource(type=type, name=name, description=description)
-
-
- db.session.add(new_practice)
- db.session.commit()
-
- elif request.form.get('resource_type') == 'book':
- type = 'book'
- name = request.form.get('book_name')
- description = request.form.get('description')
-
- if not name:
- flash('Name is required!')
- else:
- book = Book.query.filter_by(name=name).first()
-
- if book:
- flash('Book with same name already exists')
- return redirect(url_for('create.create_resource',_external=True,_scheme=os.environ.get('SSL_SCHEME')))
-
-
- new_book = Resource(type=type, name=name, description=description)
-
-
- db.session.add(new_book)
- db.session.commit()
-
- resource_dropdown = Resource.query
- return render_template('create.html', resource_dropdown=resource_dropdown)
|