跳至内容
菜单
此问题已终结
3 回复
4343 查看

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'

形象
丢弃
最佳答案

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)


形象
丢弃
最佳答案

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.

形象
丢弃
相关帖文 回复 查看 活动
2
1月 20
5199
2
9月 22
1704
2
6月 22
3361
0
11月 21
2318
2
11月 21
3086