Monkey patch django.core.urlresolvers with our own reverse function packaged in l10n.urlresolvers. Prevents having to try importing l10n.urlresolvers and falling back on django.core.urlresolvers

This commit is contained in:
Paul Osman 2010-10-15 16:59:55 -04:00
Родитель 738c7d2d1c
Коммит 67178906dd
12 изменённых файлов: 14 добавлений и 67 удалений

Просмотреть файл

@ -3,14 +3,10 @@ from django.db.models import Q
from django.contrib.auth.models import User
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
from django.core.urlresolvers import reverse
from django.utils.timesince import timesince
from django.utils.translation import ugettext as _
try:
from l10n.urlresolvers import reverse
except ImportError:
from django.core.urlresolvers import reverse
from activity.schema import object_type, verbs, object_types, UnknownActivityError
class ActivityManager(models.Manager):

Просмотреть файл

@ -1,4 +1,5 @@
from django.contrib.auth.decorators import login_required
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext
@ -7,11 +8,6 @@ from activity.models import Activity
from profiles.models import Profile
from users.forms import LoginForm
try:
from l10n.urlresolvers import reverse
except ImportError:
from django.core.urlresolvers import reverse
def splash(request):
"""Splash page we show to users who are not authenticated."""
form = LoginForm()

Просмотреть файл

@ -1,18 +1,4 @@
from django.db import models
from django.core import urlresolvers as django_urlresolvers
from l10n import urlresolvers
def permalink(func):
"""
Decorator that calls l10n.urlresolvers.reverse() to return a URL using
parameters returned by the decorated function "func".
Note that this decorator is exactly the same as django.db.models.permalink
except that it uses l10n.urlresolvers instead of django.core.urlresolvers.
We monkey patch django.db.models here to make this behaviour the default.
"""
from l10n.urlresolvers import reverse
def inner(*args, **kwargs):
bits = func(*args, **kwargs)
return reverse(bits[0], None, *bits[1:3])
return inner
models.permalink = permalink
django_urlresolvers.reverse = urlresolvers.reverse

Просмотреть файл

@ -1,14 +1,10 @@
from django.http import HttpResponse, HttpResponseRedirect, Http404
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.views.decorators.http import require_http_methods
from django.shortcuts import render_to_response
from django.template import RequestContext
try:
from l10n.urlresolvers import reverse
except ImportError:
from django.core.urlresolvers import reverse
from profiles.forms import ImageForm, ProfileForm, InterestForm, SkillForm
from profiles.models import Profile, Skill, Interest

Просмотреть файл

@ -1,12 +1,8 @@
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.db import models
from django.db.models.signals import post_save
from django.template.defaultfilters import slugify
try:
from l10n.urlresolvers import reverse
except ImportError:
from django.core.urlresolvers import reverse
class Project(models.Model):
"""Placeholder model for projects."""

Просмотреть файл

@ -1,5 +1,6 @@
import re
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
@ -7,10 +8,6 @@ from django.template import RequestContext
from projects.models import Project
from projects.forms import ProjectForm
try:
from l10n.urlresolvers import reverse
except ImportError:
from django.core.urlresolvers import reverse
def show(request, slug):
project = get_object_or_404(Project, slug=slug)

Просмотреть файл

@ -1,15 +1,11 @@
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from django.core.urlresolvers import reverse
from django.http import HttpResponse, HttpResponseRedirect
from django.utils.translation import ugettext as _
from django.views.decorators.http import require_http_methods
from django.shortcuts import render_to_response
from django.template import RequestContext
try:
from l10n.urlresolvers import reverse
except ImportError:
from django.core.urlresolvers import reverse
from relationships.models import Relationship

Просмотреть файл

@ -1,12 +1,8 @@
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.db import models
from django.db.models.signals import post_save
try:
from l10n.urlresolvers import reverse
except ImportError:
from django.core.urlresolvers import reverse
class Status(models.Model):
author = models.ForeignKey(User)
object_type = 'http://activitystrea.ms/schema/1.0/status'

Просмотреть файл

@ -6,6 +6,7 @@ from django.contrib import auth
from django.contrib.auth import models as auth_models
from django.contrib.auth.models import User
from django.contrib.auth.backends import ModelBackend
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.utils.translation import ugettext as _
from openid.consumer.consumer import SUCCESS
@ -19,11 +20,6 @@ from django_openid_auth.models import UserOpenID
from django_openid_auth.views import make_consumer, render_openid_request, \
parse_openid_response
try:
from l10n.urlresolvers import reverse
except ImportError:
from django.core.urlresolvers import reverse
def get_hexdigest(algorithm, salt, raw_password):
"""Generate SHA-256 hash."""
if algorithm == 'sha256':

Просмотреть файл

@ -1,9 +1,5 @@
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _
try:
from l10n.urlresolvers import reverse
except ImportError:
from django.core.urlresolvers import reverse
def send_reset_email(user, token, uri_func, view='users_reset_password_form'):
"""Send instructions to user on how to reset their password."""

Просмотреть файл

@ -1,10 +1,10 @@
import hashlib
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.db import IntegrityError
from django.test import Client, TestCase
from l10n.urlresolvers import reverse
from users.models import ConfirmationToken
class TestLogins(TestCase):

Просмотреть файл

@ -3,6 +3,7 @@ from django.contrib import auth
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect, Http404
from django.utils.translation import ugettext as _
from django.views.decorators.http import require_http_methods
@ -11,11 +12,6 @@ from django.template import RequestContext
from django_openid_auth.forms import OpenIDLoginForm
try:
from l10n.urlresolvers import reverse
except ImportError:
from django.core.urlresolvers import reverse
from users.mail import send_reset_email, send_registration_email
from users.models import ConfirmationToken, unique_confirmation_token
from users.forms import (RegisterForm, LoginForm, ForgotPasswordForm,