[Schevo-devel] More field objects

Matthew Scott mscott at goldenspud.com
Fri Dec 16 10:57:04 EST 2005


On 12/16/05, Tom Locke <tom at livelogix.com> wrote:
> Hi,
>
> I'm still trying to get to grips with field objects...
>
> I think part of the chat yesterday went something like: (apologies if
> I'm miss quoting)
>
> Pat: fields objects can have info that customizes the UI for that field
>
> Me: Shouldn't that be stored on the field_spec and accessed via the extent?
>
> Pat: No because there can be custom info for specific entities.
>
> Assuming I remembered that right, I'm wondering how that works, given
> than someEntity.sys.fields() creates the field objects then and there.

The field -classes- are stored in the extent's field_spec.

So, let's say the Person extent has a 'name' field.  When I am done
merging query2 into trunk, extents will have their 'f' namespace
available as well as field_spec:

  >>> name_spec = db.Person.f.name

What name_spec is at this point is the subclass of schevo.field.Field
that was created especially for the 'name' field spec on the Person
extent.

What name_spec doesn't give you is the value of any fields, since it's
only a specification of how a field instance should look by default
for that field.

In the current scheme of things, Entity instances can be thought of as
specialized View instances.  A View instance has a dictionary of
fields, rather than field classes, available via its .f namespace, and
for the purposes of UI autogeneration, its .sys.fields method.

If an entity's fields are based on its extent's field_spec, how are
the entity's field instances created?

First, a set of values for fields is retrieved from the database.  We
can continue the example above to mimick this:

  >>> values = dict(name=u'Bob')

Then, you can use the field_map method of the FieldSpecMap to create a
FieldMap ordered dictionary:

  >>> fmap = db.Person.field_spec.field_map(values)

Now you have an ordered dictionary of field instances based on the
field classes:

  >>> name_field = fmap['name']
  >>> name_field.get()
  u'Bob'

If you just want the values of a field map, you can use the value_map method:

  >>> vmap = fmap.value_map()
  >>> vmap['name']
  u'Bob'

For a View that is not an Entity itself, the fields could be based on
an entity's fields, or could have totally new fields created based on
something else, or could have a mixture.  Now that the query2 stuff is
merging into trunk, views will become more important once I get a good
nufox GUI going for queries and viewing query results.

--
Matthew R. Scott



More information about the Schevo-devel mailing list