of emails for various functions • Eldarion’s client needed to control the content of the email templates via a third party solution • We needed the ability to integrate with this third party’s API rather than send the email directly • Creating hooksets in django-user-accounts preserved default behavior while providing a way for us to override the email sending in the site
emails the standard way def send_invitation_email(to, ctx): ! class HookProxy(object): def __getattr__(self, attr): return getattr(settings.ACCOUNT_HOOKSET, attr) ! hookset = HookProxy()
! class SignupCode(models.Model): def send(self, **kwargs): # building up the context hookset.send_invitation_email([self.email], ctx) # finish things up
very specific requirements around password complexity and profile creation at signup. • Out of the box, django-user-accounts has password validation that works great on most sites but didn’t fit this client’s requirements. • We were able to easily leverage all that django-user- accounts gives us by customizing the SignupView and ChangePasswordForm objects with very little code.
SignupView as AccountSignupView from .forms import SignupForm ! class SignupView(AccountSignupView): form_class = SignupForm def generate_username(self, form): # custom username def create_user(self, form, commit=True, **kwargs): # create the user with first_name / last_name from form def after_signup(self, form): # Create profile and process any coupon codes
( SignupForm as AccountSignupForm ChangePasswordForm as AccountChangePasswordForm, PasswordResetTokenForm as AcccountPasswordResetTokenForm ) ! class SecurePasswordMixin(object): def assert_strong_password(self, data): # raise forms.ValidationError if rules are broken ! class ChangePasswordForm(SecurePasswordMixin, AccountChangePasswordForm): ! class PasswordResetTokenForm(SecurePasswordMixin, AcccountPasswordResetTokenForm): ! class SignupForm(SecurePasswordMixin, AccountSignupForm): # Add extra fields for profile
still in early development, KPITree, needed a way to easily extend the number of integrations it could have with 3rd party sources of metrics. • We created an app that will be open sourced and accept pull requests for new integration plugins. • This will enable functionality to be added to KPITree with the site only knowing about the Plugin interface and the Plugin author not having to know about any of the KPITree internals.
choices=registry.choices()) inputs = JSONField(default=lambda: {}) ! def clean(self): # validate self.inputs against plugin.inputs ! def process(self): # process data that is fetched from the plugin data = self.plugin().fetch(start, end) ! def plugin(self): return registry.get(self.provider)(**self.inputs)
settings.INSTALLED_APPS: # import each submodule in each app ! def load_submodules(module): # given a module, import all it's submodules ! def run(): autoload(["receivers"]) load_submodules("kpitree.integrations") admin.autodiscover()