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.

application.py 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 hasattr(pattern, 'url_patterns'):
  23. self.post_process_urls(pattern.url_patterns)
  24. if not hasattr(pattern, '_callback'):
  25. continue
  26. # Look for a custom decorator
  27. decorator = self.get_url_decorator(pattern)
  28. if decorator:
  29. # Nasty way of modifying a RegexURLPattern
  30. pattern._callback = decorator(pattern._callback)
  31. return urlpatterns
  32. def get_url_decorator(self, url_name):
  33. return None
  34. @property
  35. def urls(self):
  36. # We set the application and instance namespace here
  37. return self.get_urls(), self.app_name, self.name