Ejemplo n.º 1
0
 def create_field(self,fld):
     meth = getattr(fld,'_return_type_for_method',None)
     if meth is not None:
         # uh, this is tricky...
         return MethodStoreField(fld)
     #~ if isinstance(fld,fields.HtmlBox):
         #~ ...
     if isinstance(fld,fields.VirtualField):
         delegate = self.create_field(fld.return_type)
         return VirtStoreField(fld,delegate)
     if isinstance(fld,models.FileField):
         return FileFieldStoreField(fld)
     if isinstance(fld,models.ManyToManyField):
         return StoreField(fld)
     if isinstance(fld,models.OneToOneField):
         return OneToOneStoreField(fld)
     if isinstance(fld,models.ForeignKey):
         return ForeignKeyStoreField(fld)
     if isinstance(fld,models.DateField):
         return DateStoreField(fld,settings.LINO.date_format_extjs)
         #~ return DateStoreField(fld,self.report.date_format)
     if isinstance(fld,models.BooleanField):
         return BooleanStoreField(fld)
     if isinstance(fld,models.AutoField):
         return AutoStoreField(fld)
         #~ kw.update(type='int')
     kw = {}
     if isinstance(fld,models.SmallIntegerField):
         kw.update(type='int')
     if isinstance(fld,models.IntegerField):
         kw.update(type='int')
     if choosers.uses_simple_values(fld):
         return StoreField(fld,**kw)
     else:
         return ComboStoreField(fld,**kw)
Ejemplo n.º 2
0
def create_atomizer(fld, name):
    if isinstance(fld, fields.RemoteField):
        """
        Hack: we create a StoreField based on the remote field,
        then modify its behaviour.
        """
        sf = create_atomizer(fld.field, fld.name)

        def value_from_object(sf, obj, ar):
            #~ if fld.name == 'event__when_text':
                #~ logger.info("20130802 create_atomizer RemoteField value_from_object")
            m = fld.func
            return m(obj, ar)

        def full_value_from_object(sf, obj, ar):
            #~ logger.info("20120406 %s.full_value_from_object(%s)",sf.name,sf)
            m = fld.func
            v = m(obj, ar)
            #~ if fld.name == 'event__when_text':
                #~ logger.info("20130802 full_value_from_object %s",obj)
            return v

        sf.value_from_object = curry(value_from_object, sf)
        sf.full_value_from_object = curry(full_value_from_object, sf)
        #~ sf.field = fld.field
        #~ sf.value2list = curry(value2list,sf)
        return sf
    #~ if isinstance(fld,tables.ComputedColumn):
        #~ logger.info("20111230 Store.create_atomizer(%s)", fld)
        #~ return ComputedColumnField(fld)
    meth = getattr(fld, '_return_type_for_method', None)
    if meth is not None:
        # uh, this is tricky...
        return MethodStoreField(fld, name)
    #~ if isinstance(fld,fields.HtmlBox):
        #~ ...
    #~ if isinstance(fld,dd.LinkedForeignKey):
        #~ return LinkedForeignKeyField(fld,name)

    sf_class = getattr(fld, 'lino_atomizer_class', None)
    if sf_class is not None:
        return sf_class(fld, name)

    if isinstance(fld, dd.RequestField):
        delegate = create_atomizer(fld.return_type, fld.name)
        return RequestStoreField(fld, delegate, name)
    if isinstance(fld, dd.VirtualField):
        delegate = create_atomizer(fld.return_type, fld.name)
        return VirtStoreField(fld, delegate, name)
    if isinstance(fld, models.FileField):
        return FileFieldStoreField(fld, name)
    if isinstance(fld, models.ManyToManyField):
        return StoreField(fld, name)
    if isinstance(fld, dd.PasswordField):
        return PasswordStoreField(fld, name)
    if isinstance(fld, models.OneToOneField):
        return OneToOneStoreField(fld, name)
    if isinstance(fld, generic.GenericForeignKey):
        return GenericForeignKeyField(fld, name)
    if isinstance(fld, dd.GenericForeignKeyIdField):
        return ComboStoreField(fld, name)
    if isinstance(fld, models.ForeignKey):
        return ForeignKeyStoreField(fld, name)
    if isinstance(fld, models.TimeField):
        return TimeStoreField(fld, name)
    if isinstance(fld, models.DateTimeField):
        return DateTimeStoreField(fld, name)
    if isinstance(fld, dd.IncompleteDateField):
        return IncompleteDateStoreField(fld, name)
    if isinstance(fld, models.DateField):
        return DateStoreField(fld, name)
    if isinstance(fld, models.BooleanField):
        return BooleanStoreField(fld, name)
    if isinstance(fld, models.DecimalField):
        return DecimalStoreField(fld, name)
    if isinstance(fld, models.AutoField):
        return AutoStoreField(fld, name)
        #~ kw.update(type='int')
    if isinstance(fld, models.SmallIntegerField):
        return IntegerStoreField(fld, name)
    if isinstance(fld, dd.DisplayField):
        return DisplayStoreField(fld, name)
    if isinstance(fld, models.IntegerField):
        return IntegerStoreField(fld, name)
    kw = {}
    if choosers.uses_simple_values(fld):
        return StoreField(fld, name, **kw)
    else:
        return ComboStoreField(fld, name, **kw)
Ejemplo n.º 3
0
Archivo: store.py Proyecto: NewRGB/lino
def create_atomizer(holder, fld, name):
    """
    The holder is where the (potential) choices come from. It can be
    a model, an actor or an action.
    """
    if name is None:
        return
        # raise Exception("20181023 create_atomizer() {}".format(fld))
    if isinstance(fld, fields.RemoteField):
        """
        Hack: we create a StoreField based on the remote field,
        then modify its behaviour.
        """
        sf = create_atomizer(holder, fld.field, fld.name)

        # print("20180712 create_atomizer {} from {}".format(sf, fld.field))

        def value_from_object(sf, obj, ar=None):
            m = fld.func
            return m(obj, ar)

        def full_value_from_object(sf, obj, ar=None):
            m = fld.func
            v = m(obj, ar)
            return v

        def set_value_in_object(sf, ar, instance, v):
            # print("20180712 {}.set_value_in_object({}, {})".format(
            #     sf, instance, v))
            old_value = sf.value_from_object(instance, ar.request)
            if old_value != v:
                return fld.setter(instance, v)

        sf.value_from_object = curry(value_from_object, sf)
        sf.full_value_from_object = curry(full_value_from_object, sf)
        sf.set_value_in_object = curry(set_value_in_object, sf)
        return sf

    meth = getattr(fld, '_return_type_for_method', None)
    if meth is not None:
        # uh, this is tricky...
        return MethodStoreField(fld, name)

    sf_class = getattr(fld, 'lino_atomizer_class', None)
    if sf_class is not None:
        return sf_class(fld, name)

    if isinstance(fld, fields.DummyField):
        return None
    if isinstance(fld, fields.RequestField):
        delegate = create_atomizer(holder, fld.return_type, fld.name)
        return RequestStoreField(fld, delegate, name)
    if isinstance(fld, fields.VirtualField):
        delegate = create_atomizer(holder, fld.return_type, fld.name)
        if delegate is None:
            # e.g. VirtualField with DummyField as return_type
            return None
            # raise Exception("No atomizer for %s %s %s" % (
            #     holder, fld.return_type, fld.name))
        return VirtStoreField(fld, delegate, name)
    if isinstance(fld, models.FileField):
        return FileFieldStoreField(fld, name)
    if isinstance(fld, models.ManyToManyField):
        return StoreField(fld, name)
    if isinstance(fld, fields.PasswordField):
        return PasswordStoreField(fld, name)
    if isinstance(fld, models.OneToOneField):
        return OneToOneStoreField(fld, name)
    if isinstance(fld, models.OneToOneRel):
        return OneToOneRelStoreField(fld, name)

    if settings.SITE.is_installed('contenttypes'):
        from lino.core.gfks import GenericForeignKey
        if isinstance(fld, GenericForeignKey):
            return GenericForeignKeyField(fld, name)
        from lino.modlib.gfks.fields import GenericForeignKeyIdField
        if isinstance(fld, GenericForeignKeyIdField):
            return ComboStoreField(fld, name)

    if isinstance(fld, models.ForeignKey):
        return ForeignKeyStoreField(fld, name)
    if isinstance(fld, models.TimeField):
        return TimeStoreField(fld, name)
    if isinstance(fld, models.DateTimeField):
        return DateTimeStoreField(fld, name)
    if isinstance(fld, fields.IncompleteDateField):
        return IncompleteDateStoreField(fld, name)
    if isinstance(fld, models.DateField):
        return DateStoreField(fld, name)
    if isinstance(fld, models.BooleanField):
        return BooleanStoreField(fld, name)
    if isinstance(fld, models.DecimalField):
        return DecimalStoreField(fld, name)
    if isinstance(fld, models.AutoField):
        return AutoStoreField(fld, name)
        # kw.update(type='int')
    if isinstance(fld, models.SmallIntegerField):
        return IntegerStoreField(fld, name)
    if isinstance(fld, fields.DisplayField):
        return DisplayStoreField(fld, name)
    if isinstance(fld, models.IntegerField):
        return IntegerStoreField(fld, name)
    if isinstance(fld, models.ManyToOneRel):
        # raise Exception("20190625 {} {} {}".format(holder, fld, name))
        return
    kw = {}
    if choosers.uses_simple_values(holder, fld):
        return StoreField(fld, name, **kw)
    else:
        return ComboStoreField(fld, name, **kw)
Ejemplo n.º 4
0
def create_atomizer(model, fld, name):
    if isinstance(fld, fields.RemoteField):
        """
        Hack: we create a StoreField based on the remote field,
        then modify its behaviour.
        """
        sf = create_atomizer(model, fld.field, fld.name)

        def value_from_object(sf, obj, ar):
            m = fld.func
            return m(obj, ar)

        def full_value_from_object(sf, obj, ar):
            m = fld.func
            v = m(obj, ar)
            return v

        sf.value_from_object = curry(value_from_object, sf)
        sf.full_value_from_object = curry(full_value_from_object, sf)
        return sf
    meth = getattr(fld, '_return_type_for_method', None)
    if meth is not None:
        # uh, this is tricky...
        return MethodStoreField(fld, name)

    sf_class = getattr(fld, 'lino_atomizer_class', None)
    if sf_class is not None:
        return sf_class(fld, name)

    if isinstance(fld, fields.DummyField):
        return None
    if isinstance(fld, fields.RequestField):
        delegate = create_atomizer(model, fld.return_type, fld.name)
        return RequestStoreField(fld, delegate, name)
    if isinstance(fld, fields.VirtualField):
        delegate = create_atomizer(model, fld.return_type, fld.name)
        return VirtStoreField(fld, delegate, name)
    if isinstance(fld, models.FileField):
        return FileFieldStoreField(fld, name)
    if isinstance(fld, models.ManyToManyField):
        return StoreField(fld, name)
    if isinstance(fld, fields.PasswordField):
        return PasswordStoreField(fld, name)
    if isinstance(fld, models.OneToOneField):
        return OneToOneStoreField(fld, name)
    if isinstance(fld, GenericForeignKey):
        return GenericForeignKeyField(fld, name)
    if isinstance(fld, fields.GenericForeignKeyIdField):
        return ComboStoreField(fld, name)
    if isinstance(fld, models.ForeignKey):
        return ForeignKeyStoreField(fld, name)
    if isinstance(fld, models.TimeField):
        return TimeStoreField(fld, name)
    if isinstance(fld, models.DateTimeField):
        return DateTimeStoreField(fld, name)
    if isinstance(fld, fields.IncompleteDateField):
        return IncompleteDateStoreField(fld, name)
    if isinstance(fld, models.DateField):
        return DateStoreField(fld, name)
    if isinstance(fld, models.BooleanField):
        return BooleanStoreField(fld, name)
    if isinstance(fld, models.DecimalField):
        return DecimalStoreField(fld, name)
    if isinstance(fld, models.AutoField):
        return AutoStoreField(fld, name)
        #~ kw.update(type='int')
    if isinstance(fld, models.SmallIntegerField):
        return IntegerStoreField(fld, name)
    if isinstance(fld, fields.DisplayField):
        return DisplayStoreField(fld, name)
    if isinstance(fld, models.IntegerField):
        return IntegerStoreField(fld, name)
    kw = {}
    if choosers.uses_simple_values(model, fld):
        return StoreField(fld, name, **kw)
    else:
        return ComboStoreField(fld, name, **kw)
Ejemplo n.º 5
0
def create_atomizer(holder, fld, name):
    """
    The holder is where the (potential) choices come from. It can be
    a model, an actor or an action.
    """
    if name is None:
        return
        # raise Exception("20181023 create_atomizer() {}".format(fld))
    if isinstance(fld, fields.RemoteField):
        """
        Hack: we create a StoreField based on the remote field,
        then modify its behaviour.
        """
        sf = create_atomizer(holder, fld.field, fld.name)
        # print("20180712 create_atomizer {} from {}".format(sf, fld.field))

        def value_from_object(sf, obj, ar=None):
            m = fld.func
            return m(obj, ar)

        def full_value_from_object(sf, obj, ar=None):
            m = fld.func
            v = m(obj, ar)
            return v

        def set_value_in_object(sf, ar, instance, v):
            # print("20180712 {}.set_value_in_object({}, {})".format(
            #     sf, instance, v))
            old_value = sf.value_from_object(instance, ar.request)
            if old_value != v:
                return fld.setter(instance, v)

        sf.value_from_object = curry(value_from_object, sf)
        sf.full_value_from_object = curry(full_value_from_object, sf)
        sf.set_value_in_object = curry(set_value_in_object, sf)
        return sf
    
    meth = getattr(fld, '_return_type_for_method', None)
    if meth is not None:
        # uh, this is tricky...
        return MethodStoreField(fld, name)

    sf_class = getattr(fld, 'lino_atomizer_class', None)
    if sf_class is not None:
        return sf_class(fld, name)

    if isinstance(fld, fields.DummyField):
        return None
    if isinstance(fld, fields.RequestField):
        delegate = create_atomizer(holder, fld.return_type, fld.name)
        return RequestStoreField(fld, delegate, name)
    if isinstance(fld, fields.VirtualField):
        delegate = create_atomizer(holder, fld.return_type, fld.name)
        if delegate is None:
            # e.g. VirtualField with DummyField as return_type
            return None
            # raise Exception("No atomizer for %s %s %s" % (
            #     holder, fld.return_type, fld.name))
        return VirtStoreField(fld, delegate, name)
    if isinstance(fld, models.FileField):
        return FileFieldStoreField(fld, name)
    if isinstance(fld, models.ManyToManyField):
        return StoreField(fld, name)
    if isinstance(fld, fields.PasswordField):
        return PasswordStoreField(fld, name)
    if isinstance(fld, models.OneToOneField):
        return OneToOneStoreField(fld, name)
    if isinstance(fld, models.OneToOneRel):
        return OneToOneRelStoreField(fld, name)

    if settings.SITE.is_installed('contenttypes'):
        from lino.core.gfks import GenericForeignKey
        if isinstance(fld, GenericForeignKey):
            return GenericForeignKeyField(fld, name)
        from lino.modlib.gfks.fields import GenericForeignKeyIdField
        if isinstance(fld, GenericForeignKeyIdField):
            return ComboStoreField(fld, name)

    if isinstance(fld, models.ForeignKey):
        return ForeignKeyStoreField(fld, name)
    if isinstance(fld, models.TimeField):
        return TimeStoreField(fld, name)
    if isinstance(fld, models.DateTimeField):
        return DateTimeStoreField(fld, name)
    if isinstance(fld, fields.IncompleteDateField):
        return IncompleteDateStoreField(fld, name)
    if isinstance(fld, models.DateField):
        return DateStoreField(fld, name)
    if isinstance(fld, models.BooleanField):
        return BooleanStoreField(fld, name)
    if isinstance(fld, models.DecimalField):
        return DecimalStoreField(fld, name)
    if isinstance(fld, models.AutoField):
        return AutoStoreField(fld, name)
        # kw.update(type='int')
    if isinstance(fld, models.SmallIntegerField):
        return IntegerStoreField(fld, name)
    if isinstance(fld, fields.DisplayField):
        return DisplayStoreField(fld, name)
    if isinstance(fld, models.IntegerField):
        return IntegerStoreField(fld, name)
    kw = {}
    if choosers.uses_simple_values(holder, fld):
        return StoreField(fld, name, **kw)
    else:
        return ComboStoreField(fld, name, **kw)
Ejemplo n.º 6
0
def create_atomizer(model, fld, name):
    if isinstance(fld, fields.RemoteField):
        """
        Hack: we create a StoreField based on the remote field,
        then modify its behaviour.
        """
        sf = create_atomizer(model, fld.field, fld.name)

        def value_from_object(sf, obj, ar):
            m = fld.func
            return m(obj, ar)

        def full_value_from_object(sf, obj, ar):
            m = fld.func
            v = m(obj, ar)
            return v

        sf.value_from_object = curry(value_from_object, sf)
        sf.full_value_from_object = curry(full_value_from_object, sf)
        return sf
    meth = getattr(fld, '_return_type_for_method', None)
    if meth is not None:
        # uh, this is tricky...
        return MethodStoreField(fld, name)

    sf_class = getattr(fld, 'lino_atomizer_class', None)
    if sf_class is not None:
        return sf_class(fld, name)

    if isinstance(fld, fields.DummyField):
        return None
    if isinstance(fld, fields.RequestField):
        delegate = create_atomizer(model, fld.return_type, fld.name)
        return RequestStoreField(fld, delegate, name)
    if isinstance(fld, fields.VirtualField):
        delegate = create_atomizer(model, fld.return_type, fld.name)
        return VirtStoreField(fld, delegate, name)
    if isinstance(fld, models.FileField):
        return FileFieldStoreField(fld, name)
    if isinstance(fld, models.ManyToManyField):
        return StoreField(fld, name)
    if isinstance(fld, fields.PasswordField):
        return PasswordStoreField(fld, name)
    if isinstance(fld, models.OneToOneField):
        return OneToOneStoreField(fld, name)
    if isinstance(fld, GenericForeignKey):
        return GenericForeignKeyField(fld, name)
    if isinstance(fld, fields.GenericForeignKeyIdField):
        return ComboStoreField(fld, name)
    if isinstance(fld, models.ForeignKey):
        return ForeignKeyStoreField(fld, name)
    if isinstance(fld, models.TimeField):
        return TimeStoreField(fld, name)
    if isinstance(fld, models.DateTimeField):
        return DateTimeStoreField(fld, name)
    if isinstance(fld, fields.IncompleteDateField):
        return IncompleteDateStoreField(fld, name)
    if isinstance(fld, models.DateField):
        return DateStoreField(fld, name)
    if isinstance(fld, models.BooleanField):
        return BooleanStoreField(fld, name)
    if isinstance(fld, models.DecimalField):
        return DecimalStoreField(fld, name)
    if isinstance(fld, models.AutoField):
        return AutoStoreField(fld, name)
        #~ kw.update(type='int')
    if isinstance(fld, models.SmallIntegerField):
        return IntegerStoreField(fld, name)
    if isinstance(fld, fields.DisplayField):
        return DisplayStoreField(fld, name)
    if isinstance(fld, models.IntegerField):
        return IntegerStoreField(fld, name)
    kw = {}
    if choosers.uses_simple_values(model, fld):
        return StoreField(fld, name, **kw)
    else:
        return ComboStoreField(fld, name, **kw)