addons-server/mkt/urls.py

148 строки
4.9 KiB
Python

# -*- coding: utf-8 -*-
from django.conf import settings
from django.conf.urls import include, patterns, url
from django.contrib import admin
from django.http import HttpResponse
from django.shortcuts import redirect
from django.views.decorators.cache import cache_page
from django.views.i18n import javascript_catalog
import amo
from apps.users.views import logout
from apps.users.urls import (detail_patterns as user_detail_patterns,
users_patterns as users_users_patterns)
from mkt.api import oauth
from mkt.detail.views import manifest as mini_manifest
from mkt.developers.views import login
from mkt.operators.urls import url_patterns as operator_patterns
from mkt.purchase.urls import webpay_services_patterns
from mkt.reviewers.urls import url_patterns as reviewer_url_patterns
from mkt.stats.urls import app_site_patterns
admin.autodiscover()
handler403 = 'mkt.site.views.handler403'
handler404 = 'mkt.site.views.handler404'
handler500 = 'mkt.site.views.handler500'
home = lambda request: HttpResponse('''<a
href="https://github.com/mozilla/fireplace/wiki/Using-Fireplace-with-Zamboni">
<marquee style="font-size:400px">☠ RIP ☠</marquee></a>
''' if settings.DEBUG else '')
urlpatterns = patterns('',
# Home (now served by Fireplace).
url('^$', home, name='home'),
# App Detail pages.
# XXX: Temporary workaround for accessing overridden Fireplace URLs.
# Must come first so that url() isn't broken.
('^details/%s/' % amo.APP_SLUG, include('mkt.detail.urls')),
# TODO: Remove the app/.../ patterns after the consumer pages are removed
('^app/%s/' % amo.APP_SLUG, include('mkt.detail.urls')),
url('^app/%s/manifest.webapp$' % amo.ADDON_UUID, mini_manifest,
name='detail.manifest'),
# Dev Ecosystem
('^developers/', include('mkt.ecosystem.urls')),
('^ecosystem/', lambda r: redirect('ecosystem.landing', permanent=True)),
# Files
('^files/', include('mkt.files.urls')),
# Replace the "old" Developer Hub with the "new" Marketplace one.
('^developers/', include('mkt.developers.urls')),
# Submission.
('^developers/submit/', include('mkt.submit.urls')),
# Users (Legacy).
('^user/(?P<user_id>\d+)/', include(user_detail_patterns)),
('^users/', include(users_users_patterns)),
# Reviewer tools.
('^reviewers/', include(reviewer_url_patterns)),
# Account lookup.
('^lookup/', include('mkt.lookup.urls')),
# Bootstrapped operator dashboard.
('^operators/', include(operator_patterns)),
# Javascript translations.
url('^jsi18n.js$', cache_page(60 * 60 * 24 * 365)(javascript_catalog),
{'domain': 'javascript', 'packages': ['zamboni']}, name='jsi18n'),
# webpay / nav.pay() services.
('^services/webpay/', include(webpay_services_patterns)),
# AMO admin (not django admin).
('^admin/', include('zadmin.urls')),
# AMO Marketplace admin (not django admin).
('^admin/', include('mkt.zadmin.urls')),
# Accept extra junk at the end for a cache-busting build id.
url('^addons/buttons.js(?:/.+)?$', 'addons.buttons.js'),
# Developer Registration Login.
url('^login$', login, name='users.login'),
url('^logout$', logout, name='users.logout'),
url('^oauth/register/$', oauth.access_request,
name='mkt.developers.oauth_access_request'),
url('^oauth/token/$', oauth.token_request,
name='mkt.developers.oauth_token_request'),
url('^oauth/authorize/$', oauth.authorize,
name='mkt.developers.oauth_authorize'),
url('^api/', include('mkt.api.urls')),
url('^downloads/', include('mkt.downloads.urls')),
# Try and keep urls without a prefix at the bottom of the list for
# minor performance reasons.
# Misc pages.
('', include('mkt.commonplace.urls')),
('', include('mkt.site.urls')),
# Site events data.
url('^statistics/events-(?P<start>\d{8})-(?P<end>\d{8}).json$',
'stats.views.site_events', name='amo.site_events'),
# Catch marketplace specific statistics urls.
url('^statistics/', include(app_site_patterns)),
# Let the rest of the URLs fall through.
url('^statistics/', include('stats.urls')),
# Disable currently not working statistics.
# Fall through for any URLs not matched above stats dashboard.
url('^statistics/', lambda r: redirect('/'), name='statistics.dashboard'),
# Services.
('', include('amo.urls')),
)
if settings.TEMPLATE_DEBUG:
# 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',
{'document_root': settings.MEDIA_ROOT}),
)
if settings.SERVE_TMP_PATH and settings.DEBUG:
# Serves any URL like /tmp/* from your local ./tmp/ dir
urlpatterns += patterns('',
(r'^tmp/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.TMP_PATH}),
)