Testuji syntaxhighlighter…
class CurrencyWidget(forms.widgets.MultiWidget): std_curr = ['EUR', 'CHF', 'GBP', 'JPY', 'RUB', 'USD'] def __init__(self, czk=True, attrs=None): self._currlist = ((['CZK'] if czk else []) + self.std_curr) super(CurrencyWidget, self).__init__((forms.Select(choices=(map((lambda x: [x, x]), self._currlist) + [['OTH', u'Jiná:']]), attrs={'class': 'currsel'}), currw()), attrs) def decompress(self, value): if value in self._currlist: return [value, None] else: return ['OTH', value] def format_output(self, rw): return u' '.join(rw).replace('\n', '')
class CurrencyField(forms.MultiValueField): def __init__(self, czk=True, *args, **kwargs): kwargs['required'] = False super(CurrencyField, self).__init__(widget=widgets.CurrencyWidget(czk=czk), fields=(forms.CharField(), forms.CharField(min_length=3, max_length=3)), *args, **kwargs) def compress(self, dl): if dl: return (dl[1].upper() if (dl[0] == 'OTH') else dl[0]) else: return None def validate(self, value): if not value: self.widget.widgets[1].attrs['class'] += ' err' raise forms.ValidationError('Currency is required')
Komentáře
JM
kdo si hraje, ten nezlobi.
Jen nerozumim presne, co testujete.
Vzdyt prece uz krasne "highlightujete" sve weby davno, Paragraphos v modrem a zdejsi v maroon cervenem.
Doufam, ze nezamyslite zvyraznovat cela slova v jakemsi barevnem rameckovem pozadi, jako ta testovaci radka v bledemodrem, - nejen ze sem barevne neladi, ale bylo by to velice "tacky"...
RSS kanál komentářů k tomuto článku