Skip to content

Commit

Permalink
Merge pull request concentricsky#37 from stefanw/python-3
Browse files Browse the repository at this point in the history
Makes the project compatible with Python 3
  • Loading branch information
johnraz committed Jan 28, 2015
2 parents 99189d3 + 124d452 commit 76b7874
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
19 changes: 12 additions & 7 deletions tastypie_swagger/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
import logging

from django.db.models.sql.constants import QUERY_TERMS
from django.utils.encoding import force_unicode

try:
from django.utils.encoding import force_text
except ImportError:
from django.utils.encoding import force_text as force_text


from tastypie import fields

Expand Down Expand Up @@ -134,7 +139,7 @@ def build_parameters_from_fields(self):
name=name,
dataType=field['type'],
required=not field['blank'],
description=force_unicode(field['help_text']),
description=force_text(field['help_text']),
))
return parameters

Expand Down Expand Up @@ -180,7 +185,7 @@ def build_parameters_from_filters(self, prefix="", method='GET'):
name=name,
dataType=type,
required=False,
description=force_unicode(desc),
description=force_text(desc),
))
if 'filtering' in self.schema and method.upper() == 'GET':
for name, field in self.schema['filtering'].items():
Expand Down Expand Up @@ -237,7 +242,7 @@ def build_parameters_from_filters(self, prefix="", method='GET'):

for query in field:
if query == 'exact':
description = force_unicode(schema_field['help_text'])
description = force_text(schema_field['help_text'])

# Use a better description for related models with exact filter
parameters.append(self.build_parameter(
Expand All @@ -253,7 +258,7 @@ def build_parameters_from_filters(self, prefix="", method='GET'):
name="%s%s__%s" % (prefix, name, query),
dataType=dataType,
required = False,
description=force_unicode(schema_field['help_text']),
description=force_text(schema_field['help_text']),
))

return parameters
Expand Down Expand Up @@ -284,7 +289,7 @@ def build_parameters_from_extra_action(self, method, fields, resource_type):
name=name,
dataType=field.get("type", "string"),
required=field.get("required", True),
description=force_unicode(field.get("description", "")),
description=force_text(field.get("description", "")),
))

# For non-standard API functionality, allow the User to declaritively
Expand Down Expand Up @@ -443,7 +448,7 @@ def build_properties_from_fields(self, method='get'):
field.get('type'),
# note: 'help_text' is a Django proxy which must be wrapped
# in unicode *specifically* to get the actual help text.
force_unicode(field.get('help_text', '')),
force_text(field.get('help_text', '')),
)
)
return properties
Expand Down
5 changes: 4 additions & 1 deletion tastypie_swagger/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from urlparse import urljoin
try:
from urllib.parse import urljoin
except ImportError:
from urlparse import urljoin

from django.conf import settings

Expand Down

0 comments on commit 76b7874

Please sign in to comment.