class RemindResponsibleForm(forms.Form): to = UserModelChoiceField(None, required=False, disabled=True, label=_("To")) cc = UserModelMultipleChoiceField(None, required=False, disabled=True, label=_("CC")) subject = forms.CharField(label=_("Subject")) body = forms.CharField(widget=forms.Textarea(), label=_("Message")) def __init__(self, *args, responsible, **kwargs): super().__init__(*args, **kwargs) self.fields['to'].initial = responsible.pk self.fields['to'].queryset = UserProfile.objects.filter(pk=responsible.pk) self.fields['cc'].initial = responsible.cc_users.all() | responsible.delegates.all() self.fields['cc'].queryset = responsible.cc_users.all() | responsible.delegates.all() self.template = EmailTemplate.objects.get(name=EmailTemplate.EDITOR_REVIEW_REMINDER) self.fields['subject'].initial = self.template.subject self.fields['body'].initial = self.template.body def send(self, request, courses): recipient = self.cleaned_data.get('to') self.template.subject = self.cleaned_data.get('subject') self.template.body = self.cleaned_data.get('body') subject_params = {} body_params = {'user': recipient, 'courses': courses} EmailTemplate.send_to_user(recipient, self.template, subject_params, body_params, use_cc=True, request=request)
class RemindResponsibleForm(forms.Form): to = UserModelChoiceField(None, required=False, disabled=True, label=_("To")) cc = UserModelMultipleChoiceField(None, required=False, disabled=True, label=_("CC")) subject = forms.CharField(label=_("Subject")) plain_content = forms.CharField(widget=forms.Textarea(), label=_("Plain Message")) html_content = forms.CharField(widget=forms.Textarea(), label=_("HTML Message")) def __init__(self, *args, responsible, **kwargs): super().__init__(*args, **kwargs) self.fields["to"].initial = responsible.pk self.fields["to"].queryset = UserProfile.objects.filter(pk=responsible.pk) self.fields["cc"].initial = responsible.cc_users.all() | responsible.delegates.all() self.fields["cc"].queryset = responsible.cc_users.all() | responsible.delegates.all() self.template = EmailTemplate.objects.get(name=EmailTemplate.EDITOR_REVIEW_REMINDER) self.fields["subject"].initial = self.template.subject self.fields["plain_content"].initial = self.template.plain_content self.fields["html_content"].initial = self.template.html_content def send(self, request, evaluations): recipient = self.cleaned_data.get("to") self.template.subject = self.cleaned_data.get("subject") self.template.plain_content = self.cleaned_data.get("plain_content") self.template.html_content = self.cleaned_data.get("html_content") subject_params = {} body_params = {"user": recipient, "evaluations": evaluations} self.template.send_to_user(recipient, subject_params, body_params, use_cc=True, request=request)
class DelegatesForm(forms.ModelForm): delegate_of = UserModelMultipleChoiceField(None, required=False, disabled=True) cc_user_of = UserModelMultipleChoiceField(None, required=False, disabled=True) class Meta: model = UserProfile fields = ( 'delegates', 'cc_users', ) field_classes = { 'delegates': UserModelMultipleChoiceField, 'cc_users': UserModelMultipleChoiceField, } def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['cc_users'].disabled = True self.fields[ 'delegates'].queryset = UserProfile.objects.exclude_inactive_users( ) represented_users = self.instance.represented_users.all() self.fields['delegate_of'].queryset = represented_users self.fields['delegate_of'].initial = represented_users # work around https://code.djangoproject.com/ticket/25980 self.fields['delegate_of'].initial = list( represented_users.values_list('pk', flat=True)) ccing_users = self.instance.ccing_users.all() self.fields['cc_user_of'].queryset = ccing_users self.fields['cc_user_of'].initial = ccing_users # work around https://code.djangoproject.com/ticket/25980 self.fields['cc_user_of'].initial = list( ccing_users.values_list('pk', flat=True)) def save(self, *args, **kw): super().save(*args, **kw) logger.info('User "{}" edited the settings.'.format( self.instance.username))
class DelegatesForm(forms.ModelForm): delegates = UserModelMultipleChoiceField(queryset=UserProfile.objects.exclude(is_active=False).exclude(is_proxy_user=True), required=False) class Meta: model = UserProfile fields = ('delegates',) field_classes = { 'delegates': UserModelMultipleChoiceField, } def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def save(self, *args, **kw): super().save(*args, **kw) logger.info('User "{}" edited the settings.'.format(self.instance.username))