[docs]classWuttaContinuumConfigExtension(WuttaConfigExtension):""" App :term:`config extension` for Wutta-Continuum. This adds a startup hook, which can optionally turn on the SQLAlchemy-Continuum versioning features for the main app DB. """key='wutta_continuum'defstartup(self,config):""" """# only do this if config enables itifnotconfig.get_bool('wutta_continuum.enable_versioning',usedb=False,default=False):return# create wutta plugin, to assign user and ip addressspec=config.get('wutta_continuum.wutta_plugin_spec',usedb=False,default='wutta_continuum.conf:WuttaContinuumPlugin')WuttaPlugin=load_object(spec)# tell sqlalchemy-continuum to do its thingmake_versioned(plugins=[WuttaPlugin()])# nb. must load the model before configuring mappersapp=config.get_app()model=app.model# tell sqlalchemy to do its thingconfigure_mappers()
[docs]classWuttaContinuumPlugin(Plugin):""" SQLAlchemy-Continuum manager plugin for Wutta-Continuum. This tries to assign the current user and IP address to the transaction. It will assume the "current machine" IP address, which may be suitable for some apps but not all (e.g. web apps, where IP address should reflect an arbitrary client machine). However it does not actually have a way to determine the current user. WuttaWeb therefore uses a different plugin, based on this one, to get both the user and IP address from current request. You can override this to use a custom plugin for this purpose; if so you must specify in your config file: .. code-block:: ini [wutta_continuum] wutta_plugin_spec = poser.db.continuum:PoserContinuumPlugin See also the SQLAlchemy-Continuum docs for :doc:`sqlalchemy-continuum:plugins`. """defget_remote_addr(self,uow,session):""" """host=socket.gethostname()returnsocket.gethostbyname(host)defget_user_id(self,uow,session):""" """deftransaction_args(self,uow,session):""" """kwargs={}remote_addr=self.get_remote_addr(uow,session)ifremote_addr:kwargs['remote_addr']=remote_addruser_id=self.get_user_id(uow,session)ifuser_id:kwargs['user_id']=user_idreturnkwargs