linked_resources = request.form.getlist('linked_resources') | linked_resources = request.form.getlist('linked_resources') | ||||
remove_linked_resources = request.form.getlist('remove_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 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) | return render_template('edit.html', resource=practice, resource_dropdown=resource_dropdown, links=existing_relationships) |
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() | ||||
# 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) |
linked_resources = request.form.getlist('linked_resources') | linked_resources = request.form.getlist('linked_resources') | ||||
remove_linked_resources = request.form.getlist('remove_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 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) | return render_template('edit.html', resource=tool, resource_dropdown=resource_dropdown, links=existing_relationships) |