1
##############################################################################
3
# Copyright (c) 2007 Zikzakmedia SL (http://www.zikzakmedia.com) All Rights Reserved.
5
# WARNING: This program as such is intended to be used by professional
6
# programmers who take the whole responsability of assessing all potential
7
# consequences resulting from its eventual inadequacies and bugs
8
# End users who are looking for a ready-to-use solution with commercial
9
# garantees and support are strongly adviced to contract a Free Software
12
# This program is Free Software; you can redistribute it and/or
13
# modify it under the terms of the GNU General Public License
14
# as published by the Free Software Foundation; either version 2
15
# of the License, or (at your option) any later version.
17
# This program is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
# GNU General Public License for more details.
22
# You should have received a copy of the GNU General Public License
23
# along with this program; if not, write to the Free Software
24
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
##############################################################################
35
def export_table(self, cr, uid, data, context, server, table, fields, filter = [], filterphp = ''):
36
"""Export (synchronize) the fields of the radiotv.table to Joomla PHP server.
37
Only the records matching the filter are exported.
38
filterphp is the same filter in SQL notation to used in the PHP code.
39
New records are inserted, existing records are updated and removed records are deleted"""
40
pool = pooler.get_pool(cr.dbname)
41
obj = 'radiotv.'+table
42
tbl = 'radiotv_'+table
45
server.reset_table(tbl)
46
elem_ids = pool.get(obj).search(cr, uid, filter)
47
for elem in pool.get(obj).browse(cr, uid, elem_ids, context):
51
if field[-3:] == "_id":
52
vals[field] = getattr(elem, field).id
53
elif field[-4:] == "_ids":
54
vals[field] = [c.id for c in getattr(elem, field)]
56
vals[field] = getattr(elem, field)
58
attach_ids = pool.get('ir.attachment').search(cr, uid, [('res_model','=',obj), ('res_id', '=',elem.id)])
60
for data in pool.get('ir.attachment').browse(cr, uid, attach_ids, context):
61
s = data['datas_fname'].split('.')
62
extension = s[-1].lower()
65
#print name + " " + extension
66
if extension in ['jpeg', 'jpe', 'jpg', 'gif', 'png']:
67
if extension in ['jpeg', 'jpe', 'jpg']:
70
vals['picture'+str(cont)] = data['datas']
73
vals['picture'+str(cont)] = base64.encodestring(urllib.urlopen(data['link']).read())
76
vals['fname'+str(cont)] = name + '.' + extension
80
if server.set_table(tbl, vals):
85
delete = server.delete_table(tbl, filterphp)
86
return (new, update, delete)
89
def export_write(self, cr, uid, server, table, ids, vals, context):
90
"""Synchronize the fields defined in vals of the radiotv.table to Joomla PHP server.
91
Only the records with ids are exported.
92
New records are inserted, existing records are updated"""
93
pool = pooler.get_pool(cr.dbname)
94
obj = 'radiotv.'+table
95
tbl = 'radiotv_'+table
98
for field in vals.keys():
99
if field[-4:] == "_ids":
100
vals[field] = vals[field][0][2]
104
attach_ids = pool.get('ir.attachment').search(cr, uid, [('res_model','=',obj), ('res_id', '=',id)])
106
for data in pool.get('ir.attachment').browse(cr, uid, attach_ids, context):
107
s = data['datas_fname'].split('.')
108
extension = s[-1].lower()
111
#print name + " " + extension
112
if extension in ['jpeg', 'jpe', 'jpg', 'gif', 'png']:
113
if extension in ['jpeg', 'jpe', 'jpg']:
116
vals['picture'+str(cont)] = data['datas']
119
vals['picture'+str(cont)] = base64.encodestring(urllib.urlopen(data['link']).read())
122
vals['fname'+str(cont)] = name + '.' + extension
126
if server.set_table(tbl, vals):
134
def export_ulink(self, cr, uid, server, table, ids, table_rel=None, field_rel=None):
135
"""Synchronize the radiotv.table to Joomla PHP server.
136
Only the records with ids are deleted.
137
If table_rel and field_rel are defined, also deletes the records in the table_rel"""
138
tbl = 'radiotv_'+table
139
delete = server.delete_items(tbl, ids, "id")
140
if table_rel != None:
141
tbl = 'radiotv_'+table_rel
142
server.delete_items(tbl, ids, field_rel)