|
-
-
-
-
-
-
-
-
-
- from flask import Blueprint, render_template, request, flash, redirect, url_for
- from flask_login import login_required, current_user
- from .models import Tool
- from .models import Example
- from .models import Practice
- from werkzeug.exceptions import abort
- from . import db
-
- 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':
- name = request.form.get('name')
- description = request.form.get('description')
- project_url = request.form.get('project_url')
- repository_url = request.form.get('repository_url')
- platform_status = request.form.get('platform_status')
- expertise = request.form.get('expertise')
- self_host_expertise = request.form.get('self_host_expertise')
- ingest = request.form.get('ingest')
- output = request.form.get('output')
- saas = request.form.get('saas')
- dependencies = request.form.get('dependencies')
-
- if not name:
- flash('Name is required!')
- else:
- tool = Tool.query.filter_by(name=name).first()
-
- if tool:
- flash('Tool with same name already exists')
- return redirect(url_for('create.create'))
-
-
- new_tool = Tool(name=name, description=description, project_url=project_url, repository_url=repository_url, platform_status=platform_status, expertise=expertise, self_host_expertise=self_host_expertise, ingest=ingest, output=output, saas=saas, dependencies=dependencies)
-
-
- db.session.add(new_tool)
- db.session.commit()
-
- elif request.form.get('resource_type') == 'example':
- name = request.form.get('name')
- description = request.form.get('description')
-
- if not name:
- flash('Name is required!')
- else:
- example = Example.query.filter_by(name=name).first()
-
- if example:
- flash('Example with same name already exists')
- return redirect(url_for('create.create'))
-
-
- new_example = Example(name=name, description=description)
-
-
- db.session.add(new_example)
- db.session.commit()
-
- elif request.form.get('resource_type') == 'practice':
- name = request.form.get('name')
- description = request.form.get('description')
-
- if not name:
- flash('Name is required!')
- else:
- practice = Practice.query.filter_by(name=name).first()
-
- if practice:
- flash('Practice with same name already exists')
- return redirect(url_for('create.create'))
-
-
- new_practice = Practice(name=name, description=description)
-
-
- db.session.add(new_practice)
- db.session.commit()
-
- return render_template('create.html')
|