h icon indicating copy to clipboard operation
h copied to clipboard

Resources refactoring

Open seanh opened this issue 7 years ago • 1 comments

Notes https://slack-files.com/T03QZM0HN-FA511033L-69dc4d7561

  • [x] Move all factories into resources.py
  • [x] Split resources.py into traversal/roots.py and traversal.contexts.py
  • [x] Rename all "factories" to "roots"
  • [x] Rename all "resources" to "contexts"
  • [x] Docstrings
  • [ ] All roots should return contexts, not models
  • [ ] Roots should call model classes or services to do DB queries, not do them themselves
  • [ ] Some views can be simplified by using contexts
  • [ ] Grep the code for "resource". In some places (e.g. variable names, test class names) we're still calling things "resources" that are now called "contexts"
  • [ ] Context classes are being used in the tests for various other modules. They should be mocked.
  • [ ] Fix roots_test.py and contexts_test.py. Looks like there might be some bad stuff in there. E.g. I see a FakeGroup class.
  • [ ] Write an ADR

seanh avatar May 08 '18 17:05 seanh

I think the overall architecture we're going for is something like this:

img_1229

  • Services are built on top of models

  • Traversal roots and contexts use models (e.g. calling @classmethods on model classes to get model objects from the DB) and services. And they also use Pyramid (the request, permissions).

  • Views use traversal contexts (passed in to views as the context argument). Traversal roots also do work for views (finding the context object for the view) but are not directly called by views

  • Views may pass these context objects into other parts of the code that views call. E.g. into services, or presenters, or renderers, or templates (not pictured)

  • Views use services too

  • We also have model objects in views too! Either given to views as properties or return values of contexts or services, or views calling @classmethods on model classes.

As you can see, views are sort of the central spoke of everything. They're the integration code that integrates everything together. This is why we need to work hard to keep views small and simple: just do that integration, and move all the actual work into the various other kinds of components.

seanh avatar May 08 '18 18:05 seanh