urls.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. """
  2. This is the main ``urlconf`` for Mezzanine - it sets up patterns for
  3. all the various Mezzanine apps, third-party apps like Grappelli and
  4. filebrowser.
  5. """
  6. from __future__ import unicode_literals
  7. from future.builtins import str
  8. from django.conf.urls import include, url
  9. from django.contrib.sitemaps.views import sitemap
  10. from django.views.i18n import javascript_catalog
  11. from django.http import HttpResponse
  12. from mezzanine.conf import settings
  13. from mezzanine.core.sitemaps import DisplayableSitemap
  14. urlpatterns = []
  15. # JavaScript localization feature
  16. js_info_dict = {'domain': 'django'}
  17. urlpatterns += [
  18. url(r'^jsi18n/(?P<packages>\S+?)/$', javascript_catalog, js_info_dict),
  19. ]
  20. if settings.DEBUG and "debug_toolbar" in settings.INSTALLED_APPS:
  21. try:
  22. import debug_toolbar
  23. except ImportError:
  24. pass
  25. else:
  26. urlpatterns += [
  27. url(r'^__debug__/', include(debug_toolbar.urls)),
  28. ]
  29. # Django's sitemap app.
  30. if "django.contrib.sitemaps" in settings.INSTALLED_APPS:
  31. sitemaps = {"sitemaps": {"all": DisplayableSitemap}}
  32. urlpatterns += [
  33. url("^sitemap\.xml$", sitemap, sitemaps),
  34. ]
  35. # Return a robots.txt that disallows all spiders when DEBUG is True.
  36. if getattr(settings, "DEBUG", False):
  37. urlpatterns += [
  38. url("^robots.txt$",
  39. lambda r: HttpResponse("User-agent: *\nDisallow: /",
  40. content_type="text/plain")),
  41. ]
  42. # Miscellanous Mezzanine patterns.
  43. urlpatterns += [
  44. url("^", include("mezzanine.core.urls")),
  45. url("^", include("mezzanine.generic.urls")),
  46. # agregado
  47. url("^", include("encuesta.urls"),)
  48. ]
  49. # Mezzanine's Accounts app
  50. if "mezzanine.accounts" in settings.INSTALLED_APPS:
  51. # We don't define a URL prefix here such as /account/ since we want
  52. # to honour the LOGIN_* settings, which Django has prefixed with
  53. # /account/ by default. So those settings are used in accounts.urls
  54. urlpatterns += [
  55. url("^", include("mezzanine.accounts.urls")),
  56. ]
  57. # Mezzanine's Blog app.
  58. blog_installed = "mezzanine.blog" in settings.INSTALLED_APPS
  59. if blog_installed:
  60. BLOG_SLUG = settings.BLOG_SLUG.rstrip("/")
  61. if BLOG_SLUG:
  62. BLOG_SLUG += "/"
  63. blog_patterns = [
  64. url("^%s" % BLOG_SLUG, include("mezzanine.blog.urls")),
  65. ]
  66. urlpatterns += blog_patterns
  67. # Mezzanine's Pages app.
  68. PAGES_SLUG = ""
  69. if "mezzanine.pages" in settings.INSTALLED_APPS:
  70. # No BLOG_SLUG means catch-all patterns belong to the blog,
  71. # so give pages their own prefix and inject them before the
  72. # blog urlpatterns.
  73. if blog_installed and not BLOG_SLUG.rstrip("/"):
  74. PAGES_SLUG = getattr(settings, "PAGES_SLUG", "pages").strip("/") + "/"
  75. blog_patterns_start = urlpatterns.index(blog_patterns[0])
  76. urlpatterns[blog_patterns_start:len(blog_patterns)] = [
  77. url("^%s" % str(PAGES_SLUG), include("mezzanine.pages.urls")),
  78. ]
  79. else:
  80. urlpatterns += [
  81. url("^", include("mezzanine.pages.urls")),
  82. ]