Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

48 lines
1.5KB

  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. tools = Resource.query.filter_by(type='tool').order_by(func.random()).limit(6).all()
  20. with open('content/home.md', 'r') as f:
  21. text = f.read()
  22. text = markdown.markdown(text)
  23. book_showcase = get_book('69')
  24. book_showcase_relationships = get_relationships('69')
  25. return render_template('index.html', text=text, tools=tools, book=book_showcase, book_relationships=book_showcase_relationships)
  26. # route for profile page
  27. @main.route('/profile')
  28. @login_required
  29. def profile():
  30. return render_template('profile.html', name=current_user.name)
  31. # route for test page
  32. @main.route('/test')
  33. def test():
  34. return render_template('test.html')
  35. # route for about page
  36. @main.route('/about')
  37. def about():
  38. with open('content/about.md', 'r') as f:
  39. text = f.read()
  40. text = markdown.markdown(text)
  41. return render_template('about.html', text=text)