Selaa lähdekoodia

fixed create route

joel
Simon Bowie 3 vuotta sitten
vanhempi
commit
b79c4c77d7
2 muutettua tiedostoa jossa 32 lisäystä ja 27 poistoa
  1. +20
    -15
      web/app/create.py
  2. +12
    -12
      web/app/templates/create.html

+ 20
- 15
web/app/create.py Näytä tiedosto

@@ -10,8 +10,13 @@
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 Book
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 . import db

@@ -23,7 +28,7 @@ create = Blueprint('create', __name__)
def create_resource():
if request.method == 'POST':
if request.form.get('resource_type') == 'tool':
name = request.form.get('name')
name = request.form.get('tool_name')
description = request.form.get('description')
projectUrl = request.form.get('projectUrl')
repositoryUrl = request.form.get('repositoryUrl')
@@ -41,7 +46,7 @@ def create_resource():

if tool: # if a tool is found, we want to redirect back to create page
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
new_tool = Tool(name=name, description=description, projectUrl=projectUrl, repositoryUrl=repositoryUrl, expertiseToUse=expertiseToUse, expertiseToHost=expertiseToHost, dependencies=dependencies, ingestFormats=ingestFormats, outputFormats=outputFormats, status=status)
@@ -51,7 +56,7 @@ def create_resource():
db.session.commit()

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

if not name:
@@ -61,7 +66,7 @@ def create_resource():

if practice: # if a practice is found, we want to redirect back to create page
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
new_practice = Practice(name=name, description=description)
@@ -71,17 +76,17 @@ def create_resource():
db.session.commit()

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

if not name:
flash('Name is required!')
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
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
new_sensitivity = Sensitivity(name=name, description=description)
@@ -91,7 +96,7 @@ def create_resource():
db.session.commit()

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

if not name:
@@ -101,7 +106,7 @@ def create_resource():

if typology: # if a typology is found, we want to redirect back to create page
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
new_typology = Typology(name=name, description=description)
@@ -111,7 +116,7 @@ def create_resource():
db.session.commit()

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

@@ -122,7 +127,7 @@ def create_resource():

if publisher: # if a publisher is found, we want to redirect back to create page
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
new_publisher = Publisher(name=name, description=description, publisherUrl=publisherUrl)
@@ -132,7 +137,7 @@ def create_resource():
db.session.commit()

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

if not name:
@@ -142,7 +147,7 @@ def create_resource():

if book: # if a book is found, we want to redirect back to create page
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
new_book = Book(name=name, description=description)
@@ -161,7 +166,7 @@ def create_resource():

if reference: # if a reference is found, we want to redirect back to create page
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
new_reference = Reference(zoteroUrl=zoteroUrl)

+ 12
- 12
web/app/templates/create.html Näytä tiedosto

@@ -20,8 +20,8 @@
</div>
<div id="resource_type_tool" class="resource_type_input" style="display: none;">
<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 class="mb-3 mt-3">
@@ -71,8 +71,8 @@
</div>
<div id="resource_type_practice" class="resource_type_input" style="display: none;">
<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 class="mb-3 mt-3">
@@ -82,8 +82,8 @@
</div>
<div id="resource_type_sensitivity" class="resource_type_input" style="display: none;">
<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 class="mb-3 mt-3">
@@ -93,8 +93,8 @@
</div>
<div id="resource_type_typology" class="resource_type_input" style="display: none;">
<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 class="mb-3 mt-3">
@@ -106,8 +106,8 @@
</div>
<div id="resource_type_publisher" class="resource_type_input" style="display: none;">
<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 class="mb-3 mt-3">
@@ -122,8 +122,8 @@
</div>
<div id="resource_type_book" class="resource_type_input" style="display: none;">
<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 class="mb-3 mt-3">

Loading…
Peruuta
Tallenna