def pagenew(self, path="", noredirect=False, add_menu=False, template=False): # for supported mimetype, get correct default template _, ext = os.path.splitext(path) View = request.env['ir.ui.view'] ext_special_case = ext and ext in _guess_mimetype() and ext != '.html' if not template and ext_special_case: default_templ = 'website.default_%s' % ext.lstrip('.') if request.env.ref(default_templ, False): template = default_templ template = template and dict(template=template) or {} page = request.env['website'].new_page(path, add_menu=add_menu, **template) url = page['url'] if noredirect: return werkzeug.wrappers.Response(url, mimetype='text/plain') if ext_special_case: # redirect non html pages to backend to edit return werkzeug.utils.redirect('/web#id=' + str(page.get('view_id')) + '&view_type=form&model=ir.ui.view') return werkzeug.utils.redirect(url + "?enable_editor=1")
def _serve_page(cls): req_page = request.httprequest.path page_domain = [('url', '=', req_page)] + request.website.website_domain() published_domain = page_domain # specific page first page = request.env['website.page'].sudo().search(published_domain, order='website_id asc', limit=1) # redirect withtout trailing / if not page and req_page != "/" and req_page.endswith("/"): return request.redirect(req_page[:-1]) if page: # prefetch all menus (it will prefetch website.page too) request.website.menu_id if page and (request.website.is_publisher() or page.is_visible): need_to_cache = False cache_key = page._get_cache_key(request) if ( page.cache_time # cache > 0 and request.httprequest.method == "GET" and request.env.user._is_public() # only cache for unlogged user and 'nocache' not in request.params # allow bypass cache / debug and not request.session.debug and len(cache_key) and cache_key[-1] is not None # nocache via expr ): need_to_cache = True try: r = page._get_cache_response(cache_key) if r['time'] + page.cache_time > time.time(): response = werkzeug.Response(r['content'], mimetype=r['contenttype']) response._cached_template = r['template'] response._cached_page = page return response except KeyError: pass _, ext = os.path.splitext(req_page) response = request.render(page.view_id.id, { 'deletable': True, 'main_object': page, }, mimetype=_guess_mimetype(ext)) if need_to_cache and response.status_code == 200: r = response.render() page._set_cache_response(cache_key, { 'content': r, 'contenttype': response.headers['Content-Type'], 'time': time.time(), 'template': getattr(response, 'qcontext', {}).get('response_template') }) return response return False
def _serve_page(cls): req_page = request.httprequest.path domain = [('url', '=', req_page), '|', ('website_ids', 'in', request.website.id), ('website_ids', '=', False)] if not request.website.is_publisher: domain += [('is_visible', '=', True)] mypage = request.env['website.page'].search(domain, limit=1) _, ext = os.path.splitext(req_page) if mypage: return request.render( mypage.view_id.id, { # 'path': req_page[1:], 'deletable': True, 'main_object': mypage, }, mimetype=_guess_mimetype(ext)) return False
def _serve_page(cls): req_page = request.httprequest.path domain = [('url', '=', req_page), '|', ('website_ids', 'in', request.website.id), ('website_ids', '=', False)] pages = request.env['website.page'].search(domain) if not request.website.is_publisher(): pages = pages.filtered('is_visible') mypage = pages[0] if pages else False _, ext = os.path.splitext(req_page) if mypage: return request.render( mypage.get_view_identifier(), { # 'path': req_page[1:], 'deletable': True, 'main_object': mypage, }, mimetype=_guess_mimetype(ext)) return False
def guess_mimetype(self): return _guess_mimetype()