> So, my question now is this: Is there any docs page that explains how
> "@validate, @identity.... etc", and the secc.py file and other
> security tools in a TG2 project work?
>
> Thanks very much for your time, and keep up the good work! :)
> All the best wishes in making an even more powerful, robust,
> dependable, and reliable TG2.


You may want to wait until the next alpha for the secure controller stuff --
I believe it's still up in the air. Also, there's some discussion on
shifting around the TG2 authorization stuff, so you should probably follow
that on the tg-trunk list. But as for your question about returning a
snipped set of summaries, that's pretty simple, depending on how your
model's set up.

I'd probably design in the trimmed version of a post as a property. If
you're using a <!--more--> comment to signify a snip (like WordPress, for
instance) you could go with something like...

PAGE_BREAK = '<!--more-->'
MAX_LENGTH = 500

class Post(...):
    ...
    @property
    def trimmed(self):
        if PAGE_BREAK in self.body:
            return self.body[:self.body.find(PAGE_BREAK)]
        elif len(self.body) > MAX_LENGTH:
            return self.body[:MAX_LENGTH]
        else:
            return self.body

Then to access the latest posts, you could just build the query as a
classmethod of the Post class...

    @classmethod
    def latest(self, limit=10, offset=0):
        q = DBSession.query(Post).order_by(Post.date_posted.desc())
        return q.limit(int(limit)).offset(int(offset))

So returning the index page is really just a matter of importing the Post
class from the model, sticking Post.latest() into the template context and
iterating through the query object in Genshi with a <div py:for="">. Pretty
simple.

(Disclaimer: I wrote this code inside gmail, there may be a syntax error or
two. Also, depending on how you want to handle pagination, you may want to
do this query directly from your controller. There's no need for the class
method, it's just sugar.)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to