Преглед изворни кода

WIP: adding deletions of relationships to edit pages

joel
Simon Bowie пре 2 година
родитељ
комит
448d1f6692
3 измењених фајлова са 12 додато и 11 уклоњено
  1. +5
    -6
      web/app/resources.py
  2. +1
    -1
      web/app/templates/edit.html
  3. +6
    -4
      web/app/tool.py

+ 5
- 6
web/app/resources.py Прегледај датотеку

@@ -61,9 +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):
#relationship_id = Relationship.query.filter_by(first_resource_id=first_resource_id).first()
#return relationship_id['id']
#deletion = Relationship.query.get(relationship_id)
#db.session.delete(deletion)
#db.session.commit()
def delete_relationship(first_resource_id, second_resource_id):
relation = Relationship.query.filter_by(first_resource_id=first_resource_id).first()
deletion = Relationship.query.get(relation.id)
db.session.delete(deletion)
db.session.commit()

+ 1
- 1
web/app/templates/edit.html Прегледај датотеку

@@ -82,7 +82,7 @@
<select name="linked_resources" id="linked_resources" aria-label="Linked resources" class="selectpicker" data-live-search="true" multiple>
{% for resource_dropdown in resource_dropdown %}
{% if resource_dropdown['type'] != 'tool' %}
{% if resource_dropdown in links %}
{% if links and resource_dropdown in links %}
<option value="{{ resource_dropdown['id'] }}" selected>{{ resource_dropdown['name'] }}</option>
{% else %}
<option value="{{ resource_dropdown['id'] }}">{{ resource_dropdown['name'] }}</option>

+ 6
- 4
web/app/tool.py Прегледај датотеку

@@ -68,11 +68,13 @@ def edit_tool(tool_id):
if linked_resources:
for linked_resource in linked_resources:
link = Resource.query.get(linked_resource)
if link not in links:
if links and link not in links:
add_linked_resource(tool_id, linked_resource)
#if remove_linked_resources:
# for remove_linked_resource in remove_linked_resources:
# delete_relationship(tool_id, remove_linked_resource)
elif not links:
add_linked_resource(tool_id, linked_resource)
if remove_linked_resources:
for remove_linked_resource in remove_linked_resources:
delete_relationship(tool_id, remove_linked_resource)
return redirect(url_for('tool.get_tools'))

return render_template('edit.html', resource=tool, resource_dropdown=resource_dropdown, links=links)

Loading…
Откажи
Сачувај