<commit_before># -*- coding: utf-8 -*-
import openerp
from openerp.addons.web import http
from openerp.addons.web.controllers.main import manifest_list
from urllib import quote_plus
from openerp.addons.web.http import request

def template_values():
    script = "\n".join(['<script type="text/javascript" src="%s"></script>' % i for i in manifest_list('js', db=request.db)])
    css = "\n".join('<link rel="stylesheet" href="%s">' % i for i in manifest_list('css', db=request.db))
    try:
        request.session.check_security()
        loggued = True
        uid = request.session._uid
    except http.SessionExpiredException:
        loggued = False
        uid = openerp.SUPERUSER_ID
    values = {
        'loggued': loggued,
        'editable': loggued,
        'request': request,
        'registry': request.registry,
        'cr': request.cr,
        'uid': uid,
        'script': script,
        'css': css,
    }
    return values

class Website(openerp.addons.web.controllers.main.Home):
    @http.route('/', type='http', auth="admin")
    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('/pagenew/<path:path>', type='http', auth="admin")
    def pagenew(self, path):
        values = template_values()
        uid = values['uid']
        imd = request.registry['ir.model.data']
        view_model, view_id = imd.get_object_reference(request.cr, uid, 'website', 'default_page')
        newview_id = request.registry['ir.ui.view'].copy(request.cr, uid, view_id)
        if '.' in path:
            module, idname = path.split('.')
        else:
            module = False
            idname = path
        imd.create(request.cr, uid, {
            'name': idname,
            'module': module,
            'model': 'ir.ui.view',
            'res_id': newview_id,
        })
        # TODO: replace by a redirect
        return self.page(path)

    @http.route('/page/<path:path>', type='http', auth="admin")
    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)
        values = template_values()
        uid = values['uid']
        context = {
            'inherit_branding': values['editable'],
        }
        company = request.registry['res.company'].browse(request.cr, uid, 1, context=context)
        values.update({
            'res_company': company,
            'path': path
        })
        values['google_map_url'] = "http://maps.googleapis.com/maps/api/staticmap?center=%s&sensor=false&zoom=8&size=298x298" \
                % quote_plus('%s, %s %s, %s' % (company.street, company.city, company.zip, company.country_id and company.country_id.name_get()[0][1] or ''))
        try:
            html = request.registry.get("ir.ui.view").render(request.cr, uid, path, values, context)
        except ValueError, e:
            html = request.registry.get("ir.ui.view").render(request.cr, uid, 'website.404', values, context)
        return html

# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:<commit_msg>[IMP] manual urllib.quote_plus -> bulk urllib.urlencode<commit_after># -*- coding: utf-8 -*-
import urllib

import openerp
from openerp.addons.web import http
from openerp.addons.web.controllers.main import manifest_list
from openerp.addons.web.http import request

def template_values():
    script = "\n".join(['<script type="text/javascript" src="%s"></script>' % i for i in manifest_list('js', db=request.db)])
    css = "\n".join('<link rel="stylesheet" href="%s">' % i for i in manifest_list('css', db=request.db))
    try:
        request.session.check_security()
        loggued = True
        uid = request.session._uid
    except http.SessionExpiredException:
        loggued = False
        uid = openerp.SUPERUSER_ID
    values = {
        'loggued': loggued,
        'editable': loggued,
        'request': request,
        'registry': request.registry,
        'cr': request.cr,
        'uid': uid,
        'script': script,
        'css': css,
    }
    return values

class Website(openerp.addons.web.controllers.main.Home):
    @http.route('/', type='http', auth="admin")
    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('/pagenew/<path:path>', type='http', auth="admin")
    def pagenew(self, path):
        values = template_values()
        uid = values['uid']
        imd = request.registry['ir.model.data']
        view_model, view_id = imd.get_object_reference(request.cr, uid, 'website', 'default_page')
        newview_id = request.registry['ir.ui.view'].copy(request.cr, uid, view_id)
        if '.' in path:
            module, idname = path.split('.')
        else:
            module = False
            idname = path
        imd.create(request.cr, uid, {
            'name': idname,
            'module': module,
            'model': 'ir.ui.view',
            'res_id': newview_id,
        })
        # TODO: replace by a redirect
        return self.page(path)

    @http.route('/page/<path:path>', type='http', auth="admin")
    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)
        values = template_values()
        uid = values['uid']
        context = {
            'inherit_branding': values['editable'],
        }
        company = request.registry['res.company'].browse(request.cr, uid, 1, context=context)
        values.update(
            res_company=company,
            path=path,
            google_map_url="http://maps.googleapis.com/maps/api/staticmap?" + urllib.urlencode({
                'center': '%s, %s %s, %s' % (company.street, company.city, company.zip, company.country_id and company.country_id.name_get()[0][1] or ''),
                'sensor': 'false',
                'zoom': '8',
                'size': '298x298',
            }),
        )
        try:
            html = request.registry.get("ir.ui.view").render(request.cr, uid, path, values, context)
        except ValueError, e:
            html = request.registry.get("ir.ui.view").render(request.cr, uid, 'website.404', values, context)
        return html

# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:
{'fraction_non_alphanumeric': 0.1617070692408187, 'fraction_numerical': 0.005516040063869938, 'mean_word_length': 2.6035564853556483, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5505682', 'n_tokens_mistral': 2202, 'n_tokens_neox': 2159, 'n_words': 446}