Commit 1b332ada authored by ryanss's avatar ryanss
Browse files

Methods get_entries/get_entry_list return list of objects

parent 2bdc74fe
......@@ -28,6 +28,11 @@ Example Usage
note_query = sugarcrm.Note("Test%")
results = sugar.get_entry_list(note_query)
# Query for all contacts with the first name "Mylee"
contact_query = sugarcrm.Contact()
contact_query.first_name = "Mylee"
results = sugar.get_entry_list(contact_query)
# Get the email address for the user assigned to an Opportunity
op = sugar.get_entry("Opportunities", "82f72939-735e-53a2-0944-5418c4edae2a")
user = sugar.get_entry("Users", op.assigned_user_id)
......
......@@ -42,17 +42,33 @@ class API:
if not isinstance(ids, list):
ids = [ids,]
data = [self.session_id, module, ids, [], [], track_view]
return self.request('get_entries', data)['entry_list']
def get_entry_list(self, obj):
data = [self.session_id, obj.type, obj.query, "", 0, [], [], 2, 0, False]
return self.request('get_entry_list', data)
results = self.request('get_entries', data)['entry_list']
ret = []
for result in results:
obj = SugarObject()
obj.type = module
for key in result['name_value_list']:
setattr(obj, key, result['name_value_list'][key]['value'])
ret.append(obj)
return ret
def get_entry_list(self, q):
data = [self.session_id, q.type, q.query, "", 0, [], [], 0, 0, False]
results = self.request('get_entry_list', data)['entry_list']
ret = []
for result in results:
obj = SugarObject()
obj.type = q.type
for key in result['name_value_list']:
setattr(obj, key, result['name_value_list'][key]['value'])
ret.append(obj)
return ret
def set_entry(self, obj):
data = [self.session_id, obj.type, obj.fields]
result = self.request('set_entry', data)
obj.id = result['id']
return True
return obj
def set_note_attachment(self, note, f):
if isinstance(f, str):
......@@ -87,6 +103,8 @@ class SugarObject:
def query(self):
q = ""
for key, value in self.__dict__.items():
if not value:
continue
if q:
q += "AND "
if value.find('%') >= 0:
......@@ -96,6 +114,10 @@ class SugarObject:
return q
class Contact(SugarObject):
type = "Contacts"
class Opportunity(SugarObject):
type = "Opportunities"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment