Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError while using a value_class #5

Open
chadsaun opened this issue Mar 8, 2021 · 0 comments
Open

AttributeError while using a value_class #5

chadsaun opened this issue Mar 8, 2021 · 0 comments

Comments

@chadsaun
Copy link

chadsaun commented Mar 8, 2021

  • wagtail_cache_block version: 0.1.3
  • Django version: 2.2
  • Python version: 3..6
  • Operating System: Linux

Description

I used the cache_block template tag{% cache_block 300 request block %}...

    {% for card in self.product_cards %}
      {% cache_block 300 request card %}
        {% include_block card with request=request block=card only %}
      {% endcache_block %}
    {% endfor %}

...and got the following error

AttributeError at /
'ProductCardValue' object has no attribute 'value'

The error happened on this line of code for k, v in block_obj.value.bound_blocks.items(): which is in the middle of the below code...

def extract_block(block_obj):
    """
    Extract block values to vary_on list
    """
    vary_on = []
    if isinstance(block_obj.block, StructBlock):
        tmp_dict = {}
        for k, v in block_obj.value.bound_blocks.items():
            tmp_dict[k] = extract_block(v)
        vary_on.append({block_obj.block.name: tmp_dict})
    elif isinstance(block_obj.block, StreamBlock):
        tmp_ls = []
        for child in block_obj.value:
            sub_value = extract_block(child)

The block_obj is a ProductCardValue object which is this below:

class ProductCardValue(StructValue):
    
    def review_aggregate_data(self):
        
        ...
        
        return {}
    
    def product_info(self):

        ...
        
        return {}

The ProductCardValue is used by the ProductCardBlock as seen below:

class ProductCardBlock(blocks.StructBlock):
    title_link = LinkBlock(help_text='The title of the product')
    image_link = LinkBlock(required=False, help_text='The main image with a link')
    body = blocks.RichTextBlock(required=False, features=RICH_TEXT_FEATURES)
    product_id = blocks.ChoiceBlock(required=False, choices=PRODUCT_CHOICES, help_text='The product')
    show_product_reviews = blocks.BooleanBlock(required=False, help_text='Do you want to show the product review stars?')
    
    class Meta:
        template = 'streams/product_card_block.html'
        icon = 'placeholder'
        label = 'Product Card'
        value_class = ProductCardValue

Does this not work if you are using a value_class?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant