Pārlūkot izejas kodu

moved some duplicate code to its own function

joel
Simon Bowie pirms 2 gadiem
vecāks
revīzija
5266a31de3
3 mainītis faili ar 17 papildinājumiem un 20 dzēšanām
  1. +2
    -10
      web/app/practice.py
  2. +13
    -0
      web/app/relationships.py
  3. +2
    -10
      web/app/tool.py

+ 2
- 10
web/app/practice.py Parādīt failu

@@ -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)

+ 13
- 0
web/app/relationships.py Parādīt failu

@@ -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)

+ 2
- 10
web/app/tool.py Parādīt failu

@@ -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)

Notiek ielāde…
Atcelt
Saglabāt