- Published on
Release: Codegen fixes, createadminuser, form enhancements
- Authors
- Name
- Dave Coates
This release contains changes up until release/2022-11-15
.
To upgrade any existing projects it's recommended to pull in the relevant commits from upstream.
git remote add upstream git@gitlab.internal.alliancesoftware.com.au:alliance/template-django.git
git cherry-pick XXX1 XXX2
In cases where you are significantly behind it may be easier to pull the whole app (eg. common_audit
) in but you'll
need to review the relevant branch.
In this release
Codegen fixes
Various fixes to codegen
- This commit fixes bug in parsing values for async choices
- Fix types & return value for codegen'd model forms
- Handle removal of
NullBooleanField
in recent DRF versions
createadminuser
Adds a command createadminuser
that works like createsuperuser
but creates an AdminProfile
instead.
See this commit
Frontend Form improvements
Add handling for blankAsNull
parsing on form fields which will convert an empty string to null
. blankAsNull
is set
on fields based on the backend serializer allow_null
value.
This changes also mean the custom parsing and other form enhancements now work with Form.Item
- previously they only
worked if you used Form.Field
directly:
// This previously wouldn't use the customisations in the project for `Field`
<Form.Item field={myField} />
See this commit for the bulk of the changes and this commit for improved types on the form.
Other changes
- 7592c68d - CrudFilterListView preserves query list parameters now
- 6115abe3 - Fix issues with widget set on django form based server choices
- 1ea92c87 - Fixes useEndpoint
getPaginatorClass
check to be compatible with latest Presto - 07b6b742 - Return correct
pageSize
forPageNumberPagination
. Previously would return default rather than current value. - a2427853 - Audit updates to support latest version of pgtrigger
- a7da780e - Fix
getFormatterForField
typescript types
Roadmap
Along with the normal gradual enhancements and fixes the next major things planned are:
Replace webpack
The exact replacement is not yet known but will likely either be Parcel or Vite. Vitaly has done most the work required to replace webpack with Parcel and conceptually it is similar in function to Webpack but is simpler to configure and faster.
Vite offers some interesting possibilities with how we do things in django. Specifically, in dev, it doesn't bundle at all - it uses browser support for ES modules instead. In production it still bundles for practical reasons (namely using ES modules for everything requires too many HTTP requests for all but the simplest dependencies).
This could allow us to remove the necessity of a global entry point to all django based React rendering and instead
include things on demand as required. Right now if you want to render a component you have to expose it in django.tsx
which gets added to a global window.DJANGO_REACT
variable. We then dynamic imports to defer loading all the JS
up front.
Codegen improvements
There are two types of codegen we use: auto codegen (e.g. presto viewmodels) and manual codegen (e.g. scaffold CRUD screens).
For auto codegen it would be nice to support things like reversing django URLs from the frontend or automatically creating endpoint definitions based on what's defined in the backend.
Manual codegen will be largely rewritten to make it easier to extend and customise. The existing code has been extended many times and has many hacks to make things work. Resolving things like required imports is very explicit right now and is somewhat fragile. This will change to a more declarative approach where each "thing" to codegen can declare it's requirements and the codegen can intelligently resolve dependencies etc. based on that. It will also provide a better basis for extracting the codegen into a separate module and publishing it outside of the template project.