소스 검색

adding deletion function to practices

joel
Simon Bowie 2 년 전
부모
커밋
06c9749ebd
3개의 변경된 파일7개의 추가작업 그리고 3개의 파일을 삭제
  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 파일 보기

@@ -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 파일 보기

@@ -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 파일 보기

@@ -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 %}

Loading…
취소
저장