Bläddra i källkod

adding deletion function to practices

joel
Simon Bowie 2 år sedan
förälder
incheckning
06c9749ebd
3 ändrade filer med 7 tillägg och 3 borttagningar
  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 Visa fil

@@ -40,6 +40,7 @@ def edit_practice(practice_id):
name = request.form['name']
description = request.form['description']
linked_resources = request.form.getlist('linked_resources')
remove_linked_resources = request.form.getlist('remove_linked_resources')

if not name:
flash('Name is required!')
@@ -55,6 +56,9 @@ def edit_practice(practice_id):
add_linked_resource(practice_id, linked_resource)
elif not links:
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 render_template('edit.html', resource=practice, resource_dropdown=resource_dropdown, links=links)

+ 2
- 2
web/app/resources.py Visa fil

@@ -61,8 +61,8 @@ def delete_resource(resource_id):
flash('Successfully deleted!')

# 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)
db.session.delete(deletion)
db.session.commit()

+ 1
- 1
web/app/templates/edit.html Visa fil

@@ -83,7 +83,7 @@
{% for resource_dropdown in resource_dropdown %}
{% if resource_dropdown['type'] != 'tool' %}
{% 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 %}
<option value="{{ resource_dropdown['id'] }}">{{ resource_dropdown['name'] }}</option>
{% endif %}

Laddar…
Avbryt
Spara