[FIX] altered trunk routing stuff, bring website converters back in website
bzr revid: xmo@openerp.com-20131115132626-60p0yk3jv1pk6mhb
This commit is contained in:
parent
60863b5ab0
commit
e7117a5799
|
@ -22,17 +22,10 @@ from openerp.addons.website.models import website
|
|||
from openerp.addons.web import http
|
||||
from openerp.addons.web.http import request
|
||||
|
||||
from ..utils import slugify
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def auth_method_public():
|
||||
registry = openerp.modules.registry.RegistryManager.get(request.db)
|
||||
if not request.session.uid:
|
||||
request.uid = registry['website'].get_public_user(request.cr, openerp.SUPERUSER_ID, request.context).id
|
||||
else:
|
||||
request.uid = request.session.uid
|
||||
http.auth_methods['public'] = auth_method_public
|
||||
|
||||
NOPE = object()
|
||||
# Completely arbitrary limits
|
||||
MAX_IMAGE_WIDTH, MAX_IMAGE_HEIGHT = IMAGE_LIMITS = (1024, 768)
|
||||
|
@ -57,7 +50,7 @@ class Website(openerp.addons.web.controllers.main.Home):
|
|||
def pagenew(self, path, noredirect=NOPE):
|
||||
module = 'website'
|
||||
# completely arbitrary max_length
|
||||
idname = http.slugify(path, max_length=50)
|
||||
idname = slugify(path, max_length=50)
|
||||
|
||||
request.cr.execute('SAVEPOINT pagenew')
|
||||
imd = request.registry['ir.model.data']
|
||||
|
|
|
@ -4,5 +4,6 @@ import ir_ui_view
|
|||
import website
|
||||
import ir_rule
|
||||
import ir_qweb
|
||||
import ir_http
|
||||
|
||||
import test_models
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import openerp
|
||||
from openerp.osv import orm
|
||||
from openerp.http import request
|
||||
from openerp.addons.base import ir
|
||||
|
||||
from ..utils import slugify
|
||||
|
||||
class ir_http(orm.AbstractModel):
|
||||
_inherit = 'ir.http'
|
||||
|
||||
def _get_converters(self):
|
||||
return dict(
|
||||
super(ir_http, self)._get_converters(),
|
||||
model=ModelConverter,
|
||||
)
|
||||
|
||||
def _auth_method_public(self):
|
||||
if not request.session.uid:
|
||||
request.uid = request.registry['website'].get_public_user(
|
||||
request.cr, openerp.SUPERUSER_ID, request.context).id
|
||||
else:
|
||||
request.uid = request.session.uid
|
||||
|
||||
|
||||
class ModelConverter(ir.ir_http.ModelConverter):
|
||||
def __init__(self, url_map, model=False):
|
||||
super(ModelConverter, self).__init__(url_map, model)
|
||||
self.regex = r'[A-Za-z0-9-_]*?(\d+)'
|
||||
|
||||
def to_url(self, value):
|
||||
[(_, name)] = value.name_get()
|
||||
return "%s-%d" % (slugify(name), value.id)
|
||||
|
||||
def generate(self):
|
||||
for id in request.registry[self.model].search(request.cr, request.uid, [], context=request.context):
|
||||
yield request.registry[self.model].browse(request.cr, request.uid, id, context=request.context)
|
|
@ -0,0 +1,13 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import re
|
||||
|
||||
__all__ = ['slugify']
|
||||
|
||||
try:
|
||||
# use python-slugify (https://github.com/un33k/python-slugify) if available
|
||||
from slugify import slugify
|
||||
except ImportError:
|
||||
def slugify(s, max_length=None):
|
||||
spaceless = re.sub(r'\s+', '-', s)
|
||||
specialless = re.sub(r'[^-_A-Za-z0-9]', '', spaceless)
|
||||
return specialless[:max_length]
|
Loading…
Reference in New Issue