# -*- coding: utf-8 -*-
##############################################################################
#
#    Author: Nicolas Bessi
#    Copyright 2011-2012 Camptocamp SA
#
#    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/>.
#
##############################################################################
"""Helper to setup Postgis"""
from openerp.exceptions import MissingError
from openerp.tools import ustr

import logging

logger = logging.getLogger('geoengine.sql')


def init_postgis(cr):
    """ Initialize postgis
    Add PostGIS support to the database. PostGIS is a spatial database
    extender for PostgreSQL object-relational database. It adds support for
    geographic objects allowing location queries to be run in SQL.
    """
    cr.execute("""
        SELECT
            tablename
        FROM
            pg_tables
        WHERE
            tablename='spatial_ref_sys';
    """)
    check = cr.fetchone()
    if check:
        return {}
    try:
        cr.execute("""
        CREATE EXTENSION postgis;
        CREATE EXTENSION postgis_topology;
    """)
    except Exception as exc:
        raise MissingError(
            'Error, Can not initialize spatial postgis function. '
            'Database user may have to be superuser and postgres/postgis '
            'extentions and dev header have to be installed', ustr(exc))

@@ -1009,39 +1009,8 @@
 rror
-%0Afrom openerp.tools import ustr
 %0A%0Aim
@@ -1695,17 +1695,10 @@
 tion
- as exc
 :%0A
+
     
@@ -1733,17 +1733,17 @@
         
-'
+%22
 Error, C
@@ -1786,17 +1786,17 @@
 nction. 
-'
+%22
 %0A       
@@ -1800,17 +1800,17 @@
         
-'
+%22
 Database
@@ -1861,17 +1861,17 @@
 postgis 
-'
+%22
 %0A       
@@ -1875,17 +1875,17 @@
         
-'
+%22
 extentio
@@ -1926,18 +1926,253 @@
 lled
-', ustr(exc)
+%22%0A            %22If you do not want Odoo to connect with a super user %22%0A            %22open a client to your database using a super user and run: %5Cn%22%0A            %22CREATE EXTENSION postgis;%5Cn%22%0A            %22CREATE EXTENSION postgis_topology;%5Cn%22%0A        
 )%0A

Fix MissingError wrong argument number