# -*- coding: utf-8 -*-
from pylons import tmpl_context as c
from pylons.templating import render_mako
from {{package}}.lib.base import *
from {{package}}.model import *
from {{package}}.lib.decorators import authorize
from {{package}}.lib.auth.permissions import SignedIn
import logging
log = logging.getLogger(__name__)

class DemoController(BaseController):

    # Need to protect an entire controller?
    # Decorating __before__ protect all actions
    
    # @authorize(SignedIn())
    def __before__(self):
        pass

    def index(self):        
        # Pretty-print the graph, serialized in n3
        
        import pygments
        from pygments import lexers, formatters
        formatter = formatters.HtmlFormatter(lineseparator='<br />')
        lexer = lexers.get_lexer_by_name('n3')
        c.n3 = pygments.highlight(c.graph.serialize(format="n3"), lexer, formatter)

        c.users = User.filter_by(active=1)
        c.groups = Group.filter_by(active=1)
        c.permissions =[]
        c.title = 'Test'
        return render('default.mak')

    # Need to protect just a single action?
    # Do it like this ....
    @authorize(SignedIn())
    def privindex(self):
        c.users = User.filter_by(active=1)
        c.groups = Group.filter_by(active=1)
        c.permissions = []
        c.auth_user = request.environ['AUTH_USER']
        c.title = 'Test'
        return render('test.mak')
