Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
class SmallIntegerField(
_OtreeNumericFieldMixin, models.SmallIntegerField):
pass
class TextField(_OtreeModelFieldMixin, models.TextField):
auto_submit_default = ''
class TimeField(_OtreeModelFieldMixin, models.TimeField):
pass
class URLField(_OtreeModelFieldMixin, models.URLField):
pass
ForeignKey = models.ForeignKey
ManyToOneRel = related.ManyToOneRel
ManyToManyField = models.ManyToManyField
OneToOneField = models.OneToOneField
# aliases we might use in the future
StringField = CharField
LongStringField = TextField
class SlugField(_OtreeModelFieldMixin, models.SlugField):
pass
class SmallIntegerField(
_OtreeNumericFieldMixin, models.SmallIntegerField):
pass
class TextField(_OtreeModelFieldMixin, models.TextField):
auto_submit_default = ''
class TimeField(_OtreeModelFieldMixin, models.TimeField):
pass
class URLField(_OtreeModelFieldMixin, models.URLField):
pass
ForeignKey = models.ForeignKey
ManyToOneRel = related.ManyToOneRel
ManyToManyField = models.ManyToManyField
OneToOneField = models.OneToOneField
# aliases we might use in the future
StringField = CharField
LongStringField = TextField
return super(BooleanField, self).clean(value, model_instance)
def formfield(self, *args, **kwargs):
from otree import widgets
is_checkbox_widget = isinstance(self.widget, widgets.CheckboxInput)
if not self._blank_is_explicit and is_checkbox_widget:
kwargs.setdefault('required', False)
else:
# this use the allow_blank for the form fields
kwargs.setdefault('required', not self.allow_blank)
return super(BooleanField, self).formfield(*args, **kwargs)
class AutoField(_OtreeModelFieldMixin, models.AutoField):
pass
class BigIntegerField(
_OtreeNumericFieldMixin, models.BigIntegerField):
auto_submit_default = 0
class BinaryField(_OtreeModelFieldMixin, models.BinaryField):
pass
# FIXME: CharField should never be nullable, otherwise there is ambiguity
# when a form field is left empty (whether it's null or empty string)
class CharField(_OtreeModelFieldMixin, models.CharField):
def __init__(
# themselves. also, "default" could be misleading -- people could think
# it's the default choice in the form
kwargs.setdefault('default', kwargs.pop('initial'))
# if default=None, Django will omit the blank choice from form widget
# https://code.djangoproject.com/ticket/10792
# that is contrary to the way oTree views blank/None values, so to
# correct for this, we get rid of default=None args.
# setting null=True already should make the field null
if 'default' in kwargs and kwargs['default'] is None:
kwargs.pop('default')
super(_OtreeModelFieldMixin, self).__init__(**kwargs)
class _OtreeNumericFieldMixin(_OtreeModelFieldMixin):
auto_submit_default = 0
class BaseCurrencyField(
_OtreeNumericFieldMixin, models.DecimalField,
metaclass=models.SubfieldBase):
MONEY_CLASS = None # need to set in subclasses
def __init__(self, **kwargs):
# i think it's sufficient just to store a high number;
# this needs to be higher than decimal_places
decimal_places = self.MONEY_CLASS.get_num_decimal_places()
# where does this come from?
max_digits=12
super().__init__(
max_digits=max_digits, decimal_places=decimal_places, **kwargs)
kwargs.setdefault('null', True)
super(CharField, self).__init__(
choices=choices,
widget=widget,
initial=initial,
label=label,
doc=doc,
max_length=max_length,
blank=blank,
**kwargs)
auto_submit_default = ''
class CommaSeparatedIntegerField(_OtreeModelFieldMixin,
models.CommaSeparatedIntegerField):
pass
class DateField(_OtreeModelFieldMixin, models.DateField):
pass
class DateTimeField(_OtreeModelFieldMixin, models.DateTimeField):
pass
class DecimalField(
_OtreeNumericFieldMixin,
models.DecimalField):
pass
blank=blank,
**kwargs)
auto_submit_default = ''
class CommaSeparatedIntegerField(_OtreeModelFieldMixin,
models.CommaSeparatedIntegerField):
pass
class DateField(_OtreeModelFieldMixin, models.DateField):
pass
class DateTimeField(_OtreeModelFieldMixin, models.DateTimeField):
pass
class DecimalField(
_OtreeNumericFieldMixin,
models.DecimalField):
pass
class EmailField(_OtreeModelFieldMixin, models.EmailField):
pass
class FileField(_OtreeModelFieldMixin, models.FileField):
pass
# "initial" is an alias for default. in the context of oTree, 'initial'
# is a more intuitive name. (since the user never instantiates objects
# themselves. also, "default" could be misleading -- people could think
# it's the default choice in the form
kwargs.setdefault('default', kwargs.pop('initial'))
# if default=None, Django will omit the blank choice from form widget
# https://code.djangoproject.com/ticket/10792
# that is contrary to the way oTree views blank/None values, so to
# correct for this, we get rid of default=None args.
# setting null=True already should make the field null
if 'default' in kwargs and kwargs['default'] is None:
kwargs.pop('default')
super(_OtreeModelFieldMixin, self).__init__(**kwargs)
class DateField(_OtreeModelFieldMixin, models.DateField):
pass
class DateTimeField(_OtreeModelFieldMixin, models.DateTimeField):
pass
class DecimalField(
_OtreeNumericFieldMixin,
models.DecimalField):
pass
class EmailField(_OtreeModelFieldMixin, models.EmailField):
pass
class FileField(_OtreeModelFieldMixin, models.FileField):
pass
class FilePathField(_OtreeModelFieldMixin, models.FilePathField):
pass
class FloatField(
_OtreeNumericFieldMixin,
models.FloatField):
pass
class PositiveSmallIntegerField(
_OtreeNumericFieldMixin,
models.PositiveSmallIntegerField):
pass
class SlugField(_OtreeModelFieldMixin, models.SlugField):
pass
class SmallIntegerField(
_OtreeNumericFieldMixin, models.SmallIntegerField):
pass
class TextField(_OtreeModelFieldMixin, models.TextField):
auto_submit_default = ''
class TimeField(_OtreeModelFieldMixin, models.TimeField):
pass
class URLField(_OtreeModelFieldMixin, models.URLField):
pass
ForeignKey = models.ForeignKey
ManyToOneRel = related.ManyToOneRel
ManyToManyField = models.ManyToManyField
OneToOneField = models.OneToOneField
# this use the allow_blank for the form fields
kwargs.setdefault('required', not self.allow_blank)
return super(BooleanField, self).formfield(*args, **kwargs)
class AutoField(_OtreeModelFieldMixin, models.AutoField):
pass
class BigIntegerField(
_OtreeNumericFieldMixin, models.BigIntegerField):
auto_submit_default = 0
class BinaryField(_OtreeModelFieldMixin, models.BinaryField):
pass
# FIXME: CharField should never be nullable, otherwise there is ambiguity
# when a form field is left empty (whether it's null or empty string)
class CharField(_OtreeModelFieldMixin, models.CharField):
def __init__(
self,
*,
choices=None,
widget=None,
initial=None,
label=None,
doc='',
# varchar max length doesn't affect performance or even storage
# size; it's just for validation. so, to be easy to use,