[Grok-dev] spotlight on: megrok.traject

Ethan Jucovy ejucovy at gmail.com
Mon Jan 25 09:55:06 EST 2010


Hey Aroldo,

Two things:

1) Your latter test example is correct -- the URL you visit should not
include the colon, so browser.open('
http://localhost/app/foreigners/funnyname') is the correct way.

2) I found that registering a view named 'index' does not get treated as the
default view.  Instead you need to name your view 'index.html'.  I think
this is a bug, but I didn't get far enough to figure out what layer the bug
is in.  Alternatively, browser.open('
http://localhost/app/foreigners/funnyname/@@index') should work when your
view is named 'index'.

Hope this helps,
Ethan

On Mon, Jan 25, 2010 at 5:58 AM, Aroldo Souza-Leite <asouzaleite at gmx.de>wrote:

> Hi Martijn,
>
>
> am I wrong in the expectation that an object of a non-Grok class
> 'SomeForeignModel'
> (see attachment) would be instantiated by 'factory' in
> 'TrajectForSomeForeignModel'
> as a result of the request defined in 'pattern' and that this object (or
> some view of it) would
> be shown in the response?
>
> If this is what 'megrok.traject' does to a non-Grok model, then I got stuck
> where
> think I should implement a view for the non-Grok class 'SomeForeignModel'.
> How can I do this?
>
> Perhaps I just didn't get the basic idea of the 'megrok.traject' usage for
> non-Grok classes?
>
> Regards,
>
> Aroldo.
>
>
>
>
>
>
> Martijn Faassen wrote:
>
>> Spotlight on...
>>
>> megrok.traject is a package that allows a different way to publish your
>> models than the traversal that is most commonly used in Zope applications.
>> With megrok.traject you can define explicitly what kind of URLs you want to
>> publish your models on, instead of having to construct an object hierarchy.
>>
>> A model can be anything that you want to have views for, and doesn't need
>> to be a persistent ``grok.Model``. In fact megrok.traject is most suitable
>> for objects that are not stored in the ZODB, as the ZODB makes traversal
>> easy.
>>
>> What kind of models could you publish with megrok.traject then? It
>> could be just Python objects you design yourself. In this case you can use
>> ``traject.Model``. You tell it under what URL pattern it should appear and
>> how it is to be constructed, and you're done. ``traject.Model`` is very
>> lightweight: it's just a ``grok.Context`` that can be hooked up by a
>> "traject pattern".
>>
>> Alternatively you may want to treat your models even more lightly: you may
>> wish to hook up models that are defined by a package that is not under your
>> control at all. You could have for instance an ORM such as SQAlchemy define
>> the models in an entirely different package that knows nothing about how
>> these models should be presented on the web in your application. You can
>> then use ``traject.Traject`` to associate such models with a URL pattern in
>> your application.
>>
>> You can look at the megrok.traject documentation for more information:
>>
>> http://pypi.python.org/pypi/megrok.traject
>>
>> The low-level implementation is a reusable library called ``traject``, and
>> its documentation can give you more details:
>>
>> http://pypi.python.org/pypi/traject
>>
>> If you still don't understand why megrok.traject would be useful for
>> *you*, don't worry. Grok's traversal method of publishing objects isn't
>> going anywhere, and megrok.traject is just an option. If you have questions,
>> we'd very much like to hear them on grok-dev however, so that we can improve
>> megrok.traject and its documentation.
>>
>> Volunteers who would want to write a tutorial oriented towards beginners
>> that uses megrok.traject would also be very welcome!
>>
>>
>> _______________________________________________
>> Grok-dev mailing list
>> Grok-dev at zope.org
>> https://mail.zope.org/mailman/listinfo/grok-dev
>>
>>
>
>
> Do a functional doctest test on the app.
> ========================================
>
> :Test-Layer: functional
>
> Let's first create an instance of Trajectcave at the top level:
>
>   >>> from trajectcave.app import TrajectCave
>   >>> root = getRootFolder()
>   >>> root['app'] = TrajectCave()
>
>
> Run tests in the testbrowser
> ----------------------------
>
> The zope.testbrowser.browser module exposes a Browser class that
> simulates a web browser similar to Mozilla Firefox or IE.  We use that
> to test how our application behaves in a browser.  For more
> information, see http://pypi.python.org/pypi/zope.testbrowser.
>
> Create a browser and visit the instance you just created:
>
>   >>> from zope.testbrowser.testing import Browser
>   >>> browser = Browser()
>   >>> browser.open('http://localhost/app')
>
> Check some basic information about the page you visit:
>
>   >>> browser.url
>   'http://localhost/app'
>   >>> browser.headers.get('Status').upper()
>   '200 OK'
>
> Try to reach an instance of SomeForeignModel using the
> TrajectForSomeForeignModel Traject. THIS IS FAILING:
>
>    >>< browser.open('http://localhost/app/foreigners/:funnyname')
>    >>< browser.headers.get('Status').upper()
>    '200 OK'
>
>
> Perhaps because the url shouldn't include ':'?
> THIS IS FAILING:
>
>
>    >>< browser.open('http://localhost/app/foreigners/funnyname')
>    >>< browser.headers.get('Status').upper()
>    '200 OK'
>
> Or perhaps simply because SomeForeignModel is not a view?
>
>
>
>
>
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> https://mail.zope.org/mailman/listinfo/grok-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/grok-dev/attachments/20100125/ea50c6a5/attachment.html 


More information about the Grok-dev mailing list