# -*- coding: utf-8 -*- from django import forms from django.utils.safestring import mark_safe class SubmitButton(forms.Widget): """ A widget that handles a submit button. """ def __init__(self, name, value, label, attrs): self.name, self.value, self.label = name, value, label self.attrs = attrs def __unicode__(self): final_attrs = self.build_attrs( self.attrs, type="submit", name=self.name, value=self.value, ) return mark_safe(u'%s' % ( forms.widgets.flatatt(final_attrs), self.label, )) class MultipleSubmitButton(forms.Select): """ A widget that handles a list of submit buttons. """ def __init__(self, attrs={}, choices=()): self.attrs = attrs self.choices = choices def __iter__(self): for value, label in self.choices: yield SubmitButton(self.name, value, label, self.attrs.copy()) def __unicode__(self): return '