From a8d87655c74e4b096d85c5e71cf4c2a004fece49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 19 Aug 2010 22:12:44 +0200 Subject: [PATCH] Update for new Transaction --- INSTALL | 2 +- address.py | 28 ++++++++++++---------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/INSTALL b/INSTALL index 698e17d305..250fae3a4c 100644 --- a/INSTALL +++ b/INSTALL @@ -4,7 +4,7 @@ Installing trytond_google_maps Prerequisites ------------- - * Python 2.4 or later (http://www.python.org/) + * Python 2.5 or later (http://www.python.org/) * trytond (http://www.tryton.org/) * trytond_party (http://www.tryton.org/) diff --git a/address.py b/address.py index 5b5f99ae73..c48d98b331 100644 --- a/address.py +++ b/address.py @@ -1,7 +1,9 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from trytond.model import ModelView, ModelSQL, fields import urllib +from trytond.model import ModelView, ModelSQL, fields +from trytond.transaction import Transaction + class Address(ModelSQL, ModelView): _name = 'party.address' @@ -10,10 +12,8 @@ class Address(ModelSQL, ModelView): on_change_with=['street', 'streetbis', 'zip', 'city', 'country', 'subdivision']), 'get_google_maps_url') - def _get_url(self, cursor, user, vals, context=None): - if context is None: - context = {} - lang = context.get('language', 'en_US')[:2] + def _get_url(self, vals): + lang = Transaction().language[:2] url = '' for i in ['street', 'streetbis', 'zip', 'city', 'country', 'subdivision']: @@ -29,28 +29,25 @@ class Address(ModelSQL, ModelView): url = '' return url - def on_change_with_google_maps_url(self, cursor, user, vals, - context=None): + def on_change_with_google_maps_url(self, vals): country_obj = self.pool.get('country.country') subdivision_obj = self.pool.get('country.subdivision') vals = vals.copy() if vals.get('country'): - country = country_obj.browse(cursor, user, vals['country'], - context=context) + country = country_obj.browse(vals['country']) vals['country'] = country.name if vals.get('subdivision'): - subdivision = subdivision_obj.browse(cursor, user, - vals['subdivision'], context=context) + subdivision = subdivision_obj.browse(vals['subdivision']) vals['subdivision'] = subdivision.name - return self._get_url(cursor, user, vals, context=context) + return self._get_url(vals) - def get_google_maps_url(self, cursor, user, ids, name, context=None): + def get_google_maps_url(self, ids, name): res = {} - for address in self.browse(cursor, user, ids, context=context): + for address in self.browse(ids): vals = { 'street': address.street, 'streetbis': address.streetbis, @@ -60,8 +57,7 @@ class Address(ModelSQL, ModelView): 'subdivision': address.subdivision and \ address.subdivision.name or False, } - res[address.id] = self._get_url(cursor, user, vals, - context=context) + res[address.id] = self._get_url(vals) return res Address()