@@ -49,16 +49,8 @@ def edit_practice(practice_id): | |||
linked_resources = request.form.getlist('linked_resources') | |||
remove_linked_resources = request.form.getlist('remove_linked_resources') | |||
if linked_resources: | |||
for linked_resource in linked_resources: | |||
link = Resource.query.get(linked_resource) | |||
if existing_relationships and link not in existing_relationships: | |||
add_relationship(practice_id, linked_resource) | |||
elif not existing_relationships: | |||
add_relationship(practice_id, linked_resource) | |||
if remove_linked_resources: | |||
for remove_linked_resource in remove_linked_resources: | |||
delete_relationship(practice_id, remove_linked_resource) | |||
edit_relationships(practice_id, linked_resources, remove_linked_resources, existing_relationships) | |||
return redirect(url_for('practice.get_practices',_external=True,_scheme=os.environ.get('SSL_SCHEME'))) | |||
return render_template('edit.html', resource=practice, resource_dropdown=resource_dropdown, links=existing_relationships) |
@@ -51,3 +51,16 @@ def delete_relationship(main_id, for_deletion_id): | |||
deletion = Relationship.query.get(relation.id) | |||
db.session.delete(deletion) | |||
db.session.commit() | |||
# logic for editing relationships | |||
def edit_relationships(resource_id, linked_resources, remove_linked_resources, existing_relationships): | |||
if linked_resources: | |||
for linked_resource in linked_resources: | |||
link = Resource.query.get(linked_resource) | |||
if existing_relationships and link not in existing_relationships: | |||
add_relationship(resource_id, linked_resource) | |||
elif not existing_relationships: | |||
add_relationship(resource_id, linked_resource) | |||
if remove_linked_resources: | |||
for remove_linked_resource in remove_linked_resources: | |||
delete_relationship(resource_id, remove_linked_resource) |
@@ -61,16 +61,8 @@ def edit_tool(tool_id): | |||
linked_resources = request.form.getlist('linked_resources') | |||
remove_linked_resources = request.form.getlist('remove_linked_resources') | |||
if linked_resources: | |||
for linked_resource in linked_resources: | |||
link = Resource.query.get(linked_resource) | |||
if existing_relationships and link not in existing_relationships: | |||
add_relationship(tool_id, linked_resource) | |||
elif not existing_relationships: | |||
add_relationship(tool_id, linked_resource) | |||
if remove_linked_resources: | |||
for remove_linked_resource in remove_linked_resources: | |||
delete_relationship(tool_id, remove_linked_resource) | |||
edit_relationships(tool_id, linked_resources, remove_linked_resources, existing_relationships) | |||
return redirect(url_for('tool.get_tools',_external=True,_scheme=os.environ.get('SSL_SCHEME'))) | |||
return render_template('edit.html', resource=tool, resource_dropdown=resource_dropdown, links=existing_relationships) |