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
40 40 webservice 41 41 customizing-webservices 42 42 spatial-databases 43 upgrading 43 44 44 45 45 46 ----------- 46 47 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 1 Upgrading 2 --------- 3 4 This section provides information for upgrading a MapFish application from 5 MapFish 1.2 to MapFish 2.0 6 7 Pylons 1.0 8 ~~~~~~~~~~ 9 10 MapFish 1.2 is based on Pylons 0.9.7, and MapFish 2.0 is based on Pylons 1.0. 11 So to upgrade an application from MapFish 1.2 to MapFish 2.0 it is first needed 12 to upgrade from Pylons 0.9.7 to Pylons 1.0. For this refer to the `Pylons 1.0 13 Upgrading page <http://pylonshq.com/docs/en/1.0/upgrading/>`_, and follow the 14 provided 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 21 The Pylons 1.0 Uprading page doesn't include information for upgrading 22 the 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 54 The application should now be upgraded to Pylons 1.0, and it is now time to do 55 MapFish-specific adjusments. 56 57 MapFish 2.0 58 ~~~~~~~~~~~ 59 60 MapFish 2.0 is based on `GeoAlchemy <http://geoalchemy.org>`_. GeoAlchemy 61 provides extensions to SQLAlchemy for use with spatial databases. MapFish 2.0 62 no longer defines the ``Geometry`` type, the one defined by GeoAlchemy is to be 63 used instead. 64 65 With MapFish 1.2 the ``paster mf-layer`` command generated model files that 66 looked 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 89 With 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
1 1 from pylons import request, response, session, tmpl_context as c 2 from pylons.controllers.util import abort, redirect _to2 from pylons.controllers.util import abort, redirect 3 3 4 4 from {{basePkg}}.lib.base import BaseController 5 5 from {{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
3 3 from geoalchemy import GeometryColumn, {{geomType}} 4 4 5 5 from mapfish.sqlalchemygeom import GeometryTableMixIn 6 from {{basePkg}}.model.meta import engine, Base6 from {{basePkg}}.model.meta import Session, Base 7 7 8 8 class {{modelClass}}(Base, GeometryTableMixIn): 9 9 __tablename__ = '{{table}}' … … 12 12 "schema": '{{schema}}', 13 13 {{endif}} 14 14 "autoload": True, 15 "autoload_with": engine15 "autoload_with": Session.bind 16 16 } 17 17 {{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 sa4 from sqlalchemy import orm5 6 from {{package}}.model import meta7 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 here11 #global reflected_table12 #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 = engine19 meta.Session = orm.scoped_session(sm)20 21 22 ## Non-reflected tables may be defined and mapped at module level23 #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 # pass30 #31 #orm.mapper(Foo, foo_table)32 33 34 ## Classes for reflected tables may be defined here, but the table and35 ## mapping itself must be done in the init_model function36 #reflected_table = None37 #38 #class Reflected(object):39 # pass40 {{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 MetaData4 from sqlalchemy.orm import scoped_session, sessionmaker5 from sqlalchemy.ext.declarative import declarative_base6 7 __all__ = ['Session', 'engine', 'metadata', 'Base']8 9 # SQLAlchemy database engine. Updated by model.init_model()10 engine = None11 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 table16 # names, you'll need a metadata for each database17 metadata = MetaData()18 19 # The base class for declarative mappings20 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
2 2 3 3 class Test{{contrClass}}Controller(TestController): 4 4 def test_index(self): 5 response = self.app.get(url _for(controller='{{fullModName}}'))5 response = self.app.get(url(controller='{{fullModName}}')) 6 6 # Test response...
