<commit_before>from email.utils import parseaddr
import logging
import re

from django import forms
from django.core.exceptions import ValidationError
from django.core.urlresolvers import reverse_lazy
from django.core.validators import validate_email
from django.db.models.fields.files import FieldFile
from django.db.models import Q
from django.forms.models import modelformset_factory
from django.template.defaultfilters import linebreaksbr
from django.utils.translation import ugettext_lazy as _

from lily.contacts.models import Contact

from lily.tenant.middleware import get_current_user
from lily.utils.forms import HelloLilyForm, HelloLilyModelForm
from lily.utils.forms.fields import TagsField, FormSetField
from lily.utils.forms.mixins import FormSetFormMixin
from lily.utils.forms.widgets import Wysihtml5Input, AjaxSelect2Widget

from ..models.models import (EmailAccount, EmailTemplate, EmailAttachment, EmailOutboxAttachment, DefaultEmailTemplate,
                             EmailTemplateAttachment)
from .widgets import EmailAttachmentWidget
from ..utils import get_email_parameter_choices, TemplateParser


logger = logging.getLogger(__name__)


class EmailAccountCreateUpdateForm(HelloLilyModelForm):

    class Meta:
        model = EmailAccount
        fieldsets = (
            (_('Your account'), {
                'fields': [
                    'from_name',
                    'label',
                    'email_address',
                    'public',
                ],
            }),
        )


class AttachmentBaseForm(HelloLilyModelForm):
    """
    Form for uploading email attachments.
    """
    class Meta:
        models = EmailOutboxAttachment
        fields = ('attachment',)
        widgets = {
            'attachment': EmailAttachmentWidget(),
        }


class ComposeEmailForm(FormSetFormMixin, HelloLilyForm):
    """
    Form for writing an EmailMessage as a draft, reply or forwarded message.
    """
    draft_pk = forms.IntegerField(widget=forms.HiddenInput(), required=False)<commit_msg>LILY-900: make email_address of an email account readonly in the form<commit_after>from email.utils import parseaddr
import logging
import re

from django import forms
from django.core.exceptions import ValidationError
from django.core.urlresolvers import reverse_lazy
from django.core.validators import validate_email
from django.db.models.fields.files import FieldFile
from django.db.models import Q
from django.forms.models import modelformset_factory
from django.template.defaultfilters import linebreaksbr
from django.utils.translation import ugettext_lazy as _

from lily.contacts.models import Contact

from lily.tenant.middleware import get_current_user
from lily.utils.forms import HelloLilyForm, HelloLilyModelForm
from lily.utils.forms.fields import TagsField, FormSetField
from lily.utils.forms.mixins import FormSetFormMixin
from lily.utils.forms.widgets import Wysihtml5Input, AjaxSelect2Widget

from ..models.models import (EmailAccount, EmailTemplate, EmailAttachment, EmailOutboxAttachment, DefaultEmailTemplate,
                             EmailTemplateAttachment)
from .widgets import EmailAttachmentWidget
from ..utils import get_email_parameter_choices, TemplateParser


logger = logging.getLogger(__name__)


class EmailAccountCreateUpdateForm(HelloLilyModelForm):

    class Meta:
        model = EmailAccount
        fieldsets = (
            (_('Your account'), {
                'fields': [
                    'from_name',
                    'label',
                    'email_address',
                    'public',
                ],
            }),
        )
        widgets = {
            'email_address': forms.TextInput(attrs={'readonly': 'readonly'}),
        }


class AttachmentBaseForm(HelloLilyModelForm):
    """
    Form for uploading email attachments.
    """
    class Meta:
        models = EmailOutboxAttachment
        fields = ('attachment',)
        widgets = {
            'attachment': EmailAttachmentWidget(),
        }


class ComposeEmailForm(FormSetFormMixin, HelloLilyForm):
    """
    Form for writing an EmailMessage as a draft, reply or forwarded message.
    """
    draft_pk = forms.IntegerField(widget=forms.HiddenInput(), required=False)
{'fraction_non_alphanumeric': 0.07210179076343072, 'fraction_numerical': 0.001649387370405278, 'mean_word_length': 3.161764705882353, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1669165', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1082, 'n_words': 293}