On Fri, Jan 12, 2007 at 09:56:57AM +1100, Alec Thomas wrote:
> > > page = WikiPage(env, 'WikiStart')
> > > context = Context.from_resource(env, req, page)
> > ... or simply `context = page.get_context(req)`, instead of the more
> > complex hops through the IResourceMapper implementations which will end
> > in the `identify_resource(req, resource)` of the module?
>
> The only real reason I didn't do that was that it would ideally be in a
> base "Trac Object" and, if we have that, lots of other stuff could/should
> go in it, just like your old TracObject branch. I don't really have a
> problem with adding it, but...
I had a look at this, and I'd like to understand the actual objections
that were raised regarding TracObjects. To me it makes sense to be able
to obtain information about a Trac resource from the resource itself. In
fact, with the current Context object you could almost rename "Context"
to "Resource" and do this:
class WikiPage(Resource):
def __init__(self, env, name=None, version=None, db=None, req=None,
abs_urls=False):
Resource.__init__(self, env, req, 'wiki', name, abs_urls=abs_urls,
db=db, resource=self)
...
# Backwards compatibility "name" property
def _get_name(self):
return self.id
def _set_name(self, name):
"""Backwards compatibility property for old WikiPage model."""
self.id = name
name = property(_get_name, _set-name)
or
class Ticket(Resource):
def __init__(self, env, tkt_id=None, db=None, req=None, abs_urls=None):
Resource.__init__(self, env, req, 'ticket', tkt_id, db=db, req=req,
abs_urls=abs_urls, resource=self)
...
Then you would be able to do lots of nice things:
>>> page = WikiPage(env, 'WikiStart', req=req, abs_urls=True)
>>> page.href
'http://example.org/trac/wiki/WikiStart'
>>> page.href('#Foo')
'http://example.org/trac/wiki/WikiStart#Foo'
>>> 'WIKI_ADMIN' in page.perm
False
and of course:
>>> page.wiki_to_html('Some [wiki:Wiki] text')
...
--
Evolution: Taking care of those too stupid to take care of themselves.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Trac Development" 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/trac-dev?hl=en
-~----------~----~----~----~------~----~------~--~---