Skip to content

Conversation

@apapsch
Copy link

@apapsch apapsch commented Dec 18, 2025

Description

Custom email templates might require some dynamic data. Make use of the unused extra_context parameter of EmailDevice, allowing custom view classes to set extra_context.

Care is taken to only pass context if device generate_challenge actually supports an extra_context parameter. The base method does not define any parameters.

Motivation and Context

Please see #786 for motivation and context.

How Has This Been Tested?

  • This branch has been installed into my development environment and tested successfully with my custom view classes.
  • Unit tests of django-two-factor-auth were confirmed to finish without error.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly. (added doc comments)
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Custom email templates might require some dynamic data.
Make use of the unused extra_context parameter of
EmailDevice, allowing custom view classes to set
extra_context.

Care is taken to only pass context if device
generate_challenge actually supports an extra_context
parameter. The base method does not define any
parameters.
@apapsch apapsch force-pushed the context-data-for-email branch from 8101db8 to aec8d73 Compare December 18, 2025 10:47
@moggers87 moggers87 self-requested a review December 19, 2025 13:15
Copy link
Collaborator

@moggers87 moggers87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just one comment that needs resolving.

Comment on lines +45 to +47
generate_challenge = getattr(device, "generate_challenge", None)
if not callable(generate_challenge):
raise TypeError("Device has no generate_challenge method")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to test if device.generate_challenge callable? It's defined on the base Device model so I don't think this test is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants