Procházet zdrojové kódy

moved functions and resolved bug

joel
Simon Bowie před 1 rokem
rodič
revize
e4c3e17055
3 změnil soubory, kde provedl 34 přidání a 24 odebrání
  1. +1
    -0
      web/app/practice.py
  2. +30
    -0
      web/app/relationships.py
  3. +3
    -24
      web/app/resources.py

+ 1
- 0
web/app/practice.py Zobrazit soubor

@@ -26,6 +26,7 @@ def get_practices():
@practice.route('/practices/<int:practice_id>')
def show_practice(practice_id):
practice = get_full_resource(practice_id)
practice.references = replace_urls(practice.references)
return render_template('resource.html', resource=practice)

# route for editing a single practice based on the ID in the database

+ 30
- 0
web/app/relationships.py Zobrazit soubor

@@ -33,6 +33,36 @@ def get_relationships(primary_id):
links.extend(Resource.query.filter_by(id=primary_id).all())
return links

# function to append relationships to a resource object
def append_relationships(resource):
relationships = get_relationships(resource.id)
if relationships:
for relationship in relationships:
if relationship.type == 'tool':
if 'tools' not in resource.__dict__.keys():
resource.__dict__['tools'] = relationship
elif type(resource.__dict__['tools']) == list:
resource.__dict__['tools'].append(relationship)
else:
resource.__dict__['tools'] = [resource.__dict__['tools'], relationship]
elif relationship.type == 'practice':
if 'practices' not in resource.__dict__.keys():
resource.__dict__['practices'] = relationship
elif type(resource.__dict__['practices']) == list:
resource.__dict__['practices'].append(relationship)
else:
resource.__dict__['practices'] = [resource.__dict__['practices'], relationship]
elif relationship.type == 'book':
if 'books' not in resource.__dict__.keys():
resource.__dict__['books'] = relationship
elif type(resource.__dict__['books']) == list:
resource.__dict__['books'].append(relationship)
else:
resource.__dict__['books'] = [resource.__dict__['books'], relationship]
return resource
else:
return resource

# function to add a relationship to a linked resource
def add_relationship(resource_id, linked_resource_id):
first_resource_id = resource_id

+ 3
- 24
web/app/resources.py Zobrazit soubor

@@ -26,32 +26,11 @@ def get_resource(resource_id):
# function to retrieve data about a resource and its relationships
def get_full_resource(resource_id):
resource = get_resource(resource_id)
relationships = get_relationships(resource_id)
for relationship in relationships:
if relationship.type == 'tool':
if 'tools' not in resource.__dict__.keys():
resource.__dict__['tools'] = relationship
elif type(resource.__dict__['tools']) == list:
resource.__dict__['tools'].append(relationship)
else:
resource.__dict__['tools'] = [resource.__dict__['tools'], relationship]
elif relationship.type == 'practice':
if 'practices' not in resource.__dict__.keys():
resource.__dict__['practices'] = relationship
elif type(resource.__dict__['practices']) == list:
resource.__dict__['practices'].append(relationship)
else:
resource.__dict__['practices'] = [resource.__dict__['practices'], relationship]
elif relationship.type == 'book':
if 'books' not in resource.__dict__.keys():
resource.__dict__['books'] = relationship
elif type(resource.__dict__['books']) == list:
resource.__dict__['books'].append(relationship)
else:
resource.__dict__['books'] = [resource.__dict__['books'], relationship]
resource = append_relationships(resource)
if resource.type == 'book':
book_data = get_book_data(resource.isbn)
resource.__dict__.update(book_data)
if book_data:
resource.__dict__.update(book_data)
return resource

# function to delete a single resource

Načítá se…
Zrušit
Uložit