views:

136

answers:

1

Hi all,

I am currently making the switch from Django to Turbogears 2.1 and am running into some problems that I could not find the answers to in the Turbogears docs. If tg developers read this, let me tell you that one of the best features Django has over TG is its documentation!

1) How do I access the request (user?) object within a mako template in order to check if the user is authenticated? For instance

if (request.user.is_authenticated) 'logout link' else 'login link'

2) A related quesiton (as the user object is exposed in Django to templates via context processors). Is there a way to add data to the request context? For instance, in my Django app I add a cached dictionary of notifications for the user if the user is logged in via a definition in a context_processors.py file and then include that def in the TEMPLATE_CONTEXT_PROCESSORS tuple in the settings file.

3) This may warrant its own question, but I thought I'd throw it in in case anyone has a quick suggestion. I'm using Netbeans as my IDE and it offers no code coloring or tools for mako files. However, trying to rename the templates with a .html extension throws a mako error. Is there any way around this or am I stuck with plain text and the .mak extension?

Thanks very much

+1  A: 

I've moved from Turbogears 1.0 to Django. Might not be able to answer all of these, but I believe in general TG2 tries to keep things fairly similar to TG1. Hopefully pointing out how it works in TG 1, might help...

1) In Turbogears 1.0 you would use tg.identity.anonymous to see if the user was logged in or not. A quick look at the docs, shows it's most likely still the same.

2) Turbogears called this sort of thing stdvars - see here for details for TG 1 http://docs.turbogears.org/1.0/stdvars

3) Sorry don't know, but I presume you can probably just tell Netbeans to consider .mak as another extension for html files (so it uses html syntax highlighting).

John Montgomery