Bug 585494: nickname blacklist is all utf-8'd up now

This commit is contained in:
chenba 2010-08-09 23:21:04 -07:00
Родитель 9da9d71143
Коммит b3e06b9300
2 изменённых файлов: 4 добавлений и 2 удалений

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

@ -1,5 +1,6 @@
from django.contrib import admin, messages
from django.db.utils import IntegrityError
from django.utils.encoding import smart_unicode
import jingo
@ -52,7 +53,7 @@ class BlacklistedNicknameAdmin(admin.ModelAdmin):
if BlacklistedNickname.blocked(n):
duplicates += 1
continue
n = n.decode().lower().encode('utf-8')
n = smart_unicode(n).lower().encode('utf-8')
try:
BlacklistedNickname.objects.create(nickname=n)
inserted += 1

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

@ -10,6 +10,7 @@ from django.contrib.auth.models import User as DjangoUser
from django.core.mail import send_mail
from django.db import models
from django.template import Context, loader
from django.utils.encoding import smart_unicode
import caching.base as caching
import commonware.log
@ -204,7 +205,7 @@ class BlacklistedNickname(amo.models.ModelBase):
@classmethod
def blocked(cls, nick):
"""Check to see if a nickname is in the (cached) blacklist."""
nick = nick.decode().lower().encode('utf-8')
nick = smart_unicode(nick).lower()
qs = cls.objects.all()
f = lambda: dict(qs.values_list('nickname', 'id'))
blacklist = caching.cached_with(qs, f, 'blocked')