mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-02-17 04:30:13 +00:00
Migrate to class-based views #3
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
For code-efficiency, class-based views are preferred by modern Django devs. See https://docs.djangoproject.com/en/4.2/topics/class-based-views/
This is a classic.
Read "Kill it with fire" - particularly the bit about "Beware of artificial consistency as proposed to "improve" technical value."
And consider much more closely the background of most of the people who have to maintain troggle.
@PhilipSargent That's a reasonable concern - change for change's sake is not sufficiently justified. However, arbitrarily quoting blogs and books as a justification for inaction is somewhat fatuous; it is an appeal to authority rather than any kind of salient argument.
That said, worrying about future maintainers is, I concede, worth doing.
The justification for CBVs is as follows:
For common views (such as add/edit/delete operations on instances of Django models), class based views allow for code-reuse: instead of implementing a new view function for every model, you implement one generic class-based view that works for any model (using class-based forms) and then you can call it against any model/template. Obviously when you need something more specific then you can implement a more specific view, but for simple operations on simple models, a generic reusable default makes a lot of sense.
The ethos is very much along the lines of trying to produce a minimal set of "sensible defaults" for views, forms, and templates (especially using template inheritance structures) so that 90% of the work to integrate any given model into the front-end is pre-done, and you need only worry about edge-cases and context-specific issues. In short, CBVs are DRY where FBVs are WET.
As for future maintainers, class based views are not very dissimilar to functional based views in their implementation, and can be learnt very easily. Provided they are sufficiently commented and documented, this should not pose a problem - anyone who knows enough python to get their hands dirty with this project is capable of working out how a class method can replace a function. Additionally, as mentioned above, CBVs are efficient in terms of code-reuse so would serve to reduce the code-base rather than expand it, which surely makes it easier to maintain.
We have very little of such commonality between our different type of objects, so this won't save any effort.
But it would make maintenance ever so much harder for most of the people we have .
Template inheritance is also used VERY SPARINGLY in troggle for exactly this reason.
@PhilipSargent this does beg the question: why use a fully-featured MCV framework if you are going to intentionally subvert its features? If the explicit goal is to reinvent every wheel then why not start from the raw python webserver package and build it from the bottom up?
This seems like a very poor argument to me: to say "we use Django for this project, but we have deliberately avoided using most of the core features of Django so you can't actually refer to the Django docs but must instead rely on tribal knowledge and out-of-date pages on the handbook" seems insane. Maybe I am just missing the point.
Another view of class based views https://406.ch/writing/composition-over-inheritance-the-case-for-function-based-views/
We use quite a lot of clever and automatic Django stuff, just not that bit.
See https://expo.survex.com/handbook/troggle/trogarch.html