Review: Needs Fixing code review

Algunos comentarios inline.

Un saludo.

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-16 14:24:00 +0000
> @@ -19,6 +19,6 @@
>  #
>  
> ##############################################################################
>  
> -import mysql_connect
> +from . import mysql_connect
>  
>  # 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-16 14:24:00 +0000
> @@ -20,21 +20,18 @@
>  
> ##############################################################################
>  
>  {
> -    "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',
> -                                     ],
> +    "depends": ['base_tools'],
> +    "data": [
> +        'security/mysql_connect_security.xml',
> +        'security/ir.model.access.csv',
> +        'models/mysql_connect_view.xml',
> +    ],
>      "active": False,

active ya no es una clave válida (ahora es auto_install, que no hace la misma 
función tampoco). Mejor quitarla

>      "installable": True
>  }
> -
> -
> 
> === added directory 'dos_mysql_connect/models'
> === added file 'dos_mysql_connect/models/mysql_connect.py'
> --- dos_mysql_connect/models/mysql_connect.py 1970-01-01 00:00:00 +0000
> +++ dos_mysql_connect/models/mysql_connect.py 2014-06-16 14:24:00 +0000
> @@ -0,0 +1,109 @@
> +# -*- 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 openerp.osv import orm, fields
> +from openerp.tools.translate import _
> +import time
> +import MySQLdb
> +
> +
> +class MysqlConnect(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)

orm.except_orm

> +        raise osv.except_osv(_('Successful connection'),

orm.except_orm

> +                             _('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 !'),

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
> 
> === removed file 'dos_mysql_connect/mysql_connect.py'
> --- dos_mysql_connect/mysql_connect.py        2014-06-11 10:23:47 +0000
> +++ dos_mysql_connect/mysql_connect.py        1970-01-01 00:00:00 +0000
> @@ -1,117 +0,0 @@
> -# -*- 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 osv
> -from osv import fields
> -from 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()
> 
> === removed file 'dos_mysql_connect/mysql_connect_view.xml'
> --- dos_mysql_connect/mysql_connect_view.xml  2014-06-11 10:23:47 +0000
> +++ dos_mysql_connect/mysql_connect_view.xml  1970-01-01 00:00:00 +0000
> @@ -1,67 +0,0 @@
> -<?xml version="1.0" encoding="utf-8"?>
> -<openerp>
> -     <data>
> -     
> -             <!-- MySql Config Search View-->
> -        <record id="view_mysql_config_search" model="ir.ui.view">
> -            <field name="name">view.mysql.config.search</field>
> -            <field name="model">mysql.connect</field>
> -            <field name="type">search</field>
> -            <field name="arch" type="xml">
> -                <search string="Search">
> -                    <field name="host" select="1"/>
> -                    <field name="database" select="1"/>
> -               </search>
> -            </field>
> -        </record>
> -        
> -             <!-- MySql Config Tree View-->
> -        <record id="view_mysql_config_tree" model="ir.ui.view">
> -            <field name="name">view.mysql.config.tree</field>
> -            <field name="model">mysql.connect</field>
> -            <field name="type">tree</field>
> -            <field name="arch" type="xml">
> -                <tree string="MySql Connect Config">
> -                    <field name="host" />
> -                                     <field name="database" />
> -                                     <field name="user" />
> -                </tree>
> -            </field>
> -        </record>
> -             
> -             <!-- MySql Config Form View -->
> -             <record id="view_mysql_config_form" model="ir.ui.view" >
> -                     <field name="name">view.mysql.config.form</field>
> -                     <field name="model">mysql.connect</field>
> -                     <field name="type">form</field>
> -                     <field name="arch" type="xml">
> -                             <form string="MySql Connect Config">
> -                                     <group colspan="4" col="4">
> -                                             <separator string="MySql 
> Connect Config" colspan="4" col="4" />
> -                                             <field name="host" />
> -                                             <field name="database" />
> -                                             <field name="user" />
> -                                             <field name="password" 
> password="True" />
> -                                     </group>
> -                                     <group colspan="4" col="4">
> -                                             <separator string="Test MySql 
> Connection" colspan="4" col="4" />
> -                                             <button name="test_connection" 
> string="Test Connection" type="object" icon="gtk-execute" colspan="2" />
> -                                     </group>
> -                                     
> -                             </form>
> -                     </field>
> -             </record>
> -             
> -        <record id="action_mysql_config" model="ir.actions.act_window">
> -            <field name="name">MySql Connect Config</field>
> -            <field name="type">ir.actions.act_window</field>
> -            <field name="res_model">mysql.connect</field>
> -            <field name="view_type">form</field>
> -            <field name="view_id" ref="view_mysql_config_tree"/>
> -        </record>
> -        
> -        <menuitem name="MySql Configuration" id="menu_mysql_configuration" 
> parent="base.menu_config"/>
> -             <menuitem name="MySql Connection" id="menu_mysql_connection" 
> action="action_mysql_config" parent="menu_mysql_configuration" sequence="1"/>
> -
> -     </data>
> -</openerp>
> 
> === added directory 'dos_mysql_connect/views'
> === added file 'dos_mysql_connect/views/mysql_connect_view.xml'
> --- dos_mysql_connect/views/mysql_connect_view.xml    1970-01-01 00:00:00 
> +0000
> +++ dos_mysql_connect/views/mysql_connect_view.xml    2014-06-16 14:24:00 
> +0000
> @@ -0,0 +1,63 @@
> +<?xml version="1.0" encoding="utf-8"?>
> +<openerp>
> +     <data>
> +             <!-- MySql Config Search View-->
> +        <record id="view_mysql_config_search" model="ir.ui.view">
> +            <field name="name">view.mysql.config.search</field>
> +            <field name="model">mysql.connect</field>
> +            <field name="arch" type="xml">
> +                <search string="Search">
> +                    <field name="host" select="1"/>
> +                    <field name="database" select="1"/>
> +               </search>
> +            </field>
> +        </record>
> +        
> +             <!-- MySql Config Tree View-->
> +        <record id="view_mysql_config_tree" model="ir.ui.view">
> +            <field name="name">view.mysql.config.tree</field>
> +            <field name="model">mysql.connect</field>
> +            <field name="arch" type="xml">
> +                <tree string="MySql Connect Config">
> +                    <field name="host" />
> +                                     <field name="database" />
> +                                     <field name="user" />
> +                </tree>
> +            </field>
> +        </record>
> +             
> +             <!-- MySql Config Form View -->
> +             <record id="view_mysql_config_form" model="ir.ui.view" >
> +                     <field name="name">view.mysql.config.form</field>
> +                     <field name="model">mysql.connect</field>
> +                     <field name="arch" type="xml">
> +                             <form string="MySql Connect Config">
> +                                     <group colspan="4" col="4">
> +                                             <separator string="MySql 
> Connect Config" colspan="4" col="4" />
> +                                             <field name="host" />
> +                                             <field name="database" />
> +                                             <field name="user" />
> +                                             <field name="password" 
> password="True" />
> +                                     </group>
> +                                     <group colspan="4" col="4">
> +                                             <separator string="Test MySql 
> Connection" colspan="4" col="4" />
> +                                             <button name="test_connection" 
> string="Test Connection" type="object" icon="gtk-execute" colspan="2" />
> +                                     </group>
> +                                     
> +                             </form>
> +                     </field>
> +             </record>
> +             
> +        <record id="action_mysql_config" model="ir.actions.act_window">
> +            <field name="name">MySql Connect Config</field>
> +            <field name="type">ir.actions.act_window</field>
> +            <field name="res_model">mysql.connect</field>
> +            <field name="view_type">form</field>
> +            <field name="view_id" ref="view_mysql_config_tree"/>
> +        </record>
> +        
> +        <menuitem name="MySql Configuration" id="menu_mysql_configuration" 
> parent="base.menu_config"/>
> +             <menuitem name="MySql Connection" id="menu_mysql_connection" 
> action="action_mysql_config" parent="menu_mysql_configuration" sequence="1"/>
> +
> +     </data>
> +</openerp>
> 


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

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

Reply via email to