Hello, Two things up front 1- I hate how this "public" api is presented to us 2- I'm tired of answering the same question over and over on IRC so for now this is how things go I'll close with what I think we should do for tg2.1
Keep in mind they are a lot of "inconsistencies" in the API and some weird design choices that a limiting it by several factors. So first quickstart a project and paste this into a template. You will find the first error (1). tg.identity is None when you are not logged in, this pulls from repoze.who and I don't think it's such a bad idea as it should be None when you have no user. But it's horrible for those cases where we need the user and/or group object. The next error (2) is how clumsy the tg.predicates.is_anonymous().is_met(tg.request.environ) transformation is implemented, I won't go over this again. http://trac.turbogears.org/ticket/2205 Draw your own conclusions. But at least we have the more decent form tg.predicates.is_anonymous() at least for now. <body> <p py:if='tg.predicates.is_anonymous().is_met(tg.request.environ)'>Anonymous </p> <p> The methods below work due to a flag set by TG </p> <p py:if='tg.predicates.is_anonymous()'>Anonymous </p> <p py:if='tg.predicates.not_anonymous()'>Not Anonymous </p> <h1>WARNING: methods below will only work if you are logged in! </h1> <h2> This is due to tg.identity being None if no auth is present </h2> <h3> From repoze.who </h3> <div>User Object: ${tg.identity['repoze.who.userid']}</div> <h3>From repoze.what</h3> <div>User Object: ${tg.identity['user']}</div> <div>Groups List of Strings: ${tg.identity['groups']}</div> <div>Groups List of Objects: ${tg.identity['user'].groups}</div> <div>Permissions List of Strings: ${tg.identity['permissions']}</div> <div>Permissions List of Objects: ${tg.identity['user'].permissions}</div> <div>First Group: ${tg.identity['groups'][0]}</div> <div>First Permission: ${tg.identity['permissions'][0]}</div> <h3> These are real object </h3> <div>User Object: ${str(type(tg.identity['user']))}</div> <div>Groups List Of Strings: ${str(type(tg.identity['groups']))}</div> <div>Groups List Of Objects: ${str(type(tg.identity['user'].groups))}</div> <div>Groups First Object: ${str(type(tg.identity['user'].groups[0]))}</div> <div>Permissions List Of String: ${str(type(tg.identity['permissions']))}</div> <div>Permissions List Of Objects: ${str(type(tg.identity['user'].permissions))}</div> </body> So that was a bunch, how about doing the same thing in the controller? well it's totally different. @expose('identitytest.templates.index') def index(self): """Handle the front-page.""" from repoze.what.predicates import has_permission from tg import request yes_or_no = has_permission('manage').is_met(request.environ) print yes_or_no # outputs = the real "boolean object" yes_or_no = has_permission('manage') print yes_or_no # outputs = <repoze.what.predicates.has_permission object at 0xa63666c> #Why? don't know r.what works that way. #there is a flag you can set but it's not set at the controller level, need to ask Gustavo identity = request.environ.get('repoze.who.identity') # from here you can do everything in the template example as tg.identity is the equivalent return dict() As you can tell there is no "short form" (3) and you need to import items from 2 classes (4) and in order to get the rather simply tg.identity variable from the templates you get a really weird call to the request.environ. So bottom line that is how things are now, if someone wants to transform this into a tutorial be my guest. What I really want to do is provide a sane API to fix 1,2,3,4 and probably others what you may have. I'll leave the fix for another email, too tired right now. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

