Skip to content

Created new Mixin: PassUserIdentifierMixin

MariaV requested to merge user_mixin into master

As class based views were passing results in a context dictionary, and function based views were passing them in a results dictionary, sidebar template extender for "logged in" user_links required lots of code duplication (e.g., to generate a link back to a user's landing page, the template required an if/else block, where if a dictionary called "results" existed, the url was called using results.user_identifier as an arg, and if there was no results dictionary, the url was called with a function that returned kwargs['user_identifier'].

To solve this, I wrote a Mixin, "PassUserIdentifierMixin", that updates any CBV's context data with an extra dictionary, "results", which contains 'user_identifier', kwargs.user_identifier.

As such, all template language in the the user_links template extender referring to CBV view.user_identifier was able to be deleted, which lowers code duplication and makes development easier going forward, as CBV user_identifiers and FBV user_identifiers are now both passed to the template in a dictionary called "results".

All tests passed, and manual testing of the function reveals it appears to work as intended.

Merge request reports

Loading