LEFT | RIGHT |
(no file at all) | |
| 1 # This file is part of trytond_backend_gis. The COPYRIGHT file at the top |
| 2 # level of this repository contains the full copyright notices and license |
| 3 # terms. |
| 4 import re |
| 5 |
| 6 from trytond.transaction import Transaction |
| 7 from trytond.backend.postgresql.table import TableHandler as PGTableHandler |
| 8 |
| 9 __all__ = ['TableHandler'] |
| 10 |
| 11 GIS_RE = re.compile( |
| 12 r'GIS_(?P<type>[A-Z]+)\((?P<srid>[0-9]+), (?P<dimension>[0-9]+)\)') |
| 13 |
| 14 |
| 15 class TableHandler(PGTableHandler): |
| 16 |
| 17 def add_column(self, column_name, abstract_type, default=None, comment=''): |
| 18 if abstract_type.startswith('GIS_'): |
| 19 column_adder = self.add_geometry_column |
| 20 else: |
| 21 column_adder = super(TableHandler, self).add_column |
| 22 column_adder(column_name, abstract_type, default, comment) |
| 23 |
| 24 def add_geometry_column(self, column_name, abstract_type, default_fun=None, |
| 25 fill_default=True, comment=''): |
| 26 cursor = Transaction().connection.cursor() |
| 27 |
| 28 if self.column_exist(column_name): |
| 29 # TODO check for type and eventual migration |
| 30 return |
| 31 |
| 32 match = GIS_RE.match(abstract_type) |
| 33 assert match is not None, \ |
| 34 'The abstract type %s is not supported' % abstract_type |
| 35 type_ = match.group('type') |
| 36 srid, dimension = map(int, match.group('srid', 'dimension')) |
| 37 cursor.execute('SELECT AddGeometryColumn(%s, %s, %s, %s, %s)', |
| 38 (self.table_name, column_name, srid, type_, dimension)) |
| 39 self._update_definitions(columns=True) |
LEFT | RIGHT |