Browse Source

finishing off relationship deletion function

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

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

practice.description = description practice.description = description
db.session.commit() db.session.commit()
if linked_resources: if linked_resources:
for linked_resource in request.form.getlist('linked_resources'):
for linked_resource in linked_resources:
link = Resource.query.get(linked_resource) link = Resource.query.get(linked_resource)
if link not in links:
if links and link not in links:
add_linked_resource(practice_id, linked_resource)
elif not links:
add_linked_resource(practice_id, linked_resource) add_linked_resource(practice_id, linked_resource)
return redirect(url_for('practice.get_practices')) return redirect(url_for('practice.get_practices'))



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



# function to delete a single relationship # function to delete a single relationship
def delete_relationship(first_resource_id, second_resource_id): def delete_relationship(first_resource_id, second_resource_id):
relation = Relationship.query.filter_by(first_resource_id=first_resource_id).first()
relation = Relationship.query.filter((Relationship.first_resource_id == first_resource_id) & (Relationship.second_resource_id == second_resource_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'] != 'practice' %} {% if resource_dropdown['type'] != 'practice' %}
{% 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