Skip to content

python 3 compatibility #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions django_remote_forms/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,6 @@ def as_dict(self):
field_dict['initial'] = self.form_initial_data or self.field.initial
field_dict['help_text'] = self.field.help_text

field_dict['error_messages'] = self.field.error_messages

# Instantiate the Remote Forms equivalent of the widget if possible
# in order to retrieve the widget contents as a dictionary.
remote_widget_class_name = 'Remote%s' % self.field.widget.__class__.__name__
try:
remote_widget_class = getattr(widgets, remote_widget_class_name)
remote_widget = remote_widget_class(self.field.widget, field_name=self.field_name)
except Exception, e:
logger.warning('Error serializing %s: %s', remote_widget_class_name, str(e))
widget_dict = {}
else:
widget_dict = remote_widget.as_dict()

field_dict['widget'] = widget_dict

return field_dict


Expand Down
16 changes: 13 additions & 3 deletions django_remote_forms/forms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from collections import OrderedDict
from django import forms

from django_remote_forms import fields, logger
from django_remote_forms.utils import resolve_promise
Expand Down Expand Up @@ -38,7 +39,7 @@ def __init__(self, form, *args, **kwargs):
'Readonly fields %s are not present in form fields' % (set(self.ordered_fields) - self.all_fields))
self.ordered_fields = []

if self.included_fields | self.excluded_fields:
if self.included_fields & self.excluded_fields:
logger.warning(
'Included and excluded fields have following fields %s in common' % (
set(self.ordered_fields) - self.all_fields
Expand Down Expand Up @@ -134,11 +135,20 @@ def as_dict(self):

# Instantiate the Remote Forms equivalent of the field if possible
# in order to retrieve the field contents as a dictionary.
remote_field_class_name = 'Remote%s' % field.__class__.__name__
# remote_field_class_name = 'Remote%s' % field.__class__.__name__
remote_field_class_name = 'RemoteField'
if issubclass(field.__class__, forms.DateField):
remote_field_class_name = 'Remote{}'.format('DateField')
elif issubclass(field.__class__, forms.TimeField):
remote_field_class_name = 'Remote{}'.format('TimeField')
elif issubclass(field.__class__, forms.DateTimeField):
remote_field_class_name = 'Remote{}'.format('DateTimeField')
elif issubclass(field.__class__, forms.ChoiceField):
remote_field_class_name = 'Remote{}'.format('ChoiceField')
try:
remote_field_class = getattr(fields, remote_field_class_name)
remote_field = remote_field_class(field, form_initial_field_data, field_name=name)
except Exception, e:
except Exception as e:
logger.warning('Error serializing field %s: %s', remote_field_class_name, str(e))
field_dict = {}
else:
Expand Down
4 changes: 2 additions & 2 deletions django_remote_forms/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.utils.functional import Promise
from django.utils.encoding import force_unicode
from django.utils.encoding import force_text


def resolve_promise(o):
Expand All @@ -10,7 +10,7 @@ def resolve_promise(o):
o = [resolve_promise(x) for x in o]
elif isinstance(o, Promise):
try:
o = force_unicode(o)
o = force_text(o)
except:
# Item could be a lazy tuple or list
try:
Expand Down