← Back to team overview

avanzosc team mailing list archive

Re: [Merge] lp:~mikelarregi/avanzosc/mysql_connect into lp:~avanzosc-security-team/avanzosc/72horas

 

Review: Needs Fixing code review

Comentarios inline.

Diff comments:

> === modified file 'dos_mysql_connect/__init__.py'
> --- dos_mysql_connect/__init__.py	2014-06-11 10:23:47 +0000
> +++ dos_mysql_connect/__init__.py	2014-06-18 15:40:12 +0000
> @@ -19,6 +19,6 @@
>  #
>  ##############################################################################
>  
> -import mysql_connect
> +from . import models
>  
>  # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
> 
> === modified file 'dos_mysql_connect/__openerp__.py'
> --- dos_mysql_connect/__openerp__.py	2014-06-11 10:23:47 +0000
> +++ dos_mysql_connect/__openerp__.py	2014-06-18 15:40:12 +0000
> @@ -20,21 +20,17 @@
>  ##############################################################################
>  
>  {
> -    "name" : "DOS MySql Connect",
> -    "version" : "1.0",
> -    "author" : "DOS",
> -    "category" : "Base",
> -    "website" : "www.dos-sl.es",
> +    "name": "DOS MySql Connect",
> +    "version": "1.0",
> +    "author": "DOS",
> +    "category": "Base",
> +    "website": "www.dos-sl.es",
>      "description": "This module allows you connect to a MySql database.",
> -    "depends" : ['base_tools'],
> -    "init_xml" : [],
> -    "update_xml" : [
> -					'security/mysql_connect_security.xml',
> -					'security/ir.model.access.csv',
> -					'mysql_connect_view.xml',
> -					],
> -    "active": False,
> +    "depends": ['base_tools'],
> +    "data": [
> +        'security/mysql_connect_security.xml',
> +        'security/ir.model.access.csv',
> +        'models/mysql_connect_view.xml',
> +    ],
>      "installable": True
>  }
> -
> -
> 
> === added directory 'dos_mysql_connect/models'
> === added file 'dos_mysql_connect/models/__init__.py'
> --- dos_mysql_connect/models/__init__.py	1970-01-01 00:00:00 +0000
> +++ dos_mysql_connect/models/__init__.py	2014-06-18 15:40:12 +0000
> @@ -0,0 +1,22 @@
> +# -*- 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 . import mysql_connect
> \ No newline at end of file
> 
> === renamed file 'dos_mysql_connect/mysql_connect.py' => 'dos_mysql_connect/models/mysql_connect.py'
> --- dos_mysql_connect/mysql_connect.py	2014-06-11 10:23:47 +0000
> +++ dos_mysql_connect/models/mysql_connect.py	2014-06-18 15:40:12 +0000
> @@ -19,99 +19,91 @@
>  #
>  ##############################################################################
>  
> -from osv import osv
> -from osv import fields
> -from tools.translate import _
> +from openerp.osv import orm, fields
> +from openerp.tools.translate import _
>  import time
>  import MySQLdb
>  
> -class mysql_connect(osv.osv): 
> -
> -	_name = 'mysql.connect'
> -	_description = 'MySql Connect'
> -
> -	_columns = {
> -		'host': fields.char('Host', size=256, required=True, help='MySql host server address .'),
> -		'database': fields.char('Database', size=128, required=True, help='Name of the MySql database.'),
> -		'user': fields.char('User', size=128, required=True, help='User access to the MySql database.'),
> -		'password': fields.char('Password', size=128, required=True, help='Password to access the MySql database.'),
> -	}
> -	
> -	def test_connection(self, cr, uid, ids, context=None):
> -		if context is None:
> -			context = {}
> -
> -		data = ""
> -		
> -		for obj_conn in self.browse(cr, uid, ids, context=context):
> -			try:
> -				db = MySQLdb.connect(host = obj_conn.host, user = obj_conn.user, passwd = obj_conn.password, db = obj_conn.database)
> -				
> -				cursor = db.cursor()
> -				
> -				cursor.execute("SELECT VERSION()")
> -				
> -				row = cursor.fetchone()
> -				
> -				data = row[0]
> -	
> -				db.close()
> -				
> -			except Exception,e:
> -				raise osv.except_osv(_('Error connecting !'), e) 
> -			
> -		raise osv.except_osv(_('Successful connection'), _('The connection configuration is correct!') + '\n\r' + _('MySql Version: ') + data)
> -	
> -		return True
> -	
> -	def open_connection(self, cr, uid):
> -	
> -		# Cargamos datos configuracion
> -		config_ids = self.search(cr, uid, [], limit=1)
> -		if config_ids:
> -			config = self.browse(cr, uid, config_ids[0])
> -		else:
> -			raise osv.except_osv(_('Error !'), _('First define the configuration parameters of the mySql connection.'))
> -		
> -		# Abrimos conexion
> -		try:
> -			db = MySQLdb.connect(host = config.host, user = config.user, passwd = config.password, db = config.database)
> -			return db
> -		except Exception,e:
> -			return None
> -			
> -	def close_connection(self, db):
> -	
> -		# Cerramos conexion
> -		if db:
> -			db.close
> -			
> -		return True
> -		 
> -	def get_customer_ref(self, cr, uid, db, phone_number):
> -		
> -		# Comprobamos que existe una conexion abierta
> -		if not db:
> -			raise osv.except_osv(_('Error !'), _('First open mySql connection.'))
> -			
> -		customer_refs = None
> -		
> -		try:
> -			cursor = db.cursor()
> -			
> -			cursor.execute ("SELECT ref_cliente FROM telefonos WHERE n_telefono = '" + str(phone_number) + "'")
> -			
> -			rows = cursor.fetchall()
> -			
> -			for row in rows:
> -				customer_ref = row[0]
> -				# Controlamos que la referencia obtenida no sea nula o ?
> -				if customer_ref and customer_ref != '?':
> -					customer_refs = customer_refs and (customer_refs + ', ' + customer_ref) or customer_ref
> -				
> -		except Exception,e:
> -			return None
> -		 
> -		return customer_refs
> -	
> -mysql_connect()
> +
> +class MysqlConnect(orm.Model):
> +
> +    _name = 'mysql.connect'
> +    _description = 'MySql Connect'
> +    _columns = {
> +        'host': fields.char('Host', size=256, required=True,
> +                            help='MySql host server address .'),
> +        'database': fields.char('Database', size=128, required=True,
> +                                help='Name of the MySql database.'),
> +        'user': fields.char('User', size=128, required=True,
> +                            help='User access to the MySql database.'),
> +        'password': fields.char('Password', size=128, required=True,
> +                                help='Password to access the MySql database.'),
> +    }
> +
> +    def test_connection(self, cr, uid, ids, context=None):
> +        if context is None:
> +            context = {}
> +        data = ""
> +        for obj_conn in self.browse(cr, uid, ids, context=context):
> +            try:
> +                db = MySQLdb.connect(host=obj_conn.host,
> +                                     user=obj_conn.user,
> +                                     passwd=obj_conn.password,
> +                                     db=obj_conn.database)
> +                cursor = db.cursor()
> +                cursor.execute("SELECT VERSION()")
> +                row = cursor.fetchone()
> +                data = row[0]
> +                db.close()
> +            except Exception, e:
> +                raise osv.except_osv(_('Error connecting !'), e)
> +        raise osv.except_osv(_('Successful connection'),

Aquí tiene que ser orm.except_orm

> +                             _('The connection configuration is correct!') +
> +                             '\n\r' + _('MySql Version: ') + data)
> +        return True
> +
> +    def open_connection(self, cr, uid, context=None):
> +        # Cargamos datos configuracion
> +        config_ids = self.search(cr, uid, [], limit=1)
> +        if config_ids:
> +            config = self.browse(cr, uid, config_ids[0], context=context)
> +        else:
> +            raise osv.except_osv(_('Error !'), _('First define the '
> +                                                 'configuration parameters of'
> +                                                 ' the mySql connection.'))
> +        # Abrimos conexion
> +        try:
> +            db = MySQLdb.connect(host=config.host, user=config.user,
> +                                 passwd=config.password,
> +                                 db=config.database)
> +            return db
> +        except Exception, e:
> +            return None
> +
> +    def close_connection(self, db):
> +        # Cerramos conexion
> +        if db:
> +            db.close
> +        return True
> +
> +    def get_customer_ref(self, cr, uid, db, phone_number):
> +        # Comprobamos que existe una conexion abierta
> +        if not db:
> +            raise osv.except_osv(_('Error !'),

orm.except_orm

> +                                 _('First open mySql connection.'))
> +        customer_refs = None
> +        try:
> +            cursor = db.cursor()
> +            cursor.execute("SELECT ref_cliente FROM telefonos "
> +                           "WHERE n_telefono = '" + str(phone_number) + "'")
> +            rows = cursor.fetchall()
> +            for row in rows:
> +                customer_ref = row[0]
> +                # Controlamos que la referencia obtenida no sea nula o ?
> +                if customer_ref and customer_ref != '?':
> +                    customer_refs = (customer_refs
> +                                     and (customer_refs + ', ' + customer_ref)
> +                                     or customer_ref)
> +        except Exception, e:
> +            return None
> +        return customer_refs
> 
> === added directory 'dos_mysql_connect/views'
> === renamed file 'dos_mysql_connect/mysql_connect_view.xml' => 'dos_mysql_connect/views/mysql_connect_view.xml'


-- 
https://code.launchpad.net/~mikelarregi/avanzosc/mysql_connect/+merge/223592
Your team Avanzosc_security is subscribed to branch lp:~avanzosc-security-team/avanzosc/72horas.


References