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 814B

12345678910111213141516171819202122232425262728293031323334
  1. # -*- coding: utf-8 -*-
  2. import re
  3. from .controllers import *
  4. from .urls import urls
  5. from ..main import root_url
  6. from lodel.context import LodelContext
  7. LodelContext.expose_modules(globals(), {
  8. 'lodel.settings': ['Settings']})
  9. def format_url_rule(url_rule):
  10. if url_rule.startswith('^'):
  11. res = url_rule.replace('^', '^'+root_url())
  12. else:
  13. res = root_url()+'.*'+url_rule
  14. return res
  15. def get_controller(request):
  16. url_rules = []
  17. for url in urls:
  18. url_rules.append((format_url_rule(url[0]), url[1]))
  19. # Returning the right controller to call
  20. for regex, callback in url_rules:
  21. p = re.compile(regex)
  22. m = p.search(request.PATH)
  23. if m is not None:
  24. request.url_args = m.groupdict()
  25. return callback
  26. return not_found