Reduce dependency on Klass instance in KlassDetailView#279
Open
Reduce dependency on Klass instance in KlassDetailView#279
Conversation
This is a step on the road of removing the ORM from the template render.
We had a filter that did a complex query at template render time. That logic has now been moved to the view. Flat objects are introduced to passed method to the template instead. The helper function is horrible. We should also improve the method context data structure, but that would require more work on the template, so it's out of scope. Similarly, this makes no effort to add types to the helper function which was previously a template filter.
This adds a `klass` argument, and renames a couple of attributes. Other than that, this is just a move. This function is gnarly. Fixing it can come later.
There's no need for us to re-define this on every iteration.
ghickman
approved these changes
Oct 24, 2025
Contributor
ghickman
left a comment
There was a problem hiding this comment.
Couple of questions about essentially the same thing. I don't have a strong opinion on which way you go though, more curious to see if reducing the types are useful to you
| class Class: | ||
| db_id: int | ||
| docs_url: str | ||
| docstring: str | None |
Contributor
There was a problem hiding this comment.
Could an empty string serve the same falsey/emptiness need as None here, and reduce the number of types?
| name: str | ||
| value: str | ||
| overridden: bool | ||
| class_url: str | None |
Contributor
There was a problem hiding this comment.
Same question here, about using empty string instead of None
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a step on the road of removing the ORM.
This removes ORM objects from the template context, and some logic off the models in the process. The moved code is by no means perfect, but at least it's now in a less inconvenient place.