1707 |
1707 |
register_field_class(PasswordField)
|
1708 |
1708 |
|
1709 |
1709 |
|
|
1710 |
class CaptchaField(Field):
|
|
1711 |
key = 'captcha'
|
|
1712 |
description = N_('CAPTCHA')
|
|
1713 |
in_listing = False
|
|
1714 |
|
|
1715 |
hint = None
|
|
1716 |
mode = 'arithmetic-simple'
|
|
1717 |
extra_attributes = ['mode']
|
|
1718 |
|
|
1719 |
widget_class = CaptchaWidget
|
|
1720 |
|
|
1721 |
def add_to_form(self, form, value=None):
|
|
1722 |
if get_session().won_captcha:
|
|
1723 |
form.add(HiddenWidget, 'f%s' % self.id)
|
|
1724 |
return
|
|
1725 |
if self.hint and self.hint.startswith('<'):
|
|
1726 |
hint = htmltext(self.hint)
|
|
1727 |
else:
|
|
1728 |
hint = self.hint
|
|
1729 |
form.add(self.widget_class, 'f%s' % self.id, title=self.label, hint=hint)
|
|
1730 |
|
|
1731 |
def add_to_view_form(self, form, value=None):
|
|
1732 |
form.add(HiddenWidget, 'f%s' % self.id)
|
|
1733 |
|
|
1734 |
def get_admin_attributes(self):
|
|
1735 |
return Field.get_admin_attributes(self) + self.extra_attributes
|
|
1736 |
|
|
1737 |
def fill_admin_form(self, form):
|
|
1738 |
form.add(StringWidget, 'label', title=_('Label'), value=self.label,
|
|
1739 |
required=True, size=50)
|
|
1740 |
form.add(TextWidget, 'hint', title=_('Hint'), value=self.hint,
|
|
1741 |
cols=60, rows=3)
|
|
1742 |
modes = [('arithmetic-simple', _('Simple Arithmetic (plus and minus)')),
|
|
1743 |
('arithmetic', _('Arithmetic (includes multiplication)')),
|
|
1744 |
]
|
|
1745 |
form.add(SingleSelectWidget, 'mode', title=_('Mode'),
|
|
1746 |
value=self.mode, options=modes)
|
|
1747 |
|
|
1748 |
register_field_class(CaptchaField)
|
|
1749 |
|
|
1750 |
|
1710 |
1751 |
def get_field_class_by_type(type):
|
1711 |
1752 |
for k in field_classes:
|
1712 |
1753 |
if k.key == type:
|
1713 |
|
-
|