def get_context_data(self, **kwargs): context = {} context['inherited'] = { item.template_key: { 'template_key': item.template_key, 'enabled': item.enabled, 'days': item.days } for item in chain.from_iterable( product.productautosend_set.all() for product in self.object.real.products ) } context['template_keys'] = list(set( template.key for template in chain.from_iterable( EmailTemplate.get_templates(product.organizationalunit) for product in self.object.real.products ) )) if hasattr(self.object, 'product') and self.object.product is not None: context['organizationalunit'] = \ self.object.product.organizationalunit context['autosend_enable_days'] = EmailTemplateType.get_keys( enable_days=True ) context.update(kwargs) return super(ChangeVisitAutosendView, self).\ get_context_data(**context)