# -*- 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, )