Browse Source

adding deletion function to practices

joel
Simon Bowie 2 years ago
parent
commit
06c9749ebd
3 changed files with 7 additions and 3 deletions
  1. +4
    -0
      web/app/practice.py
  2. +2
    -2
      web/app/resources.py
  3. +1
    -1
      web/app/templates/edit.html

+ 4
- 0
web/app/practice.py View File

name = request.form['name'] name = request.form['name']
description = request.form['description'] description = request.form['description']
linked_resources = request.form.getlist('linked_resources') linked_resources = request.form.getlist('linked_resources')
remove_linked_resources = request.form.getlist('remove_linked_resources')


if not name: if not name:
flash('Name is required!') flash('Name is required!')
add_linked_resource(practice_id, linked_resource) add_linked_resource(practice_id, linked_resource)
elif not links: elif not links:
add_linked_resource(practice_id, linked_resource) add_linked_resource(practice_id, linked_resource)
if remove_linked_resources:
for remove_linked_resource in remove_linked_resources:
delete_relationship(practice_id, remove_linked_resource)
return redirect(url_for('practice.get_practices')) return redirect(url_for('practice.get_practices'))


return render_template('edit.html', resource=practice, resource_dropdown=resource_dropdown, links=links) return render_template('edit.html', resource=practice, resource_dropdown=resource_dropdown, links=links)

+ 2
- 2
web/app/resources.py View File

flash('Successfully deleted!') flash('Successfully deleted!')


# function to delete a single relationship # function to delete a single relationship
def delete_relationship(first_resource_id, second_resource_id):
relation = Relationship.query.filter((Relationship.first_resource_id == first_resource_id) & (Relationship.second_resource_id == second_resource_id)).first()
def delete_relationship(main_id, for_deletion_id):
relation = Relationship.query.filter(((Relationship.first_resource_id == main_id) & (Relationship.second_resource_id == for_deletion_id)) | ((Relationship.first_resource_id == for_deletion_id) & (Relationship.second_resource_id == main_id))).first()
deletion = Relationship.query.get(relation.id) deletion = Relationship.query.get(relation.id)
db.session.delete(deletion) db.session.delete(deletion)
db.session.commit() db.session.commit()

+ 1
- 1
web/app/templates/edit.html View File

{% for resource_dropdown in resource_dropdown %} {% for resource_dropdown in resource_dropdown %}
{% if resource_dropdown['type'] != 'tool' %} {% if resource_dropdown['type'] != 'tool' %}
{% if links and resource_dropdown in links %} {% if links and resource_dropdown in links %}
<option value="{{ resource_dropdown['id'] }}" selected>{{ resource_dropdown['name'] }}</option>
<option value="" selected>{{ resource_dropdown['name'] }}</option>
{% else %} {% else %}
<option value="{{ resource_dropdown['id'] }}">{{ resource_dropdown['name'] }}</option> <option value="{{ resource_dropdown['id'] }}">{{ resource_dropdown['name'] }}</option>
{% endif %} {% endif %}

Loading…
Cancel
Save