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.

3 yıl önce
3 yıl önce
3 yıl önce
1 yıl önce
1 yıl önce
3 yıl önce
3 yıl önce
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. main_text = f.read()
  49. main_text = markdown.markdown(main_text)
  50. with open('content/colophon.md', 'r') as f:
  51. sidebar_text = f.read()
  52. sidebar_text = markdown.markdown(sidebar_text)
  53. return render_template('about.html', main_text=main_text, sidebar_text=sidebar_text)
  54. # route for events page
  55. @main.route('/practice_seminars')
  56. @main.route('/expub_seminars')
  57. def events():
  58. with open('content/seminar.md', 'r') as f:
  59. main_text = f.read()
  60. main_text = markdown.markdown(main_text)
  61. with open('content/seminar_details.md', 'r') as f:
  62. sidebar_text = f.read()
  63. sidebar_text = markdown.markdown(sidebar_text)
  64. return render_template('about.html', main_text=main_text, sidebar_text=sidebar_text)