使用 Wagtail 2.9,我正在尝试创建一个具有生成 URL 的功能的块。要生成 URL,我需要当前登录的用户。
class Look(blocks.StructBlock):
title = blocks.CharBlock(required=True, help_text='Add your look title')
id = blocks.CharBlock(required=True, help_text='Enter the Id')
class Meta:
template = "looker/looker_block.html"
value_class = LookStructValue
值类的get_url()
定义如下:
class LookStructValue(blocks.StructValue):
def url(self):
id = self.get('id')
user = User(15,
first_name='This is where is need the current user First name',
last_name='and last name',
permissions=['some_permission'],
models=['some_model'],
group_ids=[2],
external_group_id='awesome_engineers',
user_attributes={"test": "test",
"test_count": "1"},
access_filters={})
url_path = "/embed/looks/" + id
url = URL(user,url_path, force_logout_login=True)
return "https://" + url.to_string()
我可以在 LookStructValue 类中获取当前用户吗?