Ir al contenido
Menú
Se marcó esta pregunta
3 Respuestas
4249 Vistas

I am trying to restrict all blogs access to only authenticated users, I am using the following class to override the blog routes:

class RestrictWebBLog(WebsiteBlog):

@http.route(auth='user')
def blogs(self):
return super(RestrictWebBLog, self).blogs()

@http.route(auth='user')
def blog_post(self):
return super(RestrictWebBLog, self).blog_post()

@http.route(auth='user')
def blog(self):
return super(RestrictWebBLog, self).blog()

It seems to work, because login is required when trying to access any blog, but after entering credentials, the following error appears:  

500: Internal Server Error

Error message:

blog() got an unexpected keyword argument 'blog'
Traceback (most recent call last):
  File "/opt/odoo/odoo/addons/base/models/ir_http.py", line 203, in _dispatch
    result = request.dispatch()
  File "/opt/odoo/odoo/http.py", line 833, in dispatch
    r = self._call_function(**self.params)
  File "/opt/odoo/odoo/http.py", line 344, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/opt/odoo/odoo/service/model.py", line 97, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/odoo/odoo/http.py", line 337, in checked_call
    result = self.endpoint(*a, **kw)
  File "/opt/odoo/odoo/http.py", line 939, in __call__
    return self.method(*args, **kw)
  File "/opt/odoo/odoo/http.py", line 517, in response_wrap
    response = f(*args, **kw)
TypeError: blog() got an unexpected keyword argument 'blog'

Avatar
Descartar
Mejor respuesta

Try to override the route methods with all the parameters as they are defined in the main module and then make your change.

Ex:

@http.route([
'/blog',
'/blog/page/<int:page>',
], type='http', auth="user", website=True)


Avatar
Descartar
Mejor respuesta

Another simpler way which involves only editing the corresponding View, is to add inside the HTML element the following code:

t-if="request.env.user.id == request.env.ref('base.public_user').id"

For example:

<div class="alert alert-primary" t-if="request.env.user.id != request.env.ref('base.public_user').id">
    <h4>Message Title</4>
    <p>This is a Custom Message</p>
</div>

This will show a Custom Message only for Logged in Users.

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
2
ene 20
5044
2
sept 22
1600
2
jun 22
3204
0
nov 21
2163
2
nov 21
2963