2009-10-21 06:20:38 +04:00
|
|
|
from django.conf import settings
|
2012-09-08 03:10:39 +04:00
|
|
|
from django.conf.urls import include, patterns, url
|
2010-01-02 00:32:21 +03:00
|
|
|
from django.contrib import admin
|
2010-01-27 23:24:35 +03:00
|
|
|
from django.shortcuts import redirect
|
2010-05-05 22:51:20 +04:00
|
|
|
from django.views.i18n import javascript_catalog
|
|
|
|
from django.views.decorators.cache import cache_page
|
2010-01-02 00:32:21 +03:00
|
|
|
|
2011-08-26 22:19:05 +04:00
|
|
|
from amo.urlresolvers import reverse
|
|
|
|
|
2011-02-19 03:27:02 +03:00
|
|
|
import blocklist.views
|
2010-08-26 19:50:05 +04:00
|
|
|
import versions.urls
|
|
|
|
|
2010-01-02 00:32:21 +03:00
|
|
|
admin.autodiscover()
|
2009-10-23 03:43:38 +04:00
|
|
|
|
2012-09-21 21:22:01 +04:00
|
|
|
handler403 = 'amo.views.handler403'
|
2010-02-05 04:51:14 +03:00
|
|
|
handler404 = 'amo.views.handler404'
|
|
|
|
handler500 = 'amo.views.handler500'
|
|
|
|
|
2011-11-02 20:21:31 +04:00
|
|
|
|
2009-10-21 03:29:27 +04:00
|
|
|
urlpatterns = patterns('',
|
2010-04-21 07:08:27 +04:00
|
|
|
# Discovery pane is first for undetectable efficiency wins.
|
|
|
|
('^discovery/', include('discovery.urls')),
|
|
|
|
|
2011-02-19 03:27:02 +03:00
|
|
|
# There are many more params but we only care about these three. The end is
|
|
|
|
# not anchored on purpose!
|
|
|
|
url('^blocklist/(?P<apiver>\d+)/(?P<app>[^/]+)/(?P<appver>[^/]+)/',
|
|
|
|
blocklist.views.blocklist, name='blocklist'),
|
2011-03-17 01:34:32 +03:00
|
|
|
('^blocked/', include('blocklist.urls')),
|
2011-02-19 03:27:02 +03:00
|
|
|
|
2012-02-18 03:17:57 +04:00
|
|
|
# AMO homepage or Marketplace Developer Hub? Choose your destiny.
|
2012-03-08 09:59:44 +04:00
|
|
|
url('^$', settings.HOME, name='home'),
|
2011-11-02 20:21:31 +04:00
|
|
|
|
2010-01-27 23:15:17 +03:00
|
|
|
# Add-ons.
|
|
|
|
('', include('addons.urls')),
|
|
|
|
|
2010-02-06 01:06:16 +03:00
|
|
|
# Browse pages.
|
|
|
|
('', include('browse.urls')),
|
|
|
|
|
2010-07-27 03:37:06 +04:00
|
|
|
# Tags.
|
|
|
|
('', include('tags.urls')),
|
|
|
|
|
2010-07-16 03:46:37 +04:00
|
|
|
# Collections.
|
|
|
|
('', include('bandwagon.urls')),
|
|
|
|
|
2011-03-08 03:13:29 +03:00
|
|
|
# Files
|
|
|
|
('^files/', include('files.urls')),
|
|
|
|
|
2010-08-26 19:50:05 +04:00
|
|
|
# Downloads.
|
|
|
|
('^downloads/', include(versions.urls.download_patterns)),
|
|
|
|
|
2010-02-17 18:18:32 +03:00
|
|
|
# Localizer Pages
|
|
|
|
('^localizers/', include('localizers.urls')),
|
|
|
|
|
2009-12-14 23:34:11 +03:00
|
|
|
# Users
|
2010-02-02 20:03:47 +03:00
|
|
|
('', include('users.urls')),
|
2009-10-21 06:20:38 +04:00
|
|
|
|
2010-09-07 05:19:48 +04:00
|
|
|
# Developer Hub.
|
2011-07-19 21:47:01 +04:00
|
|
|
('^developers/', include('devhub.urls')),
|
2010-09-07 05:19:48 +04:00
|
|
|
|
2010-12-30 22:31:49 +03:00
|
|
|
# Developer Hub.
|
|
|
|
('editors/', include('editors.urls')),
|
|
|
|
|
2009-12-31 01:26:56 +03:00
|
|
|
# AMO admin (not django admin).
|
2010-04-14 02:59:28 +04:00
|
|
|
('^admin/', include('zadmin.urls')),
|
2010-01-27 23:24:35 +03:00
|
|
|
|
2012-07-11 23:12:39 +04:00
|
|
|
# Performance wall of shame.
|
|
|
|
('^performance/', include('perf.urls')),
|
|
|
|
|
2010-03-29 22:02:34 +04:00
|
|
|
# Localizable pages.
|
|
|
|
('', include('pages.urls')),
|
|
|
|
|
2010-08-17 21:55:49 +04:00
|
|
|
# App versions.
|
|
|
|
('pages/appversions/', include('applications.urls')),
|
|
|
|
|
2010-02-05 02:14:16 +03:00
|
|
|
# Services
|
2010-05-13 07:56:50 +04:00
|
|
|
('', include('amo.urls')),
|
2010-02-05 08:39:55 +03:00
|
|
|
|
2011-11-16 21:08:51 +04:00
|
|
|
# Paypal
|
2012-04-04 20:22:40 +04:00
|
|
|
('^services/', include('paypal.urls')),
|
2011-11-16 21:08:51 +04:00
|
|
|
|
2010-02-25 22:17:53 +03:00
|
|
|
# Search
|
|
|
|
('^search/', include('search.urls')),
|
|
|
|
|
2010-02-13 23:41:54 +03:00
|
|
|
# Javascript translations.
|
2011-05-02 23:03:27 +04:00
|
|
|
url('^jsi18n.js$', cache_page(60 * 60 * 24 * 365)(javascript_catalog),
|
2010-12-23 05:21:36 +03:00
|
|
|
{'domain': 'javascript', 'packages': ['zamboni']}, name='jsi18n'),
|
2010-02-13 23:41:54 +03:00
|
|
|
|
2010-02-10 22:35:25 +03:00
|
|
|
# SAMO/API
|
|
|
|
('^api/', include('api.urls')),
|
|
|
|
|
2011-04-11 21:44:52 +04:00
|
|
|
('^compatibility/', include('compat.urls')),
|
|
|
|
|
2012-01-20 04:02:25 +04:00
|
|
|
# Site events data.
|
2012-01-31 02:24:10 +04:00
|
|
|
url('^statistics/events-(?P<start>\d{8})-(?P<end>\d{8}).json$',
|
2012-01-20 04:02:25 +04:00
|
|
|
'stats.views.site_events', name='amo.site_events'),
|
|
|
|
|
2012-02-11 00:46:48 +04:00
|
|
|
# Site statistics that we are going to catch, the rest will fall through.
|
|
|
|
url('^statistics/', include('stats.urls')),
|
|
|
|
|
|
|
|
# Fall through for any URLs not matched above stats dashboard.
|
2012-01-31 03:55:28 +04:00
|
|
|
url('^statistics/', lambda r: redirect('/'), name='statistics.dashboard'),
|
|
|
|
|
2010-08-27 08:54:01 +04:00
|
|
|
# Review spam.
|
2011-10-29 02:24:36 +04:00
|
|
|
url('^reviews/spam/$', 'reviews.views.spam', name='addons.reviews.spam'),
|
2010-08-27 08:54:01 +04:00
|
|
|
|
2010-02-05 08:39:55 +03:00
|
|
|
# Redirect patterns.
|
2010-06-08 02:27:22 +04:00
|
|
|
('^bookmarks/?$',
|
|
|
|
lambda r: redirect('browse.extensions', 'bookmarks', permanent=True)),
|
|
|
|
|
2010-02-05 08:39:55 +03:00
|
|
|
('^reviews/display/(\d+)',
|
2011-10-29 02:24:36 +04:00
|
|
|
lambda r, id: redirect('addons.reviews.list', id, permanent=True)),
|
2010-02-06 02:38:38 +03:00
|
|
|
|
2010-08-27 05:11:07 +04:00
|
|
|
('^reviews/add/(\d+)',
|
2011-10-29 02:24:36 +04:00
|
|
|
lambda r, id: redirect('addons.reviews.add', id, permanent=True)),
|
2010-08-27 05:11:07 +04:00
|
|
|
|
2010-02-02 20:03:47 +03:00
|
|
|
('^users/info/(\d+)',
|
|
|
|
lambda r, id: redirect('users.profile', id, permanent=True)),
|
|
|
|
|
2010-03-29 22:02:34 +04:00
|
|
|
('^pages/about$',
|
|
|
|
lambda r: redirect('pages.about', permanent=True)),
|
2010-05-12 21:51:53 +04:00
|
|
|
|
2012-03-17 03:36:06 +04:00
|
|
|
('^pages/credits$',
|
|
|
|
lambda r: redirect('pages.credits', permanent=True)),
|
|
|
|
|
2010-03-29 22:02:34 +04:00
|
|
|
('^pages/faq$',
|
|
|
|
lambda r: redirect('pages.faq', permanent=True)),
|
2010-05-12 21:51:53 +04:00
|
|
|
|
|
|
|
# Redirect persona/xxx
|
2012-03-29 03:45:08 +04:00
|
|
|
('^getpersonas$',
|
|
|
|
lambda r: redirect('http://www.getpersonas.com/gallery/All/Popular',
|
|
|
|
permanent=True)),
|
|
|
|
|
2011-03-03 22:31:32 +03:00
|
|
|
url('^persona/(?P<persona_id>\d+)', 'addons.views.persona_redirect',
|
|
|
|
name='persona'),
|
2010-05-26 23:39:14 +04:00
|
|
|
|
2010-07-29 01:56:26 +04:00
|
|
|
# Redirect top-tags to tags/top
|
2010-07-27 03:37:06 +04:00
|
|
|
('^top-tags/?',
|
|
|
|
lambda r: redirect('tags.top_cloud', permanent=True)),
|
|
|
|
|
2010-05-26 23:39:14 +04:00
|
|
|
('^personas/film and tv/?$',
|
|
|
|
lambda r: redirect('browse.personas', 'film-and-tv', permanent=True)),
|
|
|
|
|
2010-06-17 21:14:30 +04:00
|
|
|
('^addons/versions/(\d+)/?$',
|
|
|
|
lambda r, id: redirect('addons.versions', id, permanent=True)),
|
|
|
|
|
2010-07-13 03:53:19 +04:00
|
|
|
('^addons/versions/(\d+)/format:rss$',
|
|
|
|
lambda r, id: redirect('addons.versions.rss', id, permanent=True)),
|
|
|
|
|
2011-09-21 01:35:23 +04:00
|
|
|
# Legacy redirect. Requires a view to get extra data not provided in URL.
|
2011-10-22 00:03:08 +04:00
|
|
|
('^versions/updateInfo/(?P<version_id>\d+)',
|
2011-09-21 01:35:23 +04:00
|
|
|
'versions.views.update_info_redirect'),
|
|
|
|
|
2010-07-20 23:36:41 +04:00
|
|
|
('^addons/reviews/(\d+)/format:rss$',
|
2011-10-29 02:24:36 +04:00
|
|
|
lambda r, id: redirect('addons.reviews.list.rss', id, permanent=True)),
|
2010-07-20 23:36:41 +04:00
|
|
|
|
2010-06-19 03:11:12 +04:00
|
|
|
('^search-engines.*$',
|
|
|
|
lambda r: redirect('browse.search-tools', permanent=True)),
|
|
|
|
|
2010-06-23 21:08:16 +04:00
|
|
|
('^addons/contribute/(\d+)/?$',
|
|
|
|
lambda r, id: redirect('addons.contribute', id, permanent=True)),
|
2010-07-27 22:35:26 +04:00
|
|
|
|
2010-08-02 05:17:36 +04:00
|
|
|
('^recommended$',
|
2011-08-26 22:19:05 +04:00
|
|
|
lambda r: redirect(reverse('browse.extensions') + '?sort=featured',
|
|
|
|
permanent=True)),
|
2010-08-02 05:17:36 +04:00
|
|
|
|
2010-08-06 08:32:19 +04:00
|
|
|
('^recommended/format:rss$',
|
|
|
|
lambda r: redirect('browse.featured.rss', permanent=True)),
|
|
|
|
|
2009-12-03 01:07:36 +03:00
|
|
|
)
|
2009-10-23 03:43:38 +04:00
|
|
|
|
2011-07-08 23:07:23 +04:00
|
|
|
urlpatterns += patterns('piston.authentication.oauth.views',
|
|
|
|
url(r'^oauth/request_token/$', 'get_request_token',
|
2010-08-27 21:07:16 +04:00
|
|
|
name='oauth.request_token'),
|
2011-07-08 23:07:23 +04:00
|
|
|
url(r'^oauth/authorize/$', 'authorize_request_token',
|
|
|
|
name='oauth.authorize'),
|
|
|
|
url(r'^oauth/access_token/$', 'get_access_token',
|
2010-08-27 21:07:16 +04:00
|
|
|
name='oauth.access_token'),
|
|
|
|
)
|
|
|
|
|
2010-11-05 22:14:19 +03:00
|
|
|
if 'django_qunit' in settings.INSTALLED_APPS:
|
|
|
|
|
2011-07-30 01:28:20 +04:00
|
|
|
def _zamboni_qunit(request, path, template):
|
2011-05-26 03:43:46 +04:00
|
|
|
from time import time
|
2010-11-05 22:14:19 +03:00
|
|
|
import django_qunit.views
|
|
|
|
import jingo
|
2011-09-02 03:25:00 +04:00
|
|
|
import mock
|
2012-01-11 02:21:15 +04:00
|
|
|
|
|
|
|
# Patch `js` so that CI gets cache-busted JS with TEMPLATE_DEBUG=True.
|
|
|
|
# (This will be fixed in `jingo-minify` with bug 717094.)
|
|
|
|
from jingo_minify.helpers import _build_html
|
|
|
|
import jinja2
|
2012-02-18 03:17:57 +04:00
|
|
|
|
2012-01-11 02:21:15 +04:00
|
|
|
def js(bundle, defer=False, async=False):
|
|
|
|
items = settings.MINIFY_BUNDLES['js'][bundle]
|
|
|
|
attrs = ['src="%s?v=%s"' % ('%s', time())]
|
|
|
|
if defer:
|
|
|
|
attrs.append('defer')
|
|
|
|
if async:
|
|
|
|
attrs.append('async')
|
|
|
|
string = '<script %s></script>' % ' '.join(attrs)
|
|
|
|
return _build_html(items, string)
|
|
|
|
|
2010-11-05 22:14:19 +03:00
|
|
|
ctx = django_qunit.views.get_suite_context(request, path)
|
2012-01-11 02:21:15 +04:00
|
|
|
ctx.update(timestamp=time(), Mock=mock.Mock, js=js)
|
2011-07-30 01:28:20 +04:00
|
|
|
response = jingo.render(request, template, ctx)
|
2010-11-22 18:51:10 +03:00
|
|
|
# This allows another site to embed the QUnit suite
|
|
|
|
# in an iframe (for CI).
|
|
|
|
response['x-frame-options'] = ''
|
|
|
|
return response
|
2010-11-05 22:14:19 +03:00
|
|
|
|
2011-07-30 01:28:20 +04:00
|
|
|
def zamboni_qunit(request, path):
|
2011-09-21 06:28:37 +04:00
|
|
|
return _zamboni_qunit(request, path, 'qunit/qunit.html')
|
2011-07-30 01:28:20 +04:00
|
|
|
|
2010-11-05 22:14:19 +03:00
|
|
|
urlpatterns += patterns('',
|
|
|
|
url(r'^qunit/(?P<path>.*)', zamboni_qunit),
|
2010-12-30 22:31:49 +03:00
|
|
|
url(r'^_qunit/', include('django_qunit.urls')),
|
2010-11-05 22:14:19 +03:00
|
|
|
)
|
|
|
|
|
2011-09-12 21:01:01 +04:00
|
|
|
if settings.TEMPLATE_DEBUG:
|
2009-10-21 06:20:38 +04:00
|
|
|
# Remove leading and trailing slashes so the regex matches.
|
|
|
|
media_url = settings.MEDIA_URL.lstrip('/').rstrip('/')
|
|
|
|
urlpatterns += patterns('',
|
|
|
|
(r'^%s/(?P<path>.*)$' % media_url, 'django.views.static.serve',
|
2009-10-22 01:56:43 +04:00
|
|
|
{'document_root': settings.MEDIA_ROOT}),
|
2009-10-21 06:20:38 +04:00
|
|
|
)
|
2012-02-01 01:52:36 +04:00
|
|
|
|
|
|
|
if settings.SERVE_TMP_PATH and settings.DEBUG:
|
|
|
|
urlpatterns += patterns('',
|
|
|
|
(r'^tmp/(?P<path>.*)$', 'django.views.static.serve',
|
|
|
|
{'document_root': settings.TMP_PATH}),
|
|
|
|
)
|