Devishree Brahmbhatt (OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-import_google-backlog-3_correction-dbr 
into lp:~openerp-dev/openobject-addons/trunk-import_google.

Requested reviews:
  Bhumika (OpenERP) (sbh-openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-import_google-backlog-3_correction-dbr/+merge/65323

Hello Ma'm,

I have improve code as per Backlog 3.

Thanks. 
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-import_google-backlog-3_correction-dbr/+merge/65323
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-import_google.
=== modified file 'import_google/wizard/import_google.py'
--- import_google/wizard/import_google.py	2011-06-16 10:21:05 +0000
+++ import_google/wizard/import_google.py	2011-06-21 09:31:11 +0000
@@ -22,6 +22,7 @@
 import re
 import urllib
 import dateutil
+import pytz
 from dateutil import *
 from pytz import timezone
 from datetime import datetime
@@ -38,56 +39,51 @@
 from import_base.mapper import *
 
 class google_import(import_framework):
-    
+
     gd_client = False
     calendars = False
     DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
     TABLE_CONTACT = 'Contact'
     TABLE_ADDRESS ='Address'
     TABLE_EVENT = 'Events'
-   
+
     def initialize(self):
         google = self.obj.pool.get('google.login')
         self.external_id_field = 'Id'
-        self.gd_client = google.google_login(self.context.get('user'), 
-                                       self.context.get('password'), 
+        self.gd_client = google.google_login(self.context.get('user'),
+                                       self.context.get('password'),
                                         self.context.get('instance'))
-        
+
         if self.context.get('instance') and self.context.get('instance') == 'contact':
-            self.contact = self.context.get('contact') 
+            self.contact = self.context.get('contact')
         if self.context.get('instance') and self.context.get('instance') == 'calendar':
-            self.calendars = self.context.get('calendars') 
-        
+            self.calendars = self.context.get('calendars')
+
     def get_mapping(self):
-        return { 
+        return {
             self.TABLE_EVENT: self.get_event_mapping(),
             self.TABLE_CONTACT: self.get_contact_mapping(),
             self.TABLE_ADDRESS: self.get_address_mapping(),
         }
-        
+
     def get_data(self, table):
-        if table == "Contact":
-            val = {
-                self.TABLE_CONTACT: self.get_contact(),
-            }
-        if table == "Address":
-            val = {
-                self.TABLE_ADDRESS: self.get_contact(),
-            }
-        elif table == "Events":
-            val = {
-                self.TABLE_EVENT: self.get_events(),
-            }
-        return val.get(table)
-    
-
-    def _get_tinydates(self, stime, etime):
+        data_fetching_function = {
+              self.TABLE_CONTACT: self.get_contact,
+              self.TABLE_ADDRESS: self.get_contact,
+              self.TABLE_EVENT: self.get_events,
+        }
+
+        return data_fetching_function.get(table)()
+
+
+    def _get_tinydates(self, stime, etime,context):
         stime = dateutil.parser.parse(stime)
         etime = dateutil.parser.parse(etime)
         try:
-            au_dt = au_tz.normalize(stime.astimezone(au_tz))
+            au_tz = context.get('au_tz')
+            au_dt = au_tz.normalize(stime.replace(tzinfo=pytz.utc).astimezone(au_tz))
             timestring = datetime.datetime(*au_dt.timetuple()[:6]).strftime('%Y-%m-%d %H:%M:%S')
-            au_dt = au_tz.normalize(etime.astimezone(au_tz))
+            au_dt = au_tz.normalize(etime.replace(tzinfo=pytz.utc).astimezone(au_tz))
             timestring_end = datetime.datetime(*au_dt.timetuple()[:6]).strftime('%Y-%m-%d %H:%M:%S')
         except:
             timestring = datetime.datetime(*stime.timetuple()[:6]).strftime('%Y-%m-%d %H:%M:%S')
@@ -191,14 +187,16 @@
         else:
             time_zone = tools.get_server_timezone()
         au_tz = timezone(time_zone)
-        event_vals = []            
+        context = self.context
+        context.update({'au_tz':au_tz})
+        event_vals = []
         for cal in self.calendars:
             events_query = gdata.calendar.service.CalendarEventQuery(user=urllib.unquote(cal.split('/')[~0]))
             events_query.start_index = 1
             events_query.max_results = 1000
             event_feed = self.gd_client.GetCalendarEventFeed(events_query.ToUri())
             for feed in event_feed.entry:
-                event = {            
+                event = {
                     'recurrency': "0",
                     'end_date' : False,
                     'end_type' : False,
@@ -214,7 +212,7 @@
 
                 timestring = timestring_end = datetime.datetime.now().strftime(self.DATETIME_FORMAT)
                 if feed.when:
-                    timestring, timestring_end = self._get_tinydates(feed.when[0].start_time, feed.when[0].end_time)
+                    timestring, timestring_end = self._get_tinydates(feed.when[0].start_time, feed.when[0].end_time,context)
                 else:
                     x = feed.recurrence.text.split(';')
                     repeat_status = self._get_repeat_status(feed.recurrence.text)
@@ -226,11 +224,11 @@
                         event.update(repeat_status)
 
                 event.update({'id' : feed.id.text,
-                              'DateStart': timestring, 
+                              'DateStart': timestring,
                               'DateEnd': timestring_end,
                               'Category':event_feed.title.text,
                               'Name': feed.title.text or 'No title',
-                              'Description': feed.content.text, 
+                              'Description': feed.content.text,
                               })
                 event_vals.append(event)
         return event_vals
@@ -246,7 +244,7 @@
         if val.get("recurrency"):
             val.update({"recurrency": "1"})
         return val
-    
+
     def get_event_mapping(self):
         return {
             'model': 'crm.meeting',
@@ -275,15 +273,15 @@
 
 
     def get_contact(self):
-        table = self.context.get('table')[0] 
-        datas = [] 
+        table = self.context.get('table')[0]
+        datas = []
         if self.context.get('group_name'):
             query = gdata.contacts.service.ContactsQuery()
             query.group = self.context.get('group_name')
             self.contact = self.gd_client.GetContactsFeed(query.ToUri())
-        else: 
-            self.contact = self.gd_client.GetContactsFeed()   
-        while self.contact: 
+        else:
+            self.contact = self.gd_client.GetContactsFeed()
+        while self.contact:
             for entry in self.contact.entry:
                 data = {}
                 data['id'] = entry.id.text
@@ -308,12 +306,12 @@
                         if phone.rel == gdata.contacts.PHONE_MOBILE:
                             data['mobile'] = phone.text
                         if phone.rel == gdata.contacts.PHONE_WORK_FAX:
-                            data['fax'] = phone.text 
-                datas.append(data)        
+                            data['fax'] = phone.text
+                datas.append(data)
             next = self.contact.GetNextLink()
-            self.contact = next and self.gd_client.GetContactsFeed(next.href) or None     
+            self.contact = next and self.gd_client.GetContactsFeed(next.href) or None
         return datas
-     
+
     def get_partner_address(self,val):
         partner_id = False
         address_pool = self.obj.pool.get('res.partner.address')
@@ -337,7 +335,7 @@
         val.update({'Type':'contact'})
         val.update({'id_new': val['id']+'address_contact' })
         return self.import_object_mapping(field_map , val, 'res.partner.address', self.context.get('table')[0], val['id_new'], self.DO_NOT_FIND_DOMAIN)
-        
+
     def get_contact_mapping(self):
         return {
             'model': 'res.partner',
@@ -349,8 +347,8 @@
                 'supplier': 'supplier',
                 'address/id': self.get_partner_address,
                 }
-            }   
-                    
+            }
+
     def get_address_mapping(self):
         return {
             'model': 'res.partner.address',
@@ -365,6 +363,5 @@
                 'fax': 'fax',
                 'function': 'function'
                 }
-        
+
         }
-

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to