Skip to content

Commit 4b419da

Browse files
committed
Merge branch 'master' of github.com:ella/django-markup
2 parents bd3fe3b + 994a0d8 commit 4b419da

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

djangomarkup/fields.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from django.contrib.contenttypes.models import ContentType
1212
from djangomarkup.models import SourceText, TextProcessor
1313
from djangomarkup.widgets import RichTextAreaWidget
14-
from djangomarkup.processors import ProcessorConfigurationError, ProcessorError
14+
from djangomarkup.processors import ProcessorError
1515

1616
RICH_FIELDS_SET = '__rich_fields_list'
1717
SRC_TEXT_ATTR = '__src_text'
@@ -22,14 +22,18 @@ class UnicodeWrapper(unicode):
2222
def __str__(self):
2323
return smart_str(self)
2424

25-
if settings.DATABASE_ENGINE == 'postgresql_psycopg2':
2625
def __conform__(self, x):
27-
# hack to enable psycopg2's adapting to work
28-
# on something that is not a unicode
29-
from psycopg2.extensions import adapt
30-
return adapt(unicode(self))
31-
UnicodeWrapper.__conform__ = __conform__
32-
26+
try:
27+
engine = settings.DATABASES['default']['ENGINE'].split('.')[-1]
28+
except (KeyError, AttributeError):
29+
engine = getattr(settings, 'DATABASE_ENGINE', '').split('.')[-1]
30+
31+
if engine.startswith('postgresql'):
32+
# hack to enable psycopg2's adapting to work
33+
# on something that is not a unicode
34+
from psycopg2.extensions import adapt
35+
return adapt(unicode(self))
36+
return unicode(self)
3337

3438
def post_save_listener(sender, instance, src_text_attr=SRC_TEXT_ATTR, **kwargs):
3539
src_texts = []

djangomarkup/models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def get_function(self):
5252
def convert(self, src_txt):
5353
function = self.get_function()
5454
try:
55-
return function(src_txt)
55+
return unicode(function(src_txt))
5656
except Exception, err:
5757
raise ProcessorError(err)
5858

0 commit comments

Comments
 (0)