Skip to content
Snippets Groups Projects
Commit 66d594e4 authored by Štěpán Farka's avatar Štěpán Farka Committed by jan.bednarik
Browse files

[FIX] rewardID per block

parent a59da545
No related branches found
No related tags found
2 merge requests!576Release,!573[ADD] crowdfunding rewards
Pipeline #9071 passed
from django.forms.utils import ErrorList
from wagtail.blocks import CharBlock, DateBlock, IntegerBlock, ListBlock, StructBlock from wagtail.blocks import CharBlock, DateBlock, IntegerBlock, ListBlock, StructBlock
from wagtail.blocks.struct_block import StructBlockValidationError
from wagtail.images.blocks import ImageChooserBlock from wagtail.images.blocks import ImageChooserBlock
class CrowdfundingVariantBlock(StructBlock):
reward_id = IntegerBlock(label="ID odměny")
title = CharBlock(
label="Název varianty", max_length=12, help_text="Například velikost: S"
)
class Meta:
icon = "radio-empty"
class CrowdfundingRewardBlock(StructBlock): class CrowdfundingRewardBlock(StructBlock):
title = CharBlock(label="Název odměny") title = CharBlock(label="Název odměny")
description = CharBlock(label="Popis", max_length=255, required=False) description = CharBlock(label="Popis", max_length=255, required=False)
...@@ -22,26 +10,14 @@ class CrowdfundingRewardBlock(StructBlock): ...@@ -22,26 +10,14 @@ class CrowdfundingRewardBlock(StructBlock):
delivery_date = DateBlock(label="Datum dodání", required=False) delivery_date = DateBlock(label="Datum dodání", required=False)
reward_id = IntegerBlock( reward_id = IntegerBlock(
label="ID odměny", label="ID odměny",
help_text="Vyplňte pouze v případě, že odměna nemá varianty", required=True,
required=False,
)
crm_product_description = CharBlock(
label="Popis produktu pro CRM",
help_text='Bude předán systému v parametru "product"',
required=False,
) )
variant_list = ListBlock( variant_list = ListBlock(
CrowdfundingVariantBlock(), label="Varianty", required=False CharBlock(label="Varianta", max_length=12, help_text="Například velikost: S"),
label="Varianty",
) )
class Meta: class Meta:
template = "donate/blocks/crowdfunding_reward_block.html" template = "donate/blocks/crowdfunding_reward_block.html"
icon = "pick" icon = "pick"
label = "Odměna" label = "Odměna"
def clean(self, value):
errors = {}
if not value["reward_id"] and not value["variant_list"]:
errors["reward_id"] = ErrorList(["Musíte vyplnit ID odměny"])
raise StructBlockValidationError(errors)
return super().clean(value)
...@@ -2,6 +2,7 @@ import urllib.parse ...@@ -2,6 +2,7 @@ import urllib.parse
from django import forms from django import forms
from django.conf import settings from django.conf import settings
from django.utils.text import slugify
class DonateForm(forms.Form): class DonateForm(forms.Form):
...@@ -21,6 +22,8 @@ class DonateForm(forms.Form): ...@@ -21,6 +22,8 @@ class DonateForm(forms.Form):
value = self.cleaned_data["periodicity"] value = self.cleaned_data["periodicity"]
if value not in self.ALLOWED_PERIODICITY: if value not in self.ALLOWED_PERIODICITY:
raise forms.ValidationError("Wrong periodicity!") raise forms.ValidationError("Wrong periodicity!")
if self.cleaned_data["crowdfunding"] and value != 99999:
raise forms.ValidationError("Wrong periodicity!")
return value return value
def clean(self): def clean(self):
...@@ -32,6 +35,10 @@ class DonateForm(forms.Form): ...@@ -32,6 +35,10 @@ class DonateForm(forms.Form):
raise forms.ValidationError("Není zadán účel daru.") raise forms.ValidationError("Není zadán účel daru.")
if not cleaned_data["amount"] and not cleaned_data["custom_amount"]: if not cleaned_data["amount"] and not cleaned_data["custom_amount"]:
raise forms.ValidationError("Nebyla zadána částka.") raise forms.ValidationError("Nebyla zadána částka.")
if cleaned_data["crowdfunding"] and not cleaned_data["product"]:
raise forms.ValidationError("Nebyla zadána produkt.")
if cleaned_data["product"] and not cleaned_data["crowdfunding"]:
raise forms.ValidationError("Nebyla zadána typ odměny.")
return cleaned_data return cleaned_data
def get_amount(self): def get_amount(self):
...@@ -60,9 +67,8 @@ class DonateForm(forms.Form): ...@@ -60,9 +67,8 @@ class DonateForm(forms.Form):
} }
if crowdfunding: if crowdfunding:
query_dict.update(crowdfunding=crowdfunding) product = slugify(product)
if product: query_dict.update(crowdfunding=crowdfunding, product=product)
query_dict.update(product=product)
query = urllib.parse.urlencode(query_dict) query = urllib.parse.urlencode(query_dict)
......
# Generated by Django 4.0.4 on 2022-07-26 10:35 # Generated by Django 4.0.4 on 2022-07-31 05:26
import wagtail.blocks import wagtail.blocks
import wagtail.fields import wagtail.fields
...@@ -48,42 +48,18 @@ class Migration(migrations.Migration): ...@@ -48,42 +48,18 @@ class Migration(migrations.Migration):
( (
"reward_id", "reward_id",
wagtail.blocks.IntegerBlock( wagtail.blocks.IntegerBlock(
help_text="Vyplňte pouze v případě, že odměna nemá varianty", label="ID odměny", required=True
label="ID odměny",
required=False,
),
),
(
"crm_product_description",
wagtail.blocks.CharBlock(
help_text='Bude předán systému v parametru "product"',
label="Popis produktu pro CRM",
required=False,
), ),
), ),
( (
"variant_list", "variant_list",
wagtail.blocks.ListBlock( wagtail.blocks.ListBlock(
wagtail.blocks.StructBlock( wagtail.blocks.CharBlock(
[ help_text="Například velikost: S",
( label="Varianta",
"reward_id", max_length=12,
wagtail.blocks.IntegerBlock(
label="ID odměny"
),
),
(
"title",
wagtail.blocks.CharBlock(
help_text="Například velikost: S",
label="Název varianty",
max_length=12,
),
),
]
), ),
label="Varianty", label="Varianty",
required=False,
), ),
), ),
] ]
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<input type="hidden" name="portal_project_id" value="{{ page.portal_project_id }}"> <input type="hidden" name="portal_project_id" value="{{ page.portal_project_id }}">
<input type="hidden" name="periodicity" value="99999"> <input type="hidden" name="periodicity" value="99999">
<input type="hidden" name="amount" value="{{ self.amount }}"> <input type="hidden" name="amount" value="{{ self.amount }}">
<input type="hidden" name="product" value="{{ self.crm_product_description }}"> <input type="hidden" name="crowdfunding" value="{{ self.reward_id }}">
<h3 class="lead mb-3">{{ self.title }}</h3> <h3 class="lead mb-3">{{ self.title }}</h3>
<div class="row"> <div class="row">
<figure class="col-12 col-md-7"> <figure class="col-12 col-md-7">
...@@ -15,22 +15,24 @@ ...@@ -15,22 +15,24 @@
</figure> </figure>
<div class="col-12 col-md-5"> <div class="col-12 col-md-5">
{{ self.description }}<br> {{ self.description }}<br>
{% if self.variant_list %} {% if self.variant_list %}
<small>Zvolte si varaintu:</small> <small>Zvolte si varaintu:</small>
{% for variant in self.variant_list %} {% for variant in self.variant_list %}
<div class="custom-control form-control-md custom-radio"> <div class="custom-control form-control-md custom-radio">
<input type="radio" id="reward-{{ variant.reward_id }}" name="crowdfunding" <input type="radio" id="product-{{ forloop.counter }}" name="product"
value="{{ variant.reward_id }}" value="{{ self.title }}-{{ variant }}"
class="custom-control-input form-control-md" required> class="custom-control-input form-control-md" required>
<label class="custom-control-label col-form-label-lg" <label class="custom-control-label col-form-label-lg"
for="reward-{{ variant.reward_id }}">{{ variant.title }}</label> for="product-{{ forloop.counter }}">{{ variant }}</label>
</div> </div>
{% endfor %} {% endfor %}
{% else %} {% else %}
<input id="reward-{{ self.reward_id }}" name="crowdfunding" <input name="product"
value="{{ self.reward_id }}" hidden value="{{ self.title }}"
class="custom-control-input form-control-md" required> hidden
class="custom-control-input form-control-md"
required
>
{% endif %} {% endif %}
</div> </div>
</div> </div>
...@@ -38,10 +40,12 @@ ...@@ -38,10 +40,12 @@
<div class="col-7 mb-2 mb-md-0"> <div class="col-7 mb-2 mb-md-0">
<button type="submit" class="btn btn-danger btn-md">Darovat {{ self.amount }}&nbsp;</button> <button type="submit" class="btn btn-danger btn-md">Darovat {{ self.amount }}&nbsp;</button>
</div> </div>
<p class="col-12 col-md-5"> {% if self.delivery_date %}
Dodání do: <br> <p class="col-12 col-md-5">
<time datetime="2019-06-18">{{ self.delivery_date|date:"d. m. Y" }}</time> Dodání do: <br>
</p> <time datetime="2019-06-18">{{ self.delivery_date|date:"d. m. Y" }}</time>
</p>
{% endif %}
</div> </div>
</form> </form>
</div> </div>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment