Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Benjamin Kampmann
@gnunicorn
I had to adapt it a little bit, but that was stolen from somewhere
Ethan Miller
@ezmiller
so it’s not part of any library but you imported it somehow on its own?
Benjamin Kampmann
@gnunicorn
what is written into each of those hashes is determined by the appropriate Marshaller for that specific object-type
I think I got it from here – http://flask.pocoo.org/snippets/44/
or maybe not. who knows...
Ethan Miller
@ezmiller
oh okay, i was thinking of looking at that page to try to understand what might be goingon.
Benjamin Kampmann
@gnunicorn
that’s the one.
Ethan Miller
@ezmiller
okay, i will look at that, but back to the json=1 result.
Benjamin Kampmann
@gnunicorn
yes. so.
common/paging_schema.py is invoked
a schema is the marshmallow description to build the json
which wraps around the schemas/object schema.
Ethan Miller
@ezmiller
okay
Benjamin Kampmann
@gnunicorn
there is a lot of magic in there and I won’t go there – with meta classes and stuff. – the important part is, that in order to have a some data dumped for an object you have, you need to let the marshmallow-er know which schema to use
we have a morphing_schema for that.
Ethan Miller
@ezmiller
just looking at that
one sec
polymorphic_identity is this key defining what kind of object is in the row in the objects table or whatever it’s called right?
Benjamin Kampmann
@gnunicorn
to register the schema you want to have the let the ObjectField registry know about thaat.
exactly.
Ethan Miller
@ezmiller
it maps to “type” later?
Benjamin Kampmann
@gnunicorn
so. as an example, take a look at beavy_modules/private_message/schemas.py
Ethan Miller
@ezmiller
okay one sec
Benjamin Kampmann
@gnunicorn
there is a schema that explains the private message – and then at the end registers that with the morphing-schema. essentially saying: if you find a type=private_message use this schema.
you need to do the same for the object you have

re

it maps to “type” later?

Ethan Miller
@ezmiller
ahah
Benjamin Kampmann
@gnunicorn
Unfortunately that is kinda hard-coded inside marshmallow and not easy to get into that. so your Schema must have a class Meta, which must have a type property set properly at the moment. look at the private message as an example again.
Ethan Miller
@ezmiller
The ObjectRegistry is hard-coded?
Benjamin Kampmann
@gnunicorn
if you did both of those, and restart the server, the resulting json should contain the data you want it to dump
Ethan Miller
@ezmiller
sorry ObjectField.registry...
Benjamin Kampmann
@gnunicorn
ObjectField is just a field containing any morphing object type. the registry is just a dictionary on that class (so a singleton inside this running process) which allows it to look up which schema to actually use when it encouters a specific type.
see beavy/schemas/object ->
class ObjectField(MorphingSchema):
    FALLBACK = BaseObject
    registry = {}
Ethan Miller
@ezmiller
Just trying to parse all this. Hold on.
Benjamin Kampmann
@gnunicorn
(the travis errors are the known “enter passphrase”- problem. need to fix that one!)
sure.
gnunicorn @ligthyear will go to bed soon, but I can wait a bit ;)
Ethan Miller
@ezmiller
didn’t we have a fix for that?
Benjamin Kampmann
@gnunicorn
did we?
Ethan Miller
@ezmiller
oh
yeah
Benjamin Kampmann
@gnunicorn
I only remember fixing it for tech talks, but not yet on master.
Ethan Miller
@ezmiller
oh no
Benjamin Kampmann
@gnunicorn
need to move them to the new dokku anyways, though.
Ethan Miller
@ezmiller
i was thinking of something else
Benjamin Kampmann
@gnunicorn
let’s focus on the json api for now.
Ethan Miller
@ezmiller
Okay,
Benjamin Kampmann
@gnunicorn
that thing is trivial to fix and I will do it one day soon ;)
Ethan Miller
@ezmiller
a couple of questions