瀏覽代碼

linking tools and practices

joel
Simon Bowie 2 年之前
父節點
當前提交
2b7ded1cb3
共有 5 個文件被更改,包括 47 次插入9 次删除
  1. +4
    -2
      web/app/create.py
  2. +10
    -0
      web/app/templates/create.html
  3. +3
    -6
      web/app/templates/practices.html
  4. +21
    -0
      web/app/templates/tool.html
  5. +9
    -1
      web/app/tool.py

+ 4
- 2
web/app/create.py 查看文件

@@ -38,6 +38,7 @@ def create_resource():
ingestFormats = request.form.get('ingestFormats')
outputFormats = request.form.get('outputFormats')
status = request.form.get('status')
practice_id = request.form.get('linked_practice_id')

if not name:
flash('Name is required!')
@@ -49,7 +50,7 @@ def create_resource():
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)
new_tool = Tool(name=name, description=description, projectUrl=projectUrl, repositoryUrl=repositoryUrl, expertiseToUse=expertiseToUse, expertiseToHost=expertiseToHost, dependencies=dependencies, ingestFormats=ingestFormats, outputFormats=outputFormats, status=status, practice_id=practice_id)

# add the new tool to the database
db.session.add(new_tool)
@@ -175,4 +176,5 @@ def create_resource():
db.session.add(new_reference)
db.session.commit()

return render_template('create.html')
practice_dropdown = Practice.query
return render_template('create.html', practice_dropdown=practice_dropdown)

+ 10
- 0
web/app/templates/create.html 查看文件

@@ -68,6 +68,16 @@
<label for="status">Platform status</label>
<input class="form-control" type="text" name="status" placeholder="Platform status" autofocus="">
</div>

<div class="mb-3 mt-3">
<label for="linked_practice_id">Linked practices</label>
<select class="form-select" aria-label="Linked practices" name="linked_practice_id">
<option selected>Select a linked practice</option>
{% for practice_dropdown in practice_dropdown %}
<option value="{{ practice_dropdown['id'] }}">{{ practice_dropdown['name'] }}</option>
{% endfor %}
</select>
</div>
</div>
<div id="resource_type_practice" class="resource_type_input" style="display: none;">
<div class="mb-3 mt-3">

+ 3
- 6
web/app/templates/practices.html 查看文件

@@ -16,17 +16,14 @@
<div class="row">
{% for practice in practices %}
<div class="col-md-4 col-sm-6 py-3">
<div class="card">
<div class="card-header">
<div class="card text-dark bg-warning mb-3">
<div class="card-body">
<a href="{{ url_for('practice.show_practice', practice_id=practice['id']) }}">
<h2 class="card-title">{{ practice['name'] }}</h2>
<h3 class="card-title text-center text-dark">{{ practice['name'] }}</h3>
</a>
</div>
<div class="card-body">
<p class="card-text">
{{ practice['description']|truncate(100) }}
</p>
<span class="badge bg-secondary">{{ practice['created'].strftime("%Y-%m-%d %H:%M") }} UTC</span>
{% if current_user.is_authenticated %}
<a href="{{ url_for('practice.edit_practice', practice_id=practice['id']) }}">
<span class="badge bg-dark">Edit</span>

+ 21
- 0
web/app/templates/tool.html 查看文件

@@ -101,4 +101,25 @@
</table>
</div>
</div>
<div class="row">
<div class="col">
<h2 class="text-center">Linked practices:</h2>
</div>
</div>
<div class="row">

<div class="col-md-4 col-sm-6 py-3">
<div class="card text-dark bg-warning mb-3">
<div class="card-body">
<a href="{{ url_for('practice.show_practice', practice_id=practice['id']) }}">
<h3 class="card-title text-center text-dark">{{ practice['name'] }}</h3>
</a>
<p class="card-text">
{{ practice['description']|truncate(100) }}
</p>
</div>
</div>
</div>

</div>
{% endblock %}

+ 9
- 1
web/app/tool.py 查看文件

@@ -10,6 +10,7 @@
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 Practice
from werkzeug.exceptions import abort
from . import db

@@ -22,6 +23,11 @@ def get_tool(tool_id):
abort(404)
return tool

# function to retrieve linked practices
def get_practice(practice_id):
practice = Practice.query.filter_by(id=practice_id).first()
return practice

# route for displaying all tools in database
@tool.route('/tools')
def get_tools():
@@ -32,7 +38,8 @@ def get_tools():
@tool.route('/tools/<int:tool_id>')
def show_tool(tool_id):
tool = get_tool(tool_id)
return render_template('tool.html', tool=tool)
practice = get_practice(tool.practice_id)
return render_template('tool.html', tool=tool, practice=practice)

# route for editing a single tool based on the ID in the database
@tool.route('/tools/<int:tool_id>/edit', methods=('GET', 'POST'))
@@ -58,6 +65,7 @@ def edit_tool(tool_id):
tool.ingestFormats = ingest
tool.outputFormats = output
tool.status = status
tool.practice_id = practice_id
db.session.commit()
return redirect(url_for('tool.get_tools'))


Loading…
取消
儲存