Skip to content
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
4 changes: 2 additions & 2 deletions sugarcrm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from sugarcrm import *
from sugarmodule import *
from .sugarcrm import *
from .sugarmodule import *
__version__ = "0.3.1"

# This is supposed to help importing, does nothing as far as I can tell
Expand Down
2 changes: 1 addition & 1 deletion sugarcrm/sugarcrm.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def f(*args):
elif error.is_null_response:
return None
elif error.is_invalid_request:
print method_name, args
print(method_name, args)
else:
raise SugarUnhandledException('%d, %s - %s' %
(error.number,
Expand Down
14 changes: 9 additions & 5 deletions sugarcrm/sugarentry.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from __future__ import print_function
import six
from six.moves.html_parser import HTMLParser

from collections import defaultdict
from itertools import count

import six
from six.moves.html_parser import HTMLParser


class SugarEntry:
"""Define an entry of a SugarCRM module."""
_hashes = defaultdict(count(1).next if hasattr(count(1), 'next') else count(1).__next__)


def __init__(self, module, fmap = None):
"""Represents a new or an existing entry.

Expand Down Expand Up @@ -39,7 +41,10 @@ def __unicode__(self):
(self._module._name.rstrip('s'), self['name'])

def __str__(self):
return str(self).encode('utf-8')
result = self.__unicode__()
if six.PY2:
result = result.encode('utf-8')
return result

def __contains__(self, key):
return key in self._module._fields
Expand Down Expand Up @@ -167,4 +172,3 @@ def get_related(self, module, fields = None, relateby = None):
entries.append(entry)

return entries

22 changes: 16 additions & 6 deletions sugarcrm/sugarmodule.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
from __future__ import unicode_literals

import sys
import itertools
from collections import deque

from six.moves.html_parser import HTMLParser

from .sugarentry import SugarEntry
from collections import deque

if sys.version > '3':
long = int
basestring = (str, bytes)
unicode = str

HTMLP = HTMLParser()

Expand Down Expand Up @@ -70,9 +79,9 @@ def _search(self, query_str, start = 0, total = 20, fields = None, query = None)
total - len(entry_list), 0)
if resp_data['total_count']:
try:
result['total'] = int(resp_data['total_count'], 10)
except TypeError as e:
print resp_data
result['total'] = int(resp_data['total_count'])
except TypeError:
print(resp_data)
else:
result['total'] = 0
if resp_data['result_count'] == 0:
Expand All @@ -88,7 +97,7 @@ def _search(self, query_str, start = 0, total = 20, fields = None, query = None)
entry[key] = HTMLP.unescape(val) if isinstance(val, basestring) else val
entry_list.append(entry)

if resp_data['result_count'] == int(resp_data['total_count'], 10):
if resp_data['result_count'] == int(resp_data['total_count']):
break

result['entries'] = entry_list
Expand Down Expand Up @@ -185,6 +194,7 @@ def _build_query(self, **query):
for key, val in list(query.items()):
# Get the field and the operator from the query
key_field, key_sep, key_oper = key.partition('__')
key_oper = key_oper or 'exact'
if q_str != '':
q_str += ' AND '

Expand Down Expand Up @@ -256,5 +266,5 @@ def __len__(self):
if self._total == -1:
result = self._module._connection.get_entries_count(self._module._name, self._query, 0)

self._total = int(result['result_count'], 10)
self._total = int(result['result_count'])
return self._total