class Resource(db.Model): | class Resource(db.Model): | ||||
__tablename__ = 'Resource' | __tablename__ = 'Resource' | ||||
# all resource types | |||||
id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy | id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy | ||||
created = db.Column(db.DateTime, default=datetime.utcnow) | created = db.Column(db.DateTime, default=datetime.utcnow) | ||||
type = db.Column(db.Text) | type = db.Column(db.Text) | ||||
name = db.Column(db.Text) | name = db.Column(db.Text) | ||||
description = db.Column(db.Text) | description = db.Column(db.Text) | ||||
# tools | |||||
developer = db.Column(db.Text) | developer = db.Column(db.Text) | ||||
developerUrl = db.Column(db.Text) | developerUrl = db.Column(db.Text) | ||||
projectUrl = db.Column(db.Text) | projectUrl = db.Column(db.Text) | ||||
ingestFormats = db.Column(db.Text) | ingestFormats = db.Column(db.Text) | ||||
outputFormats = db.Column(db.Text) | outputFormats = db.Column(db.Text) | ||||
status = db.Column(db.Text) | status = db.Column(db.Text) | ||||
publisherUrl = db.Column(db.Text) | |||||
zoteroUrl = db.Column(db.Text) | |||||
# practices | |||||
experimental = db.Column(db.Text) | |||||
lessonsLearned = db.Column(db.Text) | |||||
references = db.Column(db.Text) | |||||
# books | |||||
isbn = db.Column(db.Text) | |||||
# table for relationships | # table for relationships | ||||
class Relationship(db.Model): | class Relationship(db.Model): |
practice = Resource.query.get(practice_id) | practice = Resource.query.get(practice_id) | ||||
practice.name = request.form['name'] | practice.name = request.form['name'] | ||||
practice.description = request.form['description'] | practice.description = request.form['description'] | ||||
practice.experimental = request.form['experimental'] | |||||
practice.lessonsLearned = request.form['lessonsLearned'] | |||||
practice.references = request.form['references'] | |||||
db.session.commit() | db.session.commit() | ||||
linked_resources = request.form.getlist('linked_resources') | linked_resources = request.form.getlist('linked_resources') | ||||
remove_linked_resources = request.form.getlist('remove_linked_resources') | remove_linked_resources = request.form.getlist('remove_linked_resources') |
</div> | </div> | ||||
{% elif resource['type'] == 'practice' %} | {% elif resource['type'] == 'practice' %} | ||||
<div class="mb-3 mt-3"> | |||||
<label for="experimental">How is this / Can this be an experimental practice?</label> | |||||
<textarea name="experimental" placeholder="How is this / Can this be an experimental practice?" | |||||
class="form-control">{{ request.form['experimental'] or resource['experimental'] }}</textarea> | |||||
</div> | |||||
<div class="mb-3 mt-3"> | |||||
<label for="lessonsLearned">How has it been applied experimentally (lessons learned for authors and publishers)?</label> | |||||
<textarea name="lessonsLearned" placeholder="How has it been applied experimentally (lessons learned for authors and publishers)?" | |||||
class="form-control">{{ request.form['lessonsLearned'] or resource['lessonsLearned'] }}</textarea> | |||||
</div> | |||||
<div class="mb-3 mt-3"> | |||||
<label for="references">References</label> | |||||
<textarea name="references" placeholder="References" | |||||
class="form-control">{{ request.form['references'] or resource['references'] }}</textarea> | |||||
</div> | |||||
<div class="mb-3 mt-3"> | <div class="mb-3 mt-3"> | ||||
<label for="linked_practice_id">Linked resources</label> | <label for="linked_practice_id">Linked resources</label> | ||||
</div> | </div> |
</td> | </td> | ||||
</tr> | </tr> | ||||
{% endif %} | {% endif %} | ||||
<!-- fields for tools --> | |||||
{% if resource['developer'] %} | {% if resource['developer'] %} | ||||
<tr> | <tr> | ||||
<th> | <th> | ||||
</td> | </td> | ||||
</tr> | </tr> | ||||
{% endif %} | {% endif %} | ||||
<!-- fields for practices --> | |||||
{% if resource['experimental'] %} | |||||
<tr> | |||||
<th> | |||||
How is this / Can this be an experimental practice? | |||||
</th> | |||||
<td> | |||||
{{ resource['experimental'] }} | |||||
</td> | |||||
</tr> | |||||
{% endif %} | |||||
{% if resource['lessonsLearned'] %} | |||||
<tr> | |||||
<th> | |||||
How has it been applied experimentally (lessons learned for authors and publishers)? | |||||
</th> | |||||
<td> | |||||
<p style="white-space: pre-line">{{ resource['lessonsLearned'] }}</p> | |||||
</td> | |||||
</tr> | |||||
{% endif %} | |||||
{% if resource['references'] %} | |||||
<tr> | |||||
<th> | |||||
References: | |||||
</th> | |||||
<td> | |||||
<p style="white-space: pre-line">{{ resource['references'] }}</p> | |||||
</td> | |||||
</tr> | |||||
{% endif %} | |||||
</tbody> | </tbody> | ||||
</table> | </table> | ||||
</div> | </div> |
tools = db.engine.execute(query) | tools = db.engine.execute(query) | ||||
elif key == 'scriptingLanguage': | elif key == 'scriptingLanguage': | ||||
regex = request.args.get(key) + "$|" + request.args.get(key) + "\s\/" | regex = request.args.get(key) + "$|" + request.args.get(key) + "\s\/" | ||||
tools = Resource.query.filter(Resource.scriptingLanguage.regexp_match(regex)) | |||||
tools = Resource.query.filter_by(type='tool').filter(Resource.scriptingLanguage.regexp_match(regex)) | |||||
else: | else: | ||||
kwargs = {'type': 'tool', key: request.args.get(key)} | kwargs = {'type': 'tool', key: request.args.get(key)} | ||||
tools = Resource.query.filter_by(**kwargs) | tools = Resource.query.filter_by(**kwargs) |