Browse Source

fixed create route

joel
Simon Bowie 3 years ago
parent
commit
b79c4c77d7
2 changed files with 32 additions and 27 deletions
  1. +20
    -15
      web/app/create.py
  2. +12
    -12
      web/app/templates/create.html

+ 20
- 15
web/app/create.py View File

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 Book
from .models import Practice from .models import Practice
from .models import Sensitivity
from .models import Typology
from .models import Workflow
from .models import Publisher
from .models import Book
from .models import Reference
from werkzeug.exceptions import abort from werkzeug.exceptions import abort
from . import db from . import db


def create_resource(): def create_resource():
if request.method == 'POST': if request.method == 'POST':
if request.form.get('resource_type') == 'tool': if request.form.get('resource_type') == 'tool':
name = request.form.get('name')
name = request.form.get('tool_name')
description = request.form.get('description') description = request.form.get('description')
projectUrl = request.form.get('projectUrl') projectUrl = request.form.get('projectUrl')
repositoryUrl = request.form.get('repositoryUrl') repositoryUrl = request.form.get('repositoryUrl')


if tool: # if a tool is found, we want to redirect back to create page if tool: # if a tool is found, we want to redirect back to create page
flash('Tool with same name already exists') flash('Tool with same name already exists')
return redirect(url_for('create.create'))
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)
db.session.commit() db.session.commit()


elif request.form.get('resource_type') == 'practice': elif request.form.get('resource_type') == 'practice':
name = request.form.get('name')
name = request.form.get('practice_name')
description = request.form.get('description') description = request.form.get('description')


if not name: if not name:


if practice: # if a practice is found, we want to redirect back to create page if practice: # if a practice is found, we want to redirect back to create page
flash('Practice with same name already exists') flash('Practice with same name already exists')
return redirect(url_for('create.create'))
return redirect(url_for('create.create_resource'))


# create a new practice with the form data # create a new practice with the form data
new_practice = Practice(name=name, description=description) new_practice = Practice(name=name, description=description)
db.session.commit() db.session.commit()


elif request.form.get('resource_type') == 'sensitivity': elif request.form.get('resource_type') == 'sensitivity':
name = request.form.get('name')
name = request.form.get('sensitivity_name')
description = request.form.get('description') description = request.form.get('description')


if not name: if not name:
flash('Name is required!') flash('Name is required!')
else: else:
sensitivity = Sensitivty.query.filter_by(name=name).first() # if this returns a sensitivity, then the name already exists in database
sensitivity = Sensitivity.query.filter_by(name=name).first() # if this returns a sensitivity, then the name already exists in database


if sensitivity: # if a sensitivity is found, we want to redirect back to create page if sensitivity: # if a sensitivity is found, we want to redirect back to create page
flash('Sensitivity with same name already exists') flash('Sensitivity with same name already exists')
return redirect(url_for('create.create'))
return redirect(url_for('create.create_resource'))


# create a new sensitivity with the form data # create a new sensitivity with the form data
new_sensitivity = Sensitivity(name=name, description=description) new_sensitivity = Sensitivity(name=name, description=description)
db.session.commit() db.session.commit()


elif request.form.get('resource_type') == 'typology': elif request.form.get('resource_type') == 'typology':
name = request.form.get('name')
name = request.form.get('typology_name')
description = request.form.get('description') description = request.form.get('description')


if not name: if not name:


if typology: # if a typology is found, we want to redirect back to create page if typology: # if a typology is found, we want to redirect back to create page
flash('Typology with same name already exists') flash('Typology with same name already exists')
return redirect(url_for('create.create'))
return redirect(url_for('create.create_resource'))


# create a new typology with the form data # create a new typology with the form data
new_typology = Typology(name=name, description=description) new_typology = Typology(name=name, description=description)
db.session.commit() db.session.commit()


elif request.form.get('resource_type') == 'publisher': elif request.form.get('resource_type') == 'publisher':
name = request.form.get('name')
name = request.form.get('publisher_name')
description = request.form.get('description') description = request.form.get('description')
publisherUrl = request.form.get('publisherUrl') publisherUrl = request.form.get('publisherUrl')




if publisher: # if a publisher is found, we want to redirect back to create page if publisher: # if a publisher is found, we want to redirect back to create page
flash('Publisher with same name already exists') flash('Publisher with same name already exists')
return redirect(url_for('create.create'))
return redirect(url_for('create.create_resource'))


# create a new publisher with the form data # create a new publisher with the form data
new_publisher = Publisher(name=name, description=description, publisherUrl=publisherUrl) new_publisher = Publisher(name=name, description=description, publisherUrl=publisherUrl)
db.session.commit() db.session.commit()


elif request.form.get('resource_type') == 'book': elif request.form.get('resource_type') == 'book':
name = request.form.get('name')
name = request.form.get('book_name')
description = request.form.get('description') description = request.form.get('description')


if not name: if not name:


if book: # if a book is found, we want to redirect back to create page if book: # if a book is found, we want to redirect back to create page
flash('Book with same name already exists') flash('Book with same name already exists')
return redirect(url_for('create.create'))
return redirect(url_for('create.create_resource'))


# create a new book with the form data # create a new book with the form data
new_book = Book(name=name, description=description) new_book = Book(name=name, description=description)


if reference: # if a reference is found, we want to redirect back to create page if reference: # if a reference is found, we want to redirect back to create page
flash('Reference with same URL already exists') flash('Reference with same URL already exists')
return redirect(url_for('create.create'))
return redirect(url_for('create.create_resource'))


# create a new reference with the form data # create a new reference with the form data
new_reference = Reference(zoteroUrl=zoteroUrl) new_reference = Reference(zoteroUrl=zoteroUrl)

+ 12
- 12
web/app/templates/create.html View File

</div> </div>
<div id="resource_type_tool" class="resource_type_input" style="display: none;"> <div id="resource_type_tool" class="resource_type_input" style="display: none;">
<div class="mb-3 mt-3"> <div class="mb-3 mt-3">
<label for="name">Tool name</label>
<input class="form-control" type="text" name="name" placeholder="Tool name" autofocus="">
<label for="tool_name">Tool name</label>
<input class="form-control" type="text" name="tool_name" placeholder="Tool name" autofocus="">
</div> </div>


<div class="mb-3 mt-3"> <div class="mb-3 mt-3">
</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">
<label for="name">Practice name</label>
<input class="form-control" type="text" name="name" placeholder="Practice name" autofocus="">
<label for="practice_name">Practice name</label>
<input class="form-control" type="text" name="practice_name" placeholder="Practice name" autofocus="">
</div> </div>


<div class="mb-3 mt-3"> <div class="mb-3 mt-3">
</div> </div>
<div id="resource_type_sensitivity" class="resource_type_input" style="display: none;"> <div id="resource_type_sensitivity" class="resource_type_input" style="display: none;">
<div class="mb-3 mt-3"> <div class="mb-3 mt-3">
<label for="name">Sensitivity name</label>
<input class="form-control" type="text" name="name" placeholder="Sensitivity name" autofocus="">
<label for="sensitivity_name">Sensitivity name</label>
<input class="form-control" type="text" name="sensitivity_name" placeholder="Sensitivity name" autofocus="">
</div> </div>


<div class="mb-3 mt-3"> <div class="mb-3 mt-3">
</div> </div>
<div id="resource_type_typology" class="resource_type_input" style="display: none;"> <div id="resource_type_typology" class="resource_type_input" style="display: none;">
<div class="mb-3 mt-3"> <div class="mb-3 mt-3">
<label for="name">Typology name</label>
<input class="form-control" type="text" name="name" placeholder="Typology name" autofocus="">
<label for="typology_name">Typology name</label>
<input class="form-control" type="text" name="typology_name" placeholder="Typology name" autofocus="">
</div> </div>


<div class="mb-3 mt-3"> <div class="mb-3 mt-3">
</div> </div>
<div id="resource_type_publisher" class="resource_type_input" style="display: none;"> <div id="resource_type_publisher" class="resource_type_input" style="display: none;">
<div class="mb-3 mt-3"> <div class="mb-3 mt-3">
<label for="name">Publisher name</label>
<input class="form-control" type="text" name="name" placeholder="Publisher name" autofocus="">
<label for="publisher_name">Publisher name</label>
<input class="form-control" type="text" name="publisher_name" placeholder="Publisher name" autofocus="">
</div> </div>


<div class="mb-3 mt-3"> <div class="mb-3 mt-3">
</div> </div>
<div id="resource_type_book" class="resource_type_input" style="display: none;"> <div id="resource_type_book" class="resource_type_input" style="display: none;">
<div class="mb-3 mt-3"> <div class="mb-3 mt-3">
<label for="name">Book name</label>
<input class="form-control" type="text" name="name" placeholder="Book name" autofocus="">
<label for="book_name">Book name</label>
<input class="form-control" type="text" name="book_name" placeholder="Book name" autofocus="">
</div> </div>


<div class="mb-3 mt-3"> <div class="mb-3 mt-3">

Loading…
Cancel
Save