if request.form.get('resource_type') == 'tool': | if request.form.get('resource_type') == 'tool': | ||||
name = request.form.get('name') | name = request.form.get('name') | ||||
description = request.form.get('description') | 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') | |||||
projectUrl = request.form.get('projectUrl') | |||||
repositoryUrl = request.form.get('repositoryUrl') | |||||
expertiseToUse = request.form.get('expertiseToUse') | |||||
expertiseToHost = request.form.get('expertiseToHost') | |||||
dependencies = request.form.get('dependencies') | dependencies = request.form.get('dependencies') | ||||
ingestFormats = request.form.get('ingestFormats') | |||||
outputFormats = request.form.get('outputFormats') | |||||
status = request.form.get('status') | |||||
if not name: | if not name: | ||||
flash('Name is required!') | flash('Name is required!') | ||||
return redirect(url_for('create.create')) | return redirect(url_for('create.create')) | ||||
# create a new tool with the form data | # create a new tool with the form data | ||||
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) | |||||
new_tool = Tool(name=name, description=description, projectUrl=projectUrl, repositoryUrl=repositoryUrl, expertiseToUse=expertiseToUse, expertiseToHost=expertiseToHost, dependencies=dependencies, ingestFormats=ingestFormats, outputFormats=outputFormats, status=status) | |||||
# add the new tool to the database | # add the new tool to the database | ||||
db.session.add(new_tool) | db.session.add(new_tool) | ||||
db.session.commit() | 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 this returns a practice, then the name already exists in database | |||||
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')) | |||||
# create a new practice with the form data | |||||
new_practice = Practice(name=name, description=description) | |||||
# add the new practice to the database | |||||
db.session.add(new_practice) | |||||
db.session.commit() | |||||
elif request.form.get('resource_type') == 'sensitivity': | |||||
name = request.form.get('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 | |||||
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')) | |||||
# create a new sensitivity with the form data | |||||
new_sensitivity = Sensitivity(name=name, description=description) | |||||
# add the new sensitivity to the database | |||||
db.session.add(new_sensitivity) | |||||
db.session.commit() | |||||
elif request.form.get('resource_type') == 'typology': | |||||
name = request.form.get('name') | |||||
description = request.form.get('description') | |||||
if not name: | |||||
flash('Name is required!') | |||||
else: | |||||
typology = Typology.query.filter_by(name=name).first() # if this returns a typology, then the name already exists in database | |||||
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')) | |||||
# create a new typology with the form data | |||||
new_typology = Typology(name=name, description=description) | |||||
# add the new typology to the database | |||||
db.session.add(new_typology) | |||||
db.session.commit() | |||||
elif request.form.get('resource_type') == 'publisher': | |||||
name = request.form.get('name') | |||||
description = request.form.get('description') | |||||
publisherUrl = request.form.get('publisherUrl') | |||||
if not name: | |||||
flash('Name is required!') | |||||
else: | |||||
publisher = Publisher.query.filter_by(name=name).first() # if this returns a publisher, then the name already exists in database | |||||
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')) | |||||
# create a new publisher with the form data | |||||
new_publisher = Publisher(name=name, description=description, publisherUrl=publisherUrl) | |||||
# add the new publisher to the database | |||||
db.session.add(new_publisher) | |||||
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('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: | ||||
example = Book.query.filter_by(name=name).first() # if this returns a book, then the name already exists in database | |||||
book = Book.query.filter_by(name=name).first() # if this returns a book, then the name already exists in database | |||||
if example: # 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')) | ||||
db.session.add(new_book) | db.session.add(new_book) | ||||
db.session.commit() | db.session.commit() | ||||
elif request.form.get('resource_type') == 'practice': | |||||
name = request.form.get('name') | |||||
description = request.form.get('description') | |||||
elif request.form.get('resource_type') == 'reference': | |||||
zoteroUrl = request.form.get('zoteroUrl') | |||||
if not name: | |||||
flash('Name is required!') | |||||
if not zoteroUrl: | |||||
flash('Zotero URL is required!') | |||||
else: | else: | ||||
practice = Practice.query.filter_by(name=name).first() # if this returns a practice, then the name already exists in database | |||||
reference = Reference.query.filter_by(zoteroUrl=zoteroUrl).first() # if this returns a reference, then the name already exists in database | |||||
if practice: # if a practice is found, we want to redirect back to create page | |||||
flash('Practice with same name already exists') | |||||
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')) | ||||
# create a new practice with the form data | |||||
new_practice = Practice(name=name, description=description) | |||||
# create a new reference with the form data | |||||
new_reference = Reference(zoteroUrl=zoteroUrl) | |||||
# add the new practice to the database | |||||
db.session.add(new_practice) | |||||
# add the new reference to the database | |||||
db.session.add(new_reference) | |||||
db.session.commit() | db.session.commit() | ||||
return render_template('create.html') | return render_template('create.html') |
{% extends 'base.html' %} | {% extends 'base.html' %} | ||||
{% block content %} | {% block content %} | ||||
<h1>{% block title %} Add a New Tool, Example, or Practice {% endblock %}</h1> | |||||
<h1>{% block title %} Add a New Resource{% endblock %}</h1> | |||||
<form method="POST" action="/create" id="resource"> | <form method="POST" action="/create" id="resource"> | ||||
<div class="mb-3 mt-3"> | <div class="mb-3 mt-3"> | ||||
<label for="type">Type</label> | <label for="type">Type</label> | ||||
<select class="form-select" id="resource_type" name="resource_type" form="resource"> | <select class="form-select" id="resource_type" name="resource_type" form="resource"> | ||||
<option selected="selected">Please choose</option> | <option selected="selected">Please choose</option> | ||||
<option value="tool">Tool</option> | <option value="tool">Tool</option> | ||||
<option value="example">Example</option> | |||||
<option value="practice">Practice</option> | <option value="practice">Practice</option> | ||||
<option value="sensitivity">Sensitivity</option> | |||||
<option value="typology">Typology</option> | |||||
<option value="workflow">Workflow</option> | |||||
<option value="publisher">Publisher</option> | |||||
<option value="book">Book</option> | |||||
<option value="reference">Reference</option> | |||||
</select> | </select> | ||||
</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> | </div> | ||||
<div class="mb-3 mt-3"> | <div class="mb-3 mt-3"> | ||||
<label for="project_url">Project URL</label> | |||||
<input class="form-control" type="text" name="project_url" placeholder="Project URL" autofocus=""> | |||||
<label for="projectUrl">Project URL</label> | |||||
<input class="form-control" type="text" name="projectUrl" placeholder="Project URL" autofocus=""> | |||||
</div> | </div> | ||||
<div class="mb-3 mt-3"> | <div class="mb-3 mt-3"> | ||||
<label for="repository_url">Repository URL</label> | |||||
<input class="form-control" type="text" name="repository_url" placeholder="Repository URL" autofocus=""> | |||||
<label for="repositoryUrl">Repository URL</label> | |||||
<input class="form-control" type="text" name="repositoryUrl" placeholder="Repository URL" autofocus=""> | |||||
</div> | </div> | ||||
<div class="mb-3 mt-3"> | <div class="mb-3 mt-3"> | ||||
<label for="platform_status">Stand-alone or platform?</label> | |||||
<input class="form-control" type="text" name="platform_status" placeholder="Stand-alone or platform?" autofocus=""> | |||||
<label for="expertiseToUse">Expertise required to use</label> | |||||
<input class="form-control" type="text" name="expertiseToUse" placeholder="Expertise required to use" autofocus=""> | |||||
</div> | </div> | ||||
<div class="mb-3 mt-3"> | <div class="mb-3 mt-3"> | ||||
<label for="expertise">Expertise required</label> | |||||
<input class="form-control" type="text" name="expertise" placeholder="Expertise required" autofocus=""> | |||||
<label for="expertiseToHost">Expertise required to self-host</label> | |||||
<input class="form-control" type="text" name="expertiseToHost" placeholder="Expertise required to self-host" autofocus=""> | |||||
</div> | </div> | ||||
<div class="mb-3 mt-3"> | <div class="mb-3 mt-3"> | ||||
<label for="self_host_expertise">Expertise required to self-host</label> | |||||
<input class="form-control" type="text" name="self_host_expertise" placeholder="Expertise required to self-host" autofocus=""> | |||||
<label for="dependencies">Technical dependencies</label> | |||||
<input class="form-control" type="text" name="dependencies" placeholder="Technical dependencies" autofocus=""> | |||||
</div> | </div> | ||||
<div class="mb-3 mt-3"> | <div class="mb-3 mt-3"> | ||||
<label for="ingest">Import / ingest</label> | |||||
<input class="form-control" type="text" name="ingest" placeholder="Import / ingest" autofocus=""> | |||||
<label for="ingestFormats">Import / ingest formats</label> | |||||
<input class="form-control" type="text" name="ingestFormats" placeholder="Import / ingest formats" autofocus=""> | |||||
</div> | </div> | ||||
<div class="mb-3 mt-3"> | <div class="mb-3 mt-3"> | ||||
<label for="output">Output formats</label> | |||||
<input class="form-control" type="text" name="output" placeholder="Output formats" autofocus=""> | |||||
<label for="outputFormats">Output formats</label> | |||||
<input class="form-control" type="text" name="outputFormats" placeholder="Output formats" autofocus=""> | |||||
</div> | </div> | ||||
<div class="mb-3 mt-3"> | <div class="mb-3 mt-3"> | ||||
<label for="saas">SAAS?</label> | |||||
<input class="form-control" type="text" name="saas" placeholder="SAAS?" autofocus=""> | |||||
<label for="status">Platform status</label> | |||||
<input class="form-control" type="text" name="status" placeholder="Platform status" autofocus=""> | |||||
</div> | |||||
</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=""> | |||||
</div> | </div> | ||||
<div class="mb-3 mt-3"> | <div class="mb-3 mt-3"> | ||||
<label for="dependencies">Technical dependencies</label> | |||||
<input class="form-control" type="text" name="dependencies" placeholder="Technical dependencies" autofocus=""> | |||||
<label for="description">Practice description</label> | |||||
<textarea class="form-control" rows="4" type="text" name="description" placeholder="Practice description" autofocus=""></textarea> | |||||
</div> | </div> | ||||
</div> | </div> | ||||
<div id="resource_type_example" 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">Example name</label> | |||||
<input class="form-control" type="text" name="name" placeholder="Example name" autofocus=""> | |||||
<label for="name">Sensitivity name</label> | |||||
<input class="form-control" type="text" name="name" placeholder="Sensitivity name" autofocus=""> | |||||
</div> | </div> | ||||
<div class="mb-3 mt-3"> | <div class="mb-3 mt-3"> | ||||
<label for="description">Example description</label> | |||||
<textarea class="form-control" rows="4" type="text" name="description" placeholder="Example description" autofocus=""></textarea> | |||||
<label for="description">Sensitivity description</label> | |||||
<textarea class="form-control" rows="4" type="text" name="description" placeholder="Sensitivity description" autofocus=""></textarea> | |||||
</div> | </div> | ||||
</div> | </div> | ||||
<div id="resource_type_practice" 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">Practice name</label> | |||||
<input class="form-control" type="text" name="name" placeholder="Practice name" autofocus=""> | |||||
<label for="name">Typology name</label> | |||||
<input class="form-control" type="text" name="name" placeholder="Typology name" autofocus=""> | |||||
</div> | </div> | ||||
<div class="mb-3 mt-3"> | <div class="mb-3 mt-3"> | ||||
<label for="description">Practice description</label> | |||||
<textarea class="form-control" rows="4" type="text" name="description" placeholder="Practice description" autofocus=""></textarea> | |||||
<label for="description">Typology description</label> | |||||
<textarea class="form-control" rows="4" type="text" name="description" placeholder="Typology description" autofocus=""></textarea> | |||||
</div> | </div> | ||||
</div> | </div> | ||||
<div id="resource_type_workflow" class="resource_type_input" style="display: none;"> | |||||
</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=""> | |||||
</div> | |||||
<div class="mb-3 mt-3"> | |||||
<label for="description">Publisher description</label> | |||||
<textarea class="form-control" rows="4" type="text" name="description" placeholder="Publisher description" autofocus=""></textarea> | |||||
</div> | |||||
<div class="mb-3 mt-3"> | |||||
<label for="publisherUrl">Publisher URL</label> | |||||
<input class="form-control" type="text" name="publisherUrl" placeholder="Publisher URL" autofocus=""> | |||||
</div> | |||||
</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=""> | |||||
</div> | |||||
<div class="mb-3 mt-3"> | |||||
<label for="description">Book description</label> | |||||
<textarea class="form-control" rows="4" type="text" name="description" placeholder="Book description" autofocus=""></textarea> | |||||
</div> | |||||
</div> | |||||
<div id="resource_type_reference" class="resource_type_input" style="display: none;"> | |||||
<div class="mb-3 mt-3"> | |||||
<label for="zoteroUrl">Zotero URL</label> | |||||
<input class="form-control" type="text" name="zoteroUrl" placeholder="Zotero URL" autofocus=""> | |||||
</div> | |||||
</div> | |||||
<button type="submit" class="btn btn-primary mb-3">Submit</button> | <button type="submit" class="btn btn-primary mb-3">Submit</button> | ||||
</form> | </form> | ||||
{% endblock %} | {% endblock %} |