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 ##############################################################################
23 # Does not properly work concurently !!!
28 from tools.translate import _
30 login_form = '''<?xml version="1.0"?>
32 <field name="uname"></field>
34 <field name="password"></field>
38 send_form = '''<?xml version="1.0"?>
39 <form title="Selection">
40 <field name="uname"></field>
41 <field name="password"></field>
43 <field name="objects"></field>
45 <field name="dates" colspan="3"></field>
49 'uname': {'string':'Login', 'type':'char'},
50 'password': {'string':'Password', 'type':'char'},
51 'dates': {'string':'Auction Date', 'type':'selection', 'selection':[]}
55 'uname': {'string':'Login', 'type':'char', 'readonly':True},
56 'password': {'string':'Password', 'type':'char', 'readonly':True},
57 'objects': {'string':'# of objects', 'type':'integer', 'readonly':True},
58 'dates': {'string':'Auction Date', 'type':'selection', 'selection':[]}
61 def _catalog_send(uname, passwd, did, catalog):
62 def post_multipart(host, selector, fields, files):
63 def encode_multipart_formdata(fields, files):
64 BOUNDARY = '----------ThIs_Is_tHe_bouNdaRY_$'
67 for (key, value) in fields:
68 L.append('--' + BOUNDARY)
69 L.append('Content-Disposition: form-data; name="%s"' % key)
72 for (key,value) in files:
73 L.append('--' + BOUNDARY)
74 L.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (key, key+'.pickle'))
75 L.append('Content-Type: application/octet-stream')
78 L.append('--' + BOUNDARY + '--')
81 content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
82 return content_type, body
83 content_type, body = encode_multipart_formdata(fields, files)
86 headers = {"Content-type": content_type, "Accept": "*/*"}
87 conn = httplib.HTTPConnection(host)
88 conn.request("POST", '/bin/catalog_result.cgi', body, headers = headers)
89 response = conn.getresponse()
93 return post_multipart('auction-in-europe.com', "/bin/catalog_result.cgi", (('uname',uname),('password',passwd),('did',did)),(('file',catalog),))
95 def _get_dates(self,cr,uid, datas, context):
98 conn = httplib.HTTPConnection('www.auction-in-europe.com')
99 conn.request("GET", "/aie_upload/dates_get_result.php?uname=%s&passwd=%s" % (datas['form']['uname'], datas['form']['password']))
100 response = conn.getresponse()
101 if response.status == 200:
103 return (x.split(' - ')[0], (' - '.join(x.split(' - ')[1:]).decode('latin1').encode('utf-8')))
104 send_fields['dates']['selection'] = map(_date_decode, response.read().split('\n'))
106 raise wizard.except_wizard(_('Error'),
107 _("Connection to WWW.Auction-in-Europe.com failed !"))
108 return {'objects':len(datas['ids'])}
110 def _send(self,cr,uid, datas, context):
112 service = netsvc.LocalService("object_proxy")
113 lots = service.execute(cr.dbname,uid, 'auction.lots', 'read', datas['ids'], ['obj_num','obj_price'])
114 args = pickle.dumps(lots)
115 _catalog_send(datas['form']['uname'],datas['form']['password'], datas['form']['dates'], args)
118 class wiz_auc_lots_pay(wizard.interface):
122 'result': {'type': 'form', 'arch':login_form, 'fields': login_fields, 'state':[('date_ask','Continue'),('end','Cancel')]}
125 'actions': [_get_dates],
126 'result': {'type': 'form', 'arch':send_form, 'fields': send_fields, 'state':[('send','Send on your website'),('end','Cancel')]}
130 'result': {'type': 'state', 'state':'end'}
133 wiz_auc_lots_pay('auction.lots.send.aie.results');
136 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: