Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3 Odpowiedzi
4267 Widoki

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'

Awatar
Odrzuć
Najlepsza odpowiedź

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)


Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
sty 20
5070
2
wrz 22
1614
2
cze 22
3229
0
lis 21
2189
2
lis 21
2979