Skip to Content
Menu
This question has been flagged
3 Replies
3434 Views

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
Discard
Best Answer

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
Discard
Best Answer

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
Discard
Related Posts Replies Views Activity
2
Jan 20
3928
2
Sep 22
723
2
Jun 22
1934
0
Nov 21
1217
2
Nov 21
1813