""" megrok.traject usage exaple. A non-Grok model can be traversed using megrok.traject Dramatis personae: - the traject root: TrajectCave - the foreign data model: SomeForeignModel - the Traject: TrajectForSomeForeignModel Please see tests in app.txt. """ import grok from megrok import traject class TrajectCave(grok.Application, grok.Container): """ A root application. Foreign models can be traversed using instances of this class as a starting point. """ class Index(grok.View): """ The default view for TrajectCave. """ grok.context(TrajectCave) grok.name('index') grok.template('index') class SomeForeignModel(object): """ Some model, possibly imported. This class is implemented in this module for simplicity, but it could be any class imported from some non-Grok package. """ def __init__(self, name = 'noname', ): """ Initialises the nameof an instance. """ self.size = size class TrajectForSomeForeignModel(traject.Traject): """ A traject for SomeForeignModel. """ grok.context(TrajectCave) pattern = 'foreigners/:name' model = SomeForeignModel def factory(name='somename'): """ The factory is the just the class constructor. """ return SomeForeignModel(name=name) def arguments(some_foreign_model): """ Defines only 'name' as an argument. """ return dict(name=some_foreign_model.name)