# -*- coding: utf-8 -*-
import openerp
from openerp.addons.web import http
from openerp.addons.web.controllers.main import manifest_list
from openerp.addons.web.http import request

class Website(openerp.addons.web.controllers.main.Home):

    @http.route('/', type='http', auth="db")
    def index(self, **kw):
        return self.page("website.homepage")

    @http.route('/admin', type='http', auth="none")
    def admin(self, *args, **kw):
        return super(Website, self).index(*args, **kw)

    @http.route('/page/<path:path>', type='http', auth="db")
    def page(self, path):
        #def get_html_head():
        #    head += ['<link rel="stylesheet" href="%s">' % i for i in manifest_list('css', db=request.db)]
        #modules = request.registry.get("ir.module.module").search_read(request.cr, openerp.SUPERUSER_ID, fields=['id', 'shortdesc', 'summary', 'icon_image'], limit=50)
        try:
            request.session.check_security()
            editable = True
            uid = request.session._uid
        except http.SessionExpiredException:
            editable = False
            uid = openerp.SUPERUSER_ID
        context = {
            'inherit_branding': editable
        }
        script = "\n".join(['<script type="text/javascript" src="%s"></script>' % i for i in manifest_list('js', db=request.db)])
        values = {
            'script' : script,
            'editable': editable,
            'request': request,
            'registry': request.registry,
            'cr': request.cr,
            'uid': uid,
            'res_company': request.registry['res.company'].browse(request.cr, uid, 1, context=context),
        }
        html = request.registry.get("ir.ui.view").render(request.cr, uid, path, values, context)
        return html

# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:

@@ -175,16 +175,361 @@
 equest%0A%0A
+def template_values():%0A    script = %22%5Cn%22.join(%5B'%3Cscript type=%22text/javascript%22 src=%22%25s%22%3E%3C/script%3E' %25 i for i in manifest_list('js', db=request.db)%5D)%0A    values = %7B%0A        'request': request,%0A        'registry': request.registry,%0A        'cr': request.cr,%0A        'uid': request.session._uid,%0A        'script' : script,%0A    %7D%0A    return values%0A%0A
 class We
@@ -1553,128 +1553,33 @@
     
-script = %22%5Cn%22.join(%5B'%3Cscript type=%22text/javascript%22 src=%22%25s%22%3E%3C/script%3E' %25 i for i in manifest_list('js', db=request.db)%5D
+values = template_values(
 )%0A  
@@ -1582,35 +1582,40 @@
 )%0A        values
- = 
+.update(
 %7B%0A            's
@@ -1613,32 +1613,25 @@
        '
-script' : script
+uid': uid
 ,%0A      
@@ -1662,136 +1662,8 @@
 le,%0A
-            'request': request,%0A            'registry': request.registry,%0A            'cr': request.cr,%0A            'uid': uid,%0A
     
@@ -1763,32 +1763,33 @@
 text),%0A        %7D
+)
 %0A        html = 

factorize values