Considering my current understanding of the adapters pattern - waiting to stand corrected - we're going to define adapter mapping trees.
Will it exclusively go in one way, ie:
from django.db.models import Person
# add returns a clone of the payload, so we're instanciating 2 payloads here
# because the FormView adapter's post_add() will add(Form adapter, clone=False)
# if it's not already there ?
p = Payload.factory(instance=Person()).add('django.views.ModelFormView')
# executing a step returns a clone of the payload, but we don't care:
# we have an adapter mapping on data, a request, and we want a response
assert p.steps.response(request=request).response
The tutorial demonstrates how the above would be possible, but it might look like this (not tested code, obviously clumsy):
import Person model
make a payload with an empty instance,
because it's a model, factory will add the django model adapter, which has post_add():
introspect the payload,
map payload.instance._meta.fields to keys of the Payload corresponding to field names
add validate and clean steps on the person payload
add a render step
add the template adapter on the person,
which adds a render step with a default template name
that will be able to see other adapter's render outputs
add a response step which to orchestrate other steps,
but needs payload.request, and sets payload.response
in a clone as usual when a step is executed
unless clone=False, for calling steps from within steps
execute the response step by adding request to the payload
modelformview adapter response will try to execute all prior steps,
if no errors are added by clean() step then process() step will save
if no errors response() will if errors on validate step show the form again, otherwise redirect to the detail view, if errors were added during process who knows and honnestly i leave it up to you what the default behaviour will be since it should be so easy to override not only the method but the default adapter registered for ModelFormView !!
Or, will it allow to build a nested adapter map, and then be able to generate a model class with another adapter ?
class Hobby(adapters.Payload):
name = Payload(adapters=[StringAdapter()])
class Person(adapters.Payload):
hobbies = Payload(map=[HobbyAdapter()])
class Meta:
adapters = [OnlyAllowHobbiesToBe('archery', 'django', 'music')]
p = Person().add('django.db.models.Model')
# custom step by django model adapter, optinal, sets payload.model if not already present
p.steps.modelize().model
Another possibility is to make everything an adapter, which can have adapters who know about their parent, in which case steps also are adapters, just they orchestrate the adapters which are in a mapping structure, and defining a step is just defining a method which may depend on methods priorly executed.
Sorry if this doesn't make any sense please correct me ;)
If that makes sense to you then you probably understand why i consider this million $ worth, in terms of refactoring, and code reusability.
Considering my current understanding of the adapters pattern - waiting to stand corrected - we're going to define adapter mapping trees.
Will it exclusively go in one way, ie:
The tutorial demonstrates how the above would be possible, but it might look like this (not tested code, obviously clumsy):
payload.map.name.adapters == [StringAdapter(max_length=255)]
payload.map.name.adapters == [StringAdapter(max_length=255), TextFieldAdapter(label="my verbose name")]
Or, will it allow to build a nested adapter map, and then be able to generate a model class with another adapter ?
Another possibility is to make everything an adapter, which can have adapters who know about their parent, in which case steps also are adapters, just they orchestrate the adapters which are in a mapping structure, and defining a step is just defining a method which may depend on methods priorly executed.
Sorry if this doesn't make any sense please correct me ;)
If that makes sense to you then you probably understand why i consider this million $ worth, in terms of refactoring, and code reusability.