You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.py 1.7KB

3 vuotta sitten
3 vuotta sitten
3 vuotta sitten
1 vuosi sitten
1 vuosi sitten
3 vuotta sitten
2 vuotta sitten
3 vuotta sitten
2 vuotta sitten
2 vuotta sitten
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # @name: main.py
  2. # @creation_date: 2021-10-20
  3. # @license: The MIT License <https://opensource.org/licenses/MIT>
  4. # @author: Simon Bowie <ad7588@coventry.ac.uk>
  5. # @purpose: Main route for index and other pages
  6. # @acknowledgements:
  7. # https://www.digitalocean.com/community/tutorials/how-to-add-authentication-to-your-app-with-flask-login
  8. from flask import Blueprint, render_template
  9. from flask_login import login_required, current_user
  10. from .models import Resource
  11. from .resources import *
  12. from .relationships import *
  13. from sqlalchemy.sql import func
  14. import markdown
  15. main = Blueprint('main', __name__)
  16. # route for index page
  17. @main.route('/')
  18. def index():
  19. view = request.args.get('view')
  20. # curated list of resources to display on homepage
  21. tool_ids = ['4','10', '34', '27']
  22. practice_ids = ['53', '59', '65', '56']
  23. book_ids = ['94', '72', '105', '67']
  24. # concatenate lists of resources
  25. resource_ids = tool_ids + practice_ids + book_ids
  26. # get data for curated resources
  27. curated = get_curated_resources(resource_ids)
  28. with open('content/home.md', 'r') as f:
  29. text = f.read()
  30. text = markdown.markdown(text)
  31. return render_template('index.html', text=text, resources=curated, view=view)
  32. # route for profile page
  33. @main.route('/profile')
  34. @login_required
  35. def profile():
  36. return render_template('profile.html', name=current_user.name)
  37. # route for test page
  38. @main.route('/test')
  39. def test():
  40. return render_template('test.html')
  41. # route for about page
  42. @main.route('/about')
  43. def about():
  44. with open('content/about.md', 'r') as f:
  45. text = f.read()
  46. text = markdown.markdown(text)
  47. return render_template('about.html', text=text)