All pastes #1753168 Raw Edit

Mine

public python v1 · immutable
#1753168 ·published 2010-01-16 03:36 UTC
rendered paste body
## first activate the django environment and settingsimport sys, os, sitesite.addsitedir('/home/egj/django/lib/python2.5/site-packages/')sys.path.append('/home/egj/django/greeb')os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'import grokfrom megrok import trajectfrom myapp.models import Fooclass MyApp(grok.Application, grok.Container):    pass## hook up the Foo class (django Model subclass) with trajectclass DjangoTraject(traject.Traject):    grok.context(MyApp)    pattern = 'foo/:id:int'    model = Foo    def factory(id):        try:            return Foo.objects.get(pk=id)        except Foo.DoesNotExist:  # let the query fail silenty so grok can issue a 404            return None    def arguments(foo):        return dict(foo_id=foo.pk)## hook up at least one grok view to the django modelclass Index(grok.View):    grok.context(Foo)    def render(self):        # self.context is the django model instance        return str(self.context)