Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

application.py 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. from django.conf.urls import patterns
  2. from oscar.core.loading import feature_hidden
  3. class Application(object):
  4. name = None
  5. hidable_feature_name = None
  6. def __init__(self, app_name=None, **kwargs):
  7. self.app_name = app_name
  8. # Set all kwargs as object attributes
  9. for key, value in kwargs.iteritems():
  10. setattr(self, key, value)
  11. def get_urls(self):
  12. """
  13. Return the url patterns for this app, MUST be implemented in the
  14. subclass
  15. """
  16. return patterns('')
  17. def post_process_urls(self, urlpatterns):
  18. """
  19. Customise URL patterns.
  20. By default, this only allows custom decorators to be specified, but you
  21. could override this method to do anything you want.
  22. """
  23. # Test if this the URLs in the Application instance should be
  24. # available. If the feature is hidden then we don't include the URLs.
  25. if feature_hidden(self.hidable_feature_name):
  26. return patterns('')
  27. for pattern in urlpatterns:
  28. if hasattr(pattern, 'url_patterns'):
  29. self.post_process_urls(pattern.url_patterns)
  30. if not hasattr(pattern, '_callback'):
  31. continue
  32. # Look for a custom decorator
  33. decorator = self.get_url_decorator(pattern)
  34. if decorator:
  35. # Nasty way of modifying a RegexURLPattern
  36. pattern._callback = decorator(pattern._callback)
  37. return urlpatterns
  38. def get_url_decorator(self, url_name):
  39. """
  40. Return the appropriate decorator for the view function with the passed
  41. URL name
  42. """
  43. return None
  44. @property
  45. def urls(self):
  46. # We set the application and instance namespace here
  47. return self.get_urls(), self.app_name, self.name