您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

application.py 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from django.conf.urls import patterns
  2. class Application(object):
  3. name = None
  4. def __init__(self, app_name=None, **kwargs):
  5. self.app_name = app_name
  6. # Set all kwargs as object attributes
  7. for key, value in kwargs.iteritems():
  8. setattr(self, key, value)
  9. def get_urls(self):
  10. """
  11. Return the url patterns for this app, MUST be implemented in the
  12. subclass
  13. """
  14. return patterns('')
  15. def post_process_urls(self, urlpatterns):
  16. """
  17. Customise URL patterns.
  18. By default, this only allows custom decorators to be specified, but you
  19. could override this method to do anything you want.
  20. """
  21. for pattern in urlpatterns:
  22. if not hasattr(pattern, '_callback'):
  23. continue
  24. # Look for a custom decorator
  25. decorator = self.get_url_decorator(pattern)
  26. if decorator:
  27. # Nasty way of modifying a RegexURLPattern
  28. pattern._callback = decorator(pattern._callback)
  29. return urlpatterns
  30. def get_url_decorator(self, url_name):
  31. return None
  32. @property
  33. def urls(self):
  34. # We set the application and instance namespace here
  35. return self.get_urls(), self.app_name, self.name