No Description
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.

router.py 787B

12345678910111213141516171819202122232425262728293031323334
  1. # -*- coding: utf-8 -*-
  2. import re
  3. from .controllers import *
  4. from .urls import urls
  5. from lodel.settings import Settings
  6. def format_url_rule(url_rule):
  7. if url_rule == '^$':
  8. return "^%s$" % Settings.sitename
  9. formatted_rule = ''
  10. if url_rule.startswith('^'):
  11. formatted_rule += "^"
  12. formatted_rule += "%s/%s" % (Settings.sitename, url_rule)
  13. return formatted_rule
  14. def get_controller(request):
  15. url_rules = []
  16. for url in urls:
  17. url_rules.append((format_url_rule(url[0]), url[1]))
  18. # Returning the right controller to call
  19. for regex, callback in url_rules:
  20. match = re.search(regex, request.PATH)
  21. if match is not None:
  22. request.url_args = match.groups()
  23. return callback
  24. return not_found