[ADD] google_contact: Added a wizard to import google contacts.
bzr revid: uco@tinyerp.com-20110210112805-kijvixuhavnghuck
This commit is contained in:
@@ -20,5 +20,7 @@
|
||||
##############################################################################
|
||||
|
||||
import google_contact
|
||||
import wizard
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
||||
@@ -30,7 +30,8 @@
|
||||
'depends': ['base'],
|
||||
'init_xml': [],
|
||||
'update_xml': [
|
||||
# 'google_contact_view.xml'
|
||||
#'google_contact_view.xml',
|
||||
'wizard/google_contact_import_view.xml'
|
||||
],
|
||||
'demo_xml': [],
|
||||
'installable': True,
|
||||
|
||||
@@ -20,10 +20,11 @@
|
||||
##############################################################################
|
||||
|
||||
from osv import fields,osv,orm
|
||||
from tools.translate import _
|
||||
|
||||
try:
|
||||
import gdata
|
||||
from gdata import contacts
|
||||
from gdata import contacts
|
||||
import gdata.contacts.service
|
||||
except ImportError:
|
||||
raise osv.except_osv(_('Google Contacts Import Error!'), _('Please install gdata-python-client from http://code.google.com/p/gdata-python-client/downloads/list'))
|
||||
@@ -36,10 +37,16 @@ class google_lib(object):
|
||||
self.contact.email = email
|
||||
self.contact.password = password
|
||||
self.contact.source = 'GoogleInc-ContactsPythonSample-1'
|
||||
self.contact.ProgrammaticLogin()
|
||||
try:
|
||||
self.contact.ProgrammaticLogin()
|
||||
except Exception, e:
|
||||
raise osv.except_osv(_('Error!'),_('%s' % (e)))
|
||||
|
||||
def _get_contact(self):
|
||||
feed= self.contact.GetContactsFeed()
|
||||
def _get_contact(self, href=''):
|
||||
if href:
|
||||
feed = self.contact.GetContactsFeed(href)
|
||||
else:
|
||||
feed = self.contact.GetContactsFeed()
|
||||
return feed
|
||||
|
||||
def _get_contact_allGroups(self):
|
||||
@@ -59,28 +66,5 @@ class google_lib(object):
|
||||
self.contact.DeleteContact(selected_entry.GetEditLink().href)
|
||||
return True
|
||||
|
||||
class google_contact(osv.osv):
|
||||
_description ='Google Contact'
|
||||
_name = 'google.contact'
|
||||
_columns = {
|
||||
'user': fields.char('Login', size=64, required=True,),
|
||||
'password': fields.char('Password', size=64,),
|
||||
}
|
||||
def get_contact(self, cr, uid, ids, context):
|
||||
# Only see the result , we will change the code
|
||||
for obj in self.browse(cr, uid, ids, context=context):
|
||||
google_obj=google_lib(obj.user,obj.password)
|
||||
contact=google_obj._get_contact()
|
||||
while contact:
|
||||
for i, contact in enumerate(contact.entry):
|
||||
if contact.title.text:
|
||||
print contact.title.text
|
||||
next = contact.GetNextLink()
|
||||
contact=None
|
||||
if next:
|
||||
contact = google_obj._get_contact(next.href)
|
||||
return {}
|
||||
google_contact()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import google_contact_import
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -0,0 +1,74 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import fields,osv,orm
|
||||
from tools.translate import _
|
||||
|
||||
from google_contact import google_contact
|
||||
|
||||
class google_contact_import(osv.osv_memory):
|
||||
_description ='Google Contact'
|
||||
_name = 'google.contact.import'
|
||||
_columns = {
|
||||
'user': fields.char('User Name', size=64, required=True),
|
||||
'password': fields.char('Password', size=64),
|
||||
}
|
||||
|
||||
def get_contact(self, cr, uid, ids, context=None):
|
||||
# Only see the result, we will change the code
|
||||
addresss_obj = self.pool.get('res.partner.address')
|
||||
for obj in self.browse(cr, uid, ids, context=context):
|
||||
google_obj = google_contact.google_lib(obj.user, obj.password)
|
||||
contact = google_obj._get_contact()
|
||||
addresses = []
|
||||
while contact:
|
||||
for entry in contact.entry:
|
||||
name = entry.title.text
|
||||
phone_numbers = ','.join(phone_number.text for phone_number in entry.phone_number)
|
||||
emails = ','.join(email.address for email in entry.email)
|
||||
data = {
|
||||
'name': name,
|
||||
'phone': phone_numbers,
|
||||
'email': emails
|
||||
}
|
||||
contact_ids = addresss_obj.search(cr, uid, [('email','ilike',emails)])
|
||||
if not contact_ids:
|
||||
addresses.append(addresss_obj.create(cr, uid, data, context=context))
|
||||
if not contact:
|
||||
break
|
||||
next = contact.GetNextLink()
|
||||
contact = None
|
||||
if next:
|
||||
contact = google_obj._get_contact(next.href)
|
||||
return {
|
||||
'name': _('Contacts'),
|
||||
'domain': "[('id','in',"+str(addresses)+")]",
|
||||
'view_type': 'form',
|
||||
'view_mode': 'tree,form',
|
||||
'res_model': 'res.partner.address',
|
||||
'context': context,
|
||||
'views': [(False, 'tree'),(False, 'form')],
|
||||
'type': 'ir.actions.act_window',
|
||||
}
|
||||
|
||||
google_contact_import()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record model="ir.ui.view" id="view_google_contact_import_form">
|
||||
<field name="name">google.contact.import.form</field>
|
||||
<field name="model">google.contact.import</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Import Google Contacts">
|
||||
<group colspan="4" col="4">
|
||||
<field name="user"/>
|
||||
<newline/>
|
||||
<label string="ex: user@gmail.com" align="1.0" colspan="2"/>
|
||||
<newline/>
|
||||
<field name="password" password="True"/>
|
||||
</group>
|
||||
<separator string="" colspan="4"/>
|
||||
<group colspan="2" col="2">
|
||||
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
|
||||
<button name="get_contact" string="Import Contacts" type="object" icon="terp-personal+"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.actions.act_window" id="act_google_contact_import_form">
|
||||
<field name="name">Import Google Contacts</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">google.contact.import</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
<field name="view_id" ref="view_google_contact_import_form"/>
|
||||
</record>
|
||||
|
||||
<menuitem name="Import Google Contacts" id="menu_google_contact"
|
||||
parent="base.menu_address_book" action="act_google_contact_import_form"
|
||||
sequence="10" />
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
Reference in New Issue
Block a user