# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.core.serializers.json import DjangoJSONEncoder
from django_react_templatetags.mixins import RepresentationMixin


def json_encoder_cls_factory(context):
    class ReqReactRepresentationJSONEncoder(ReactRepresentationJSONEncoder):
        context = None

    ReqReactRepresentationJSONEncoder.context = context
    return ReqReactRepresentationJSONEncoder


class ReactRepresentationJSONEncoder(DjangoJSONEncoder):
    '''
    Custom json encoder that adds support for RepresentationMixin
    '''

    def default(self, o):
        if isinstance(o, RepresentationMixin):
            args = [self.context if hasattr(self, 'context') else None]
            args = [x for x in args if x is not None]

            return o.to_react_representation(*args)

        return super(ReactRepresentationJSONEncoder, self).default(o)

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.core.serializers.json import DjangoJSONEncoder
from django_react_templatetags.mixins import RepresentationMixin


def json_encoder_cls_factory(context):
    class ReqReactRepresentationJSONEncoder(ReactRepresentationJSONEncoder):
        context = None

    ReqReactRepresentationJSONEncoder.context = context
    return ReqReactRepresentationJSONEncoder


class ReactRepresentationJSONEncoder(DjangoJSONEncoder):
    '''
    Custom json encoder that adds support for RepresentationMixin
    '''

    def default(self, o):
        if isinstance(o, RepresentationMixin):
            # Allow backwards compability with react_representation prop
            if not hasattr(o, 'to_react_representation'):
                return o.react_representation

            args = [self.context if hasattr(self, 'context') else None]
            args = [x for x in args if x is not None]

            return o.to_react_representation(*args)

        return super(ReactRepresentationJSONEncoder, self).default(o)

--- 
+++ 
@@ -20,10 +20,6 @@
 
     def default(self, o):
         if isinstance(o, RepresentationMixin):
-            # Allow backwards compability with react_representation prop
-            if not hasattr(o, 'to_react_representation'):
-                return o.react_representation
-
             args = [self.context if hasattr(self, 'context') else None]
             args = [x for x in args if x is not None]
 
Drop support for reacct_representation property
