1
0
mirror of https://github.com/django/django.git synced 2024-12-23 01:25:58 +00:00

Fixed #5996 -- Add a pyscopg2 convertor for SafeUnicode -> unicode. Thanks, remco@diji.biz

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6816 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2007-12-01 22:26:24 +00:00
parent b3db18817a
commit 348f2cbfc1
2 changed files with 7 additions and 0 deletions

View File

@ -6,6 +6,7 @@ Requires psycopg 2: http://initd.org/projects/psycopg2
from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures
from django.db.backends.postgresql.operations import DatabaseOperations as PostgresqlDatabaseOperations from django.db.backends.postgresql.operations import DatabaseOperations as PostgresqlDatabaseOperations
from django.utils.safestring import SafeUnicode
try: try:
import psycopg2 as Database import psycopg2 as Database
import psycopg2.extensions import psycopg2.extensions
@ -17,6 +18,7 @@ DatabaseError = Database.DatabaseError
IntegrityError = Database.IntegrityError IntegrityError = Database.IntegrityError
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE) psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
psycopg2.extensions.register_adapter(SafeUnicode, psycopg2.extensions.QuotedString)
class DatabaseFeatures(BaseDatabaseFeatures): class DatabaseFeatures(BaseDatabaseFeatures):
needs_datetime_string_cast = False needs_datetime_string_cast = False

View File

@ -48,4 +48,9 @@ u'Default headline'
>>> d = now - a.pub_date >>> d = now - a.pub_date
>>> d.seconds < 5 >>> d.seconds < 5
True True
# make sure that SafeUnicode fields work
>>> from django.utils.safestring import SafeUnicode
>>> a.headline = SafeUnicode(u'SafeUnicode Headline')
>>> a.save()
"""} """}