简体   繁体   English

如何在自定义 wagtail 块中使用功能标志?

[英]How can I use a feature flag within a custom wagtail block?

I'm working on a project where we would like to add a new option for a StreamBlock but only have that option be available to some (paid) users.我正在做一个项目,我们想为 StreamBlock 添加一个新选项,但只有某些(付费)用户可以使用该选项。 So, ideally we would like to put this new option behind a feature flag.所以,理想情况下,我们希望将这个新选项放在功能标志后面。

A very simplified version of what I want to do with our code looks like this:我想用我们的代码做的事情的一个非常简化的版本如下所示:

class OneColumnBlock(StreamBlock):
    paragraph = ParagraphBlock()
    image = ImageBlock()
    if feature_flag_is_on_for_site:
        embed = CustomEmbedBlock(max_width=800)


class ScrollingExhibitPage(Page):
    body = StreamField(
        [("one_column", OneColumnBlock()), ("two_column", TwoColumnBlock()), ("full_width", FullWidthBlock())]
    )

    content_panels = Page.content_panels + [
        StreamFieldPanel("body", heading="Body"),
    ]

We want to make that embed option only available to some specific users.我们希望该embed选项仅对某些特定用户可用。 If the embed was at the same level as body I think I could figure out how to put it behind a flag in the content_panels section but since it is inside a custom StreamBlock and that affects the database set up, I'm not sure how to do that effectively.如果embedbody处于同一级别,我想我可以弄清楚如何将它放在content_panels部分的标志后面,但由于它位于自定义StreamBlock内并且会影响数据库设置,我不确定如何有效地做到这一点。

We do something like this - but at the block level and the feature is enabled at the site level rather than the user level.我们做这样的事情 - 但在块级别并且该功能在站点级别而不是用户级别启用。 The code is in our wagtail-jetstream repository.代码在我们的 wagtail-jetstream 存储库中。 The Iframe block is the block that has to be 'enabled' to be used. Iframe 块是必须“启用”才能使用的块。 Code for our FeatureCustomizedStreamBlock is https://github.com/caltechads/wagtail-jetstream/blob/master/jetstream/blocks.py#L46我们的 FeatureCustomizedStreamBlock 的代码是https://github.com/caltechads/wagtail-jetstream/blob/master/jetstream/blocks.py#L46

Feel free to ask additional questions if this approach sounds useful.如果此方法听起来有用,请随时提出其他问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM