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

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