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.

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