hotpocket/services/backend/hotpocket_backend/apps/ui/forms/layout.py
Tomek Wójcik b4338e2769
Some checks failed
CI / Checks (push) Failing after 13m2s
Release v1.0.0
2025-08-20 21:00:50 +02:00

42 lines
1.1 KiB
Python

# -*- coding: utf-8 -*-
from __future__ import annotations
from crispy_forms.utils import TEMPLATE_PACK
from django.template.loader import render_to_string
class CancelButton:
CSS_CLASS = 'btn btn-secondary ui-form-cancel-button'
def __init__(self,
label: str,
*,
css_id: str | None = None,
css_class: str | None = None,
**attributes,
):
self.label = label
self.css_id = css_id
self.css_class = css_class
self.attributes = attributes
def render(self, form, context, template_pack: TEMPLATE_PACK, **kwargs):
final_attributes = {
'class': self.css_class or self.CSS_CLASS,
**self.attributes,
'type': 'button',
'value': self.label,
}
if self.css_id:
final_attributes['id'] = self.css_id
context = {
'attributes': final_attributes,
}
return render_to_string(
'ui/ui/forms/cancel_button.html',
context=context,
)