def perform_update(self, serializer): existing_customer = self.get_object() updated_customer = serializer.save() json_encoder = JSONEncoder() existing_customer_data = json_encoder.encode( self.serializer_class(existing_customer).data ) updated_customer_data = json_encoder.encode(serializer.data) if existing_customer_data != updated_customer_data: adapter = get_adapter(self.request) context = { "customer": updated_customer, } managers_emails = updated_customer.customer_users.managers( ).values_list("user__email", flat=True) adapter.send_mail( "astrosat_users/email/update_customer", managers_emails, context, fail_silently=True, ) return updated_customer
def perform_update(self, serializer): existing_customer_user = self.get_object() updated_customer_user = serializer.save() json_encoder = JSONEncoder() existing_customer_user_user_data = json_encoder.encode( self.serializer_class(existing_customer_user).data["user"] ) updated_customer_user_user_data = json_encoder.encode( serializer.data["user"] ) adapter = get_adapter(self.request) context = { "user": updated_customer_user.user, "customer": updated_customer_user.customer, } if existing_customer_user_user_data != updated_customer_user_user_data: template_prefix = "astrosat_users/email/update_user" adapter.send_mail( template_prefix, updated_customer_user.user.email, context, fail_silently=True, ) if existing_customer_user.customer_user_type != updated_customer_user.customer_user_type: if updated_customer_user.customer_user_type == CustomerUserType.MANAGER: # customer_user was something else, now it's a MANAGER template_prefix = "astrosat_users/email/admin_assign" elif existing_customer_user.customer_user_type == CustomerUserType.MANAGER: # customer_user was a MANAGER, now it's something else template_prefix = "astrosat_users/email/admin_revoke" adapter.send_mail( template_prefix, updated_customer_user.user.email, context, fail_silently=True, ) return updated_customer_user