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.2KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from django.conf.urls.defaults 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 subclass
  12. """
  13. return patterns('')
  14. def post_process_urls(self, urlpatterns):
  15. """
  16. Customise URL patterns.
  17. By default, this only allows custom decorators to be specified, but you
  18. could override this method to do anything you want.
  19. """
  20. for pattern in urlpatterns:
  21. # Look for a custom decorator
  22. decorator = self.get_url_decorator(pattern)
  23. if decorator:
  24. # Nasty way of modifying a RegexURLPattern
  25. pattern._callback = decorator(pattern._callback)
  26. return urlpatterns
  27. def get_url_decorator(self, url_name):
  28. return None
  29. @property
  30. def urls(self):
  31. # We set the application and instance namespace here
  32. return self.get_urls(), self.app_name, self.name