コード例 #1
0
ファイル: middleware.py プロジェクト: Reinmar/kuma
from django.core import urlresolvers
from django.http import HttpResponsePermanentRedirect, HttpResponseForbidden
from django.utils.encoding import iri_to_uri, smart_str, smart_unicode

import tower

from devmo import get_mysql_error
from sumo.helpers import urlparams
from sumo.urlresolvers import Prefixer, set_url_prefixer, split_path
from sumo.views import handle403


# Django compatibility shim. Once we're on Django 1.4, do:
# from django.db.utils import DatabaseError
DatabaseError = get_mysql_error()


class LocaleURLMiddleware(object):
    """
    Based on zamboni.amo.middleware.
    Tried to use localeurl but it choked on 'en-US' with capital letters.

    1. Search for the locale.
    2. Save it in the request.
    3. Strip them from the URL.
    """

    def process_request(self, request):
        prefixer = Prefixer(request)
        set_url_prefixer(prefixer)
コード例 #2
0
from django.core import urlresolvers
from django.http import HttpResponsePermanentRedirect, HttpResponseForbidden
from django.utils.encoding import iri_to_uri, smart_str, smart_unicode

import jingo
import tower

from devmo import get_mysql_error
from sumo.helpers import urlparams
from sumo.urlresolvers import Prefixer, set_url_prefixer, split_path
from sumo.views import handle403

# Django compatibility shim. Once we're on Django 1.4, do:
# from django.db.utils import DatabaseError
DatabaseError = get_mysql_error()


class LocaleURLMiddleware(object):
    """
    Based on zamboni.amo.middleware.
    Tried to use localeurl but it choked on 'en-US' with capital letters.

    1. Search for the locale.
    2. Save it in the request.
    3. Strip them from the URL.
    """
    def process_request(self, request):
        prefixer = Prefixer(request)
        set_url_prefixer(prefixer)
        full_path = prefixer.fix(prefixer.shortened_path)