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.

60 satır
2.0KB

  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. # render Markdown as HTML
  29. for resource in curated:
  30. resource.description = markdown.markdown(resource.description)
  31. with open('content/home.md', 'r') as f:
  32. text = f.read()
  33. text = markdown.markdown(text)
  34. return render_template('index.html', text=text, resources=curated, view=view)
  35. # route for profile page
  36. @main.route('/profile')
  37. @login_required
  38. def profile():
  39. return render_template('profile.html', name=current_user.name)
  40. # route for test page
  41. @main.route('/test')
  42. def test():
  43. return render_template('test.html')
  44. # route for about page
  45. @main.route('/about')
  46. def about():
  47. with open('content/about.md', 'r') as f:
  48. about_text = f.read()
  49. about_text = markdown.markdown(about_text)
  50. with open('content/colophon.md', 'r') as f:
  51. colophon_text = f.read()
  52. colophon_text = markdown.markdown(colophon_text)
  53. return render_template('about.html', about_text=about_text, colophon_text=colophon_text)