Browse Source

Fix pep8

pull/7/head
Sandy Carter 11 years ago
parent
commit
ee828486b2
  1. 5
      base_address_category/__openerp__.py
  2. 18
      base_address_category/base_address.py
  3. 3
      base_partner_surname/__init__.py
  4. 5
      base_partner_surname/__openerp__.py
  5. 3
      base_partner_surname/partner.py
  6. 22
      partner_address_ldap/__openerp__.py
  7. 70
      partner_address_ldap/address.py
  8. 3
      partner_address_ldap/company.py
  9. 5
      partner_address_ldap/partner.py
  10. 24
      partner_address_ldap/wizard/wiz_import_adresses.py

5
base_address_category/__openerp__.py

@ -31,8 +31,9 @@
{
"name": "Partner Adress Category",
"description" : """Add categories on Address like there is on Partner. This is interesting for managing mailling list based on address
for example.
"description": """
Add categories on Address like there is on Partner.
This is interesting for managing mailling list based on address for example.
""",
"version": "1.2",
"author": "Camptocamp",

18
base_address_category/base_address.py

@ -30,9 +30,10 @@
##############################################################################
from osv import osv, fields
from openerp.osv import orm, fields
class ResPartnerAdressCategory(osv.osv):
class ResPartnerAdressCategory(orm.Model):
def name_get(self, cr, uid, ids, context={}):
if not len(ids):
return []
@ -48,6 +49,7 @@ class ResPartnerAdressCategory(osv.osv):
def _name_get_fnc(self, cr, uid, ids, prop, unknow_none, unknow_dict):
res = self.name_get(cr, uid, ids)
return dict(res)
def _check_recursion(self, cr, uid, ids):
level = 100
while len(ids):
@ -59,8 +61,6 @@ class ResPartnerAdressCategory(osv.osv):
level -= 1
return True
_description = 'Partner address Categories'
_name = 'res.partner.address.category'
_columns = {
@ -81,11 +81,17 @@ class ResPartnerAdressCategory(osv.osv):
ResPartnerAdressCategory()
class ResPartnerAddress(osv.osv):
class ResPartnerAddress(orm.Model):
_inherit = "res.partner.address"
_columns = {
'category_id': fields.many2many('res.partner.address.category', 'res_partner_address_category_rel', 'adress_id', 'category_id', 'Adress categories'),
'category_id': fields.many2many(
'res.partner.address.category',
'res_partner_address_category_rel',
'adress_id',
'category_id',
'Adress categories',
),
}
ResPartnerAddress()

3
base_partner_surname/__init__.py

@ -18,6 +18,5 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import partner
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
from . import partner

5
base_partner_surname/__openerp__.py

@ -25,7 +25,8 @@
"website": "http://www.openerp.com",
"category": "Generic Modules/Base",
"description": """
This module is used for separate surname from contact name of partner. Now You can give first name & last name on contact Name.
This module is used for separate surname from contact name of partner. Now You
can give first name & last name on contact Name.
This module is deprecated, it is highly recommended to use base_contact instead.
""",
@ -36,5 +37,3 @@ This module is deprecated, it is highly recommended to use base_contact instead.
"installable": True,
"auto_install": False
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

3
base_partner_surname/partner.py

@ -71,6 +71,3 @@ class res_partner_address(orm.Model):
if first_name or last_name:
res = {'name': first_name + ' ' + last_name}
return {'value': res}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

22
partner_address_ldap/__openerp__.py

@ -41,27 +41,33 @@
"description": """
Live partner address synchronization through a LDAP module (inetOrgPerson).
OpenERP becomes the master of the LDAP. Each time an address is deleted, created or updated the same is done in the ldap (a new record is pushed).
The LDAP configuration is done in the company view. There can be one different LDAP per company. Do not forget to activate
the LDAP link in the configuration.
OpenERP becomes the master of the LDAP. Each time an address is deleted,
created or updated the same is done in the ldap (a new record is pushed).
The LDAP configuration is done in the company view. There can be one different
LDAP per company. Do not forget to activate the LDAP link in the configuration.
The used LDAP depends on the current user company.
This module does not allows bulk batching synchronisation into the LDAP and is thus not suitable for an instant use with an existing LDAP.
In order to use it with an existing LDAP you have to alter the uid of contact in your LDAP. The uid should be terp_ plus the OpenERP
This module does not allows bulk batching synchronisation into the LDAP and is
thus not suitable for an instant use with an existing LDAP.
In order to use it with an existing LDAP you have to alter the uid of contact
in your LDAP. The uid should be terp_ plus the OpenERP
contact id (for example terp_10).
N.B:
The module requires the python-ldap library
Unicode support --> As python ldap does not support unicode we try to decode string if it fails we transliterate values.
Unicode support --> As python ldap does not support unicode we try to decode
string if it fails we transliterate values.
Active Directory Support for Windows server 2003, try 2008 at your own risk
(AD support not tested for Version 6 of OpenERP looking for active dir test infra)
""",
"init_xml": ["security/security.xml"],
"update_xml":['company_view.xml',
"update_xml": [
'company_view.xml',
'address_view.xml',
"wizard.xml"],
"wizard.xml",
],
"demo_xml": [],
"active": False,
"installable": True

70
partner_address_ldap/address.py

@ -30,27 +30,30 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
#TODO FInd why company parameter are cached
# TODO Find why company parameter are cached
import re
import unicodedata
import netsvc
try:
import ldap
import ldap.modlist
except :
print 'python ldap not installed please install it in order to use this module'
except ImportError:
print('python ldap not installed please install it in order to use this module')
from osv import osv, fields
from openerp.osv import orm, fields
from tools.translate import _
logger = netsvc.Logger()
class LdapConnMApper(object):
"""LdapConnMApper: push specific fields from the Terp Partner_contacts to the
LDAP schema inetOrgPerson. Ldap bind options are stored in company.r"""
LDAP schema inetOrgPerson. Ldap bind options are stored in company.
"""
def __init__(self, cursor, uid, osv_obj, context=None):
"""Initialize connexion to ldap by using parameter set in the current user compagny"""
"""Initialize connexion to ldap by using parameter set in the current user company"""
logger.notifyChannel("MY TOPIC", netsvc.LOG_DEBUG,
_('Initalize LDAP CONN'))
self.USER_DN = ''
@ -79,7 +82,7 @@ class LdapConnMApper(object):
if company.ldap_active:
for param in mand:
if not param:
raise osv.except_osv(_('Warning !'),
raise orm.except_orm(_('Warning !'),
_('An LDAP parameter is missing for company %s') % (company.name,))
def get_connexion(self):
@ -94,7 +97,7 @@ class LdapConnMApper(object):
return self.connexion
class LDAPAddress(osv.osv):
class LDAPAddress(orm.Model):
"""Override the CRUD of the objet in order to dynamically bind to ldap"""
_inherit = 'res.partner.address'
ldapMapper = None
@ -108,7 +111,7 @@ class LDAPAddress(osv.osv):
'column name to lastname ;'))
cr.execute('ALTER TABLE res_partner_address RENAME column name to lastname ;')
except Exception, e:
except Exception:
cr.rollback()
logger.notifyChannel(_('LDAP address init'),
netsvc.LOG_INFO,
@ -129,7 +132,7 @@ class LDAPAddress(osv.osv):
reads = self.read(cursor, uid, ids, ['lastname', 'firstname'])
res = []
for record in reads:
## We want to have " firstname" or ""
# We want to have " firstname" or ""
name = self._compute_name(record['firstname'], record['lastname'])
res.append((record['id'], name))
return dict(res)
@ -160,7 +163,6 @@ class LDAPAddress(osv.osv):
# res.append(add.id)
# return self.name_get(cursor, user, res, context)
_columns = {
'firstname': fields.char('First name', size=256),
'lastname': fields.char('Last name', size=256),
@ -172,7 +174,7 @@ class LDAPAddress(osv.osv):
'private_phone': fields.char('Private phone', size=128),
}
def create(self, cursor, uid, vals, context={}):
def create(self, cursor, uid, vals, context=None):
self.getconn(cursor, uid, {})
ids = None
self.validate_entries(vals, cursor, uid, ids)
@ -189,7 +191,7 @@ class LDAPAddress(osv.osv):
ids = [ids]
if ids:
self.validate_entries(vals, cursor, uid, ids)
if context.has_key('init_mode') and context['init_mode'] :
if context.get('init_mode'):
success = True
else:
success = super(LDAPAddress, self).write(cursor, uid, ids,
@ -200,7 +202,8 @@ class LDAPAddress(osv.osv):
return success
def unlink(self, cursor, uid, ids, context=None):
if not context: context = {}
if context is None:
context = {}
if ids:
self.getconn(cursor, uid, {})
if not isinstance(ids, list):
@ -230,12 +233,11 @@ class LDAPAddress(osv.osv):
phone = vals.get('phone', False)
fax = vals.get('fax', False)
mobile = vals.get('mobile', False)
lastname = vals.get('lastname', False)
private_phone = vals.get('private_phone', False)
if email:
if re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$",
email) is None:
raise osv.except_osv(_('Warning !'),
raise orm.except_orm(_('Warning !'),
_('Please enter a valid e-mail'))
phones = (('phone', phone), ('fax', fax), ('mobile', mobile),
('private_phone', private_phone))
@ -243,15 +245,16 @@ class LDAPAddress(osv.osv):
phone_number = phone_tuple[1]
if phone_number:
if not phone_number.startswith('+'):
raise osv.except_osv(_('Warning !'),
raise orm.except_orm(_('Warning !'),
_('Please enter a valid phone number in %s'
' international format (i.e. leading +)') % phone_tuple[0])
def getVals(self, att_name, key, vals, dico, uid, ids, cursor, context=None):
"""map to values to dict"""
if not context: context = {}
## We explicitely test False value
if vals.get(key, False) != False:
if context is None:
context = {}
# We explicitely test False value
if vals.get(key, False) is not False:
dico[att_name] = vals[key]
else:
if context.get('init_mode'):
@ -260,12 +263,11 @@ class LDAPAddress(osv.osv):
if tmp.get(key, False):
dico[att_name] = tmp[key]
def _un_unicodize_buf(self, in_buf):
if isinstance(in_buf, unicode):
try:
return in_buf.encode()
except Exception, e:
except Exception:
return unicodedata.normalize("NFKD", in_buf).encode('ascii', 'ignore')
return in_buf
@ -282,7 +284,6 @@ class LDAPAddress(osv.osv):
indict[key] = nonutfArray
def addNeededFields(self, id, vals, cursor, uid):
keys = vals.keys()
previousvalue = self.browse(cursor, uid, [id])[0]
if not vals.get('partner_id'):
vals['partner_id'] = previousvalue.partner_id.id
@ -296,7 +297,6 @@ class LDAPAddress(osv.osv):
"""Mapp ResPArtner adress to moddlist"""
self.addNeededFields(id, vals, cursor, uid)
conn = self.getconn(cursor, uid, {})
keys = vals.keys()
partner_obj = self.pool.get('res.partner')
part_name = partner_obj.browse(cursor, uid, vals['partner_id']).name
vals['partner'] = part_name
@ -348,7 +348,7 @@ class LDAPAddress(osv.osv):
self.getVals('company', 'partner', vals, contact_obj, uid, id, cursor, context)
self.getVals('info', 'comment', vals, contact_obj, uid, id, cursor, context)
self.getVals('displayName', 'partner', vals, contact_obj, uid, id, cursor, context)
## Web site management
# Web site management
if self.browse(cursor, uid, id).partner_id.website:
vals['website'] = self.browse(cursor, uid, id).partner_id.website
self.getVals('wWWHomePage', 'website', vals, contact_obj, uid, id, cursor, context)
@ -381,8 +381,8 @@ class LDAPAddress(osv.osv):
else:
conn.connexion.add_s("uid=terp_%s,OU=%s,%s" % (str(id), conn.OU, conn.CONTACT_DN),
ldap.modlist.addModlist(contact_obj))
except Exception, e:
raise e
except Exception:
raise
conn.connexion.unbind_s()
def updateLdapContact(self, id, vals, cursor, uid, context):
@ -407,8 +407,8 @@ class LDAPAddress(osv.osv):
try:
conn.connexion.modify_s(old_contatc_obj[0], modlist)
conn.connexion.unbind_s()
except Exception, e:
raise e
except Exception:
raise
def removeLdapContact(self, id, cursor, uid):
"""Remove a contact from ldap"""
@ -419,14 +419,14 @@ class LDAPAddress(osv.osv):
except ldap.NO_SUCH_OBJECT:
logger.notifyChannel("Warning", netsvc.LOG_INFO,
_("'no object to delete in ldap' %s") % (id))
except Exception, e :
raise e
except Exception:
raise
try:
if to_delete:
conn.connexion.delete_s(to_delete[0])
conn.connexion.unbind_s()
except Exception, e:
raise e
except Exception:
raise
def getLdapContact(self, conn, id):
result = conn.connexion.search_ext_s("ou=%s,%s" % (conn.OU, conn.CONTACT_DN),

3
partner_address_ldap/company.py

@ -33,6 +33,7 @@
from osv import osv, fields
class Res_company(osv.osv):
"""Defin ldap connexion parameters"""
@ -46,7 +47,7 @@ class Res_company(osv.osv):
'contact_dn': fields.char(
'Bind dn',
size=128,
help="Exemple: dc=ldap,dc=dcc2c -- watchout" +\
help="Exemple: dc=ldap,dc=dcc2c -- watchout"
" the OU will be automatically included inside"
),
'ounit': fields.char(

5
partner_address_ldap/partner.py

@ -31,9 +31,10 @@
#
##############################################################################
from osv import osv, fields
from openerp.osv import orm
class LdapPartner(osv.osv):
class LdapPartner(orm.Model):
"""Ensure that when deleting a partner unlink function is called on all
related addresses"""
_inherit = 'res.partner'

24
partner_address_ldap/wizard/wiz_import_adresses.py

@ -61,9 +61,10 @@ _FIELDS = {
},
}
### As this is a bulck batch wizzard the performance process was not reallay taken in account ###
##The ideal way of doing would be to modify the connexion settings in order to have a connexion singelton
## in the file partner.py it will avoid connexion renegotiation for each partner.
# As this is a bulck batch wizard the performance process was not reallay taken in account
# The ideal way of doing would be to modify the connexion settings in order to have a connexion singelton
# in the file partner.py it will avoid connexion renegotiation for each partner.
def _action_import_adresses(self, cr, uid, data, context):
""" This function create or update each adresses present in the database.
It will also genreate an error report"""
@ -71,7 +72,7 @@ def _action_import_adresses(self, cr, uid, data, context):
error_report = [u'Error report']
add_obj = pooler.get_pool(cr.dbname).get('res.partner.address')
add_ids = add_obj.search(cr, uid, [])
addresses = add_obj.browse(cr, uid, add_ids)
addresses = add_obj.browse(cr, uid, add_ids, context=context)
phone_fields = ['phone', 'fax', 'mobile', 'private_phone']
for add in addresses:
vals = {}
@ -113,10 +114,8 @@ def _action_import_adresses(self, cr, uid, data, context):
error_report.append(msg)
# Validating the CN
if not add.lastname and add.firstname:
msg = u'!!! Addresse %s for partner %s has no last name and first name that is valid partner name was used'%(
unicode(add.id),
add.partner_id.name,
)
msg = (u'!!! Address %s for partner %s has no last name and first name that is valid partner name was used'
% (unicode(add.id), add.partner_id.name))
logger.notifyChannel('ldap export', netsvc.LOG_INFO, msg)
error_report.append(msg)
# We save to LDAP
@ -127,11 +126,12 @@ def _action_import_adresses(self, cr, uid, data, context):
logger.notifyChannel("MY TOPIC", netsvc.LOG_ERROR, error_report)
try:
data = base64.encodestring(error_report.encode())
except Exception, e:
except Exception:
data = base64.encodestring("Could not generate report file. Please look in the log for details")
return {'errors': data}
class Wiz_import_addresses(wizard.interface):
states = {
'init': {
@ -142,8 +142,8 @@ class Wiz_import_addresses(wizard.interface):
'fields': {},
'state': [
('end', 'Cancel'),
('importadd','Export adresses into company LDAP')
]
('importadd', 'Export adresses into company LDAP'),
],
}
},
'importadd': {
@ -152,7 +152,7 @@ class Wiz_import_addresses(wizard.interface):
'state': [('end', 'OK', 'gtk-ok', True)],
'arch': _FORM1,
'fields': _FIELDS,
'type':'form'
'type': 'form',
}
}
}

Loading…
Cancel
Save