1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
24 from sugarsoap_services import *
25 from sugarsoap_services_types import *
27 from tools.translate import _
29 from lxml import etree
30 class LoginError(Exception): pass
32 def login(username, password, url):
33 loc = sugarsoapLocator()
35 portType = loc.getsugarsoapPortType(url)
36 request = loginRequest()
37 uauth = ns0.user_auth_Def(request)
38 request._user_auth = uauth
40 uauth._user_name = username
41 uauth._password = hashlib.md5(password).hexdigest()
42 uauth._version = '1.1'
44 response = portType.login(request)
46 raise osv.except_osv(_('Error !'), _('Authentication error !\nBad Username or Password !'))
47 if -1 == response._return._id:
48 raise LoginError(response._return._error._description)
49 return (portType, response._return._id)
51 def relation_search(portType, sessionid, module_name=None, module_id=None, related_module=None, query=None, deleted=None):
52 se_req = get_relationshipsRequest()
53 se_req._session = sessionid
54 se_req._module_name = module_name
55 se_req._module_id = module_id
56 se_req._related_module = related_module
57 se_resp = portType.get_relationships(se_req)
60 list = se_resp._return.get_element_ids()
62 ans_list.append(i.get_element_id())
65 def user_get_attendee_list(portType, sessionid, module_name=None, module_id=None):
66 se_req = get_attendee_listRequest()
67 se_req._session = sessionid
68 se_req._module_name = module_name
69 se_req._id = module_id
70 se_resp = portType.get_attendee_list(se_req)
71 list = se_resp.get_element_return()
72 arch = base64.decodestring(list.Result)
75 attende_email_id = False
76 eview = etree.XML(arch)
78 for ch in child.getchildren():
81 if ch.tag == 'email1':
82 attende_email_id = ch.text
83 return attende_id, attende_email_id
86 def search(portType, sessionid, module_name=None):
87 se_req = get_entry_listRequest()
88 se_req._session = sessionid
89 se_req._module_name = module_name
90 se_resp = portType.get_entry_list(se_req)
93 list = se_resp._return._entry_list
96 for j in i._name_value_list:
97 ans_dir[j._name.encode('utf-8')] = j._value.encode('utf-8')
99 ans_list.append(ans_dir)