From 348f2cbfc15c3d80ecc35981d1bd980e06435774 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Sat, 1 Dec 2007 22:26:24 +0000 Subject: [PATCH] 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 --- django/db/backends/postgresql_psycopg2/base.py | 2 ++ tests/modeltests/field_defaults/models.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py index d7b35583443..6b5233e8de0 100644 --- a/django/db/backends/postgresql_psycopg2/base.py +++ b/django/db/backends/postgresql_psycopg2/base.py @@ -6,6 +6,7 @@ Requires psycopg 2: http://initd.org/projects/psycopg2 from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures from django.db.backends.postgresql.operations import DatabaseOperations as PostgresqlDatabaseOperations +from django.utils.safestring import SafeUnicode try: import psycopg2 as Database import psycopg2.extensions @@ -17,6 +18,7 @@ DatabaseError = Database.DatabaseError IntegrityError = Database.IntegrityError psycopg2.extensions.register_type(psycopg2.extensions.UNICODE) +psycopg2.extensions.register_adapter(SafeUnicode, psycopg2.extensions.QuotedString) class DatabaseFeatures(BaseDatabaseFeatures): needs_datetime_string_cast = False diff --git a/tests/modeltests/field_defaults/models.py b/tests/modeltests/field_defaults/models.py index 1132f1ca418..fe80cce4060 100644 --- a/tests/modeltests/field_defaults/models.py +++ b/tests/modeltests/field_defaults/models.py @@ -48,4 +48,9 @@ u'Default headline' >>> d = now - a.pub_date >>> d.seconds < 5 True + +# make sure that SafeUnicode fields work +>>> from django.utils.safestring import SafeUnicode +>>> a.headline = SafeUnicode(u'SafeUnicode Headline') +>>> a.save() """}