Ticket #575: patch-server-575-A0.diff

File patch-server-575-A0.diff, 8.3 kB (added by elemoine, 2 years ago)
  • docs/framework/index.txt

    diff --git docs/framework/index.txt docs/framework/index.txt
    index 6ebce23..5a3b72c 100644
     
    4040   webservice 
    4141   customizing-webservices 
    4242   spatial-databases 
     43   upgrading 
    4344 
    4445 
    4546----------- 
    4647 
    47 `API References <../reference/index.html#server>`_ 
    48  No newline at end of file 
     48`API References <../reference/index.html#server>`_ 
  • (a) /dev/null vs. (b) docs/framework/upgrading.txt

    diff --git docs/framework/upgrading.txt docs/framework/upgrading.txt
    new file mode 100644
    index 0000000..aca7fb3
    a b  
     1Upgrading 
     2--------- 
     3 
     4This section provides information for upgrading a MapFish application from 
     5MapFish 1.2 to MapFish 2.0 
     6 
     7Pylons 1.0 
     8~~~~~~~~~~ 
     9 
     10MapFish 1.2 is based on Pylons 0.9.7, and MapFish 2.0 is based on Pylons 1.0. 
     11So to upgrade an application from MapFish 1.2 to MapFish 2.0 it is first needed 
     12to upgrade from Pylons 0.9.7 to Pylons 1.0. For this refer to the `Pylons 1.0 
     13Upgrading page <http://pylonshq.com/docs/en/1.0/upgrading/>`_, and follow the 
     14provided indications. 
     15 
     16.. note: 
     17    MapFish 2.0 depending on Pylons 1.0, you will run into dependency issues if 
     18    you attempt to upgrade to Pylons 0.10. So it is recommended not to attempt 
     19    it. 
     20 
     21The Pylons 1.0 Uprading page doesn't include information for upgrading 
     22the model and base controller. Here's additional information: 
     23 
     24* The ``model.meta`` module no longer stores reference to the ``engine`` and 
     25  ``metadata`` objects. Edit ``model/meta.py`` and remove these files:: 
     26   
     27      from sqlalchemy import MetaData 
     28      engine = None 
     29      metadata = MetaData() 
     30 
     31* The ``model.meta`` module now creates the ``scoped session`` and the 
     32  SQLAlchemy ``declarative base`` class. Edit ``model/meta.py``, replace the 
     33  ``Session = None`` line with:: 
     34     
     35      Session = scoped_session(sessionmaker()) 
     36 
     37  and add the following line at the end of the file:: 
     38 
     39      Base = declarative_base() 
     40 
     41* The ``init_model`` function of the ``model`` module is no longer responsible 
     42  for creating the ``Session``. Edit ``model/__init__.py`` and remove these 
     43  three lines from the body of the ``init_model`` function:: 
     44 
     45      sm = orm.sessionmaker(autoflush=True, autocommit=False, bind=engine) 
     46      meta.engine = engine 
     47      meta.Session = orm.scoped_session(sm) 
     48 
     49  The ``init_model`` function now just configures the (already-created) 
     50  Session. Add the following statement to the body of ``init_model``:: 
     51 
     52      Session.configure(bind=engine) 
     53 
     54The application should now be upgraded to Pylons 1.0, and it is now time to do 
     55MapFish-specific adjusments. 
     56 
     57MapFish 2.0 
     58~~~~~~~~~~~ 
     59 
     60MapFish 2.0 is based on `GeoAlchemy <http://geoalchemy.org>`_. GeoAlchemy 
     61provides extensions to SQLAlchemy for use with spatial databases. MapFish 2.0 
     62no longer defines the ``Geometry`` type, the one defined by GeoAlchemy is to be 
     63used instead. 
     64 
     65With MapFish 1.2 the ``paster mf-layer`` command generated model files that 
     66looked like this:: 
     67 
     68    from sqlalchemy import Column, Table, types 
     69    from sqlalchemy.orm import mapper 
     70 
     71    from mapfish.sqlalchemygeom import Geometry 
     72    from mapfish.sqlalchemygeom import GeometryTableMixIn 
     73 
     74    from blonay.model.meta import metadata, engine 
     75 
     76    users_table = Table( 
     77        'users', metadata, 
     78        Column('the_geom', Geometry(4326)), 
     79        schema='my_schema', 
     80        autoload=True, autoload_with=engine) 
     81 
     82    class User(GeometryTableMixIn): 
     83        # for GeometryTableMixIn to do its job the __table__ property 
     84        # must be set here 
     85        __table__ = users_table 
     86 
     87    mapper(User, users_table) 
     88 
     89With MapFish 2.0 the same ``user`` model looks like this:: 
     90 
     91    from sqlalchemy import Column, types 
     92 
     93    from geoalchemy import GeometryColumn, Point 
     94 
     95    from mapfish.sqlalchemygeom import GeometryTableMixIn 
     96    from sample.model.meta import Session, Base 
     97 
     98    class User(Base, GeometryTableMixIn): 
     99        __tablename__ = 'users' 
     100        __table_args__ = { 
     101            "schema": 'my_schema', 
     102            "autoload": True, 
     103            "autoload_with": Session.bind 
     104        } 
     105        the_geom = GeometryColumn(Point(dimension=2, srid=4326)) 
  • mapfish/templates/controller.py_tmpl

    diff --git mapfish/templates/controller.py_tmpl mapfish/templates/controller.py_tmpl
    index abd550d..182eb93 100644
     
    11from pylons import request, response, session, tmpl_context as c 
    2 from pylons.controllers.util import abort, redirect_to 
     2from pylons.controllers.util import abort, redirect 
    33 
    44from {{basePkg}}.lib.base import BaseController 
    55from {{basePkg}}.model.{{modName}} import {{modelClass}} 
  • mapfish/templates/model.py_tmpl

    diff --git mapfish/templates/model.py_tmpl mapfish/templates/model.py_tmpl
    index 7419326..a8a1d9f 100644
     
    33from geoalchemy import GeometryColumn, {{geomType}} 
    44 
    55from mapfish.sqlalchemygeom import GeometryTableMixIn 
    6 from {{basePkg}}.model.meta import engine, Base 
     6from {{basePkg}}.model.meta import Session, Base 
    77 
    88class {{modelClass}}(Base, GeometryTableMixIn): 
    99    __tablename__ = '{{table}}' 
     
    1212        "schema": '{{schema}}', 
    1313    {{endif}} 
    1414        "autoload": True, 
    15         "autoload_with": engine 
     15        "autoload_with": Session.bind 
    1616    } 
    1717    {{geomColName}} = GeometryColumn({{geomType}}(dimension=2, srid={{epsg}})) 
  • (a) mapfish/templates/project/+package+/model/__init__.py_tmpl vs. (b) /dev/null

    diff --git mapfish/templates/project/+package+/model/__init__.py_tmpl mapfish/templates/project/+package+/model/__init__.py_tmpl
    deleted file mode 100644
    index c6138cb..0000000
    a b  
    1 {{if sqlalchemy}} 
    2 """The application's model objects""" 
    3 import sqlalchemy as sa 
    4 from sqlalchemy import orm 
    5  
    6 from {{package}}.model import meta 
    7  
    8 def init_model(engine): 
    9     """Call me before using any of the tables or classes in the model""" 
    10     ## Reflected tables must be defined and mapped here 
    11     #global reflected_table 
    12     #reflected_table = sa.Table("Reflected", meta.metadata, autoload=True, 
    13     #                           autoload_with=engine) 
    14     #orm.mapper(Reflected, reflected_table) 
    15  
    16     sm = orm.sessionmaker(autoflush=True, autocommit=False, bind=engine) 
    17  
    18     meta.engine = engine 
    19     meta.Session = orm.scoped_session(sm) 
    20  
    21  
    22 ## Non-reflected tables may be defined and mapped at module level 
    23 #foo_table = sa.Table("Foo", meta.metadata, 
    24 #    sa.Column("id", sa.types.Integer, primary_key=True), 
    25 #    sa.Column("bar", sa.types.String(255), nullable=False), 
    26 #    ) 
    27 # 
    28 #class Foo(object): 
    29 #    pass 
    30 # 
    31 #orm.mapper(Foo, foo_table) 
    32  
    33  
    34 ## Classes for reflected tables may be defined here, but the table and 
    35 ## mapping itself must be done in the init_model function 
    36 #reflected_table = None 
    37 # 
    38 #class Reflected(object): 
    39 #    pass 
    40 {{endif}} 
  • (a) mapfish/templates/project/+package+/model/meta.py_tmpl vs. (b) /dev/null

    diff --git mapfish/templates/project/+package+/model/meta.py_tmpl mapfish/templates/project/+package+/model/meta.py_tmpl
    deleted file mode 100644
    index 99011e7..0000000
    a b  
    1 {{if sqlalchemy}} 
    2 """SQLAlchemy Metadata and Session object""" 
    3 from sqlalchemy import MetaData 
    4 from sqlalchemy.orm import scoped_session, sessionmaker 
    5 from sqlalchemy.ext.declarative import declarative_base 
    6  
    7 __all__ = ['Session', 'engine', 'metadata', 'Base'] 
    8  
    9 # SQLAlchemy database engine. Updated by model.init_model() 
    10 engine = None 
    11  
    12 # SQLAlchemy session manager. Updated by model.init_model() 
    13 Session = scoped_session(sessionmaker()) 
    14  
    15 # Global metadata. If you have multiple databases with overlapping table 
    16 # names, you'll need a metadata for each database 
    17 metadata = MetaData() 
    18  
    19 # The base class for declarative mappings 
    20 Base = declarative_base(metadata=metadata) 
    21 {{endif}} 
  • mapfish/templates/test_controller.py_tmpl

    diff --git mapfish/templates/test_controller.py_tmpl mapfish/templates/test_controller.py_tmpl
    index ac9db0d..0d85915 100644
     
    22 
    33class Test{{contrClass}}Controller(TestController): 
    44    def test_index(self): 
    5         response = self.app.get(url_for(controller='{{fullModName}}')) 
     5        response = self.app.get(url(controller='{{fullModName}}')) 
    66        # Test response...