Defines simple contact form that can be used to
    contact a site member passed by username in the URL
    or to all superusers or to a list defined in settings.DEFAULT_CONTACTS.

def simple_contact(request, username=""):
    """
    Defines simple contact form that can be used to
    contact a site member passed by username in the URL
    or to all superusers or to a list defined in settings.DEFAULT_CONTACTS.
    """
    site = Site.objects.get_current()
    form = ContactForm(request.POST or None)
    UserModel = get_user_model()
    recipients = []
    site_form = False

    logger.debug('Recipients should be empty: %s' % recipients)

    # if we know, fill in the user name and email
    if request.user.is_authenticated:
        # first, resolve username for tango and non-tango sites
        try:
            name = request.user.display_name
        except AttributeError:
            name = request.user.username
        form.fields['sender_name'].widget.attrs['readonly'] = 'true'
        form.fields['sender_name'].initial = name
        form.fields['sender_email'].widget.attrs['readonly'] = 'true'
        form.fields['sender_email'].initial = request.user.email

    if username:
        member = get_object_or_404(UserModel, username=username)
        recipients = [member.email, ]
        logger.debug('Recipients should be a single user: %s' % recipients)

    else:
        # site contact form.
        # Use first of settings.DEFAULT_CONTACTS or all superusers
        site_form = True
        member = None
        recipients = getattr(settings, "DEFAULT_CONTACTS", None)
        logger.debug('Recipients should be match DEFAULT_CONTACTS: %s' % recipients)

        if not recipients:
            recipients = UserModel.objects.filter(is_superuser=True).values_list('email', flat=True)
            warnings.warn(
                "settings.DEFAULT_CONTACTS does not exist. You may want to create it.",
                RuntimeWarning
            )
            logger.debug('Recipients should be superusers: %s' % recipients)

    if form.is_valid():
        if site_form:
            subject = "A {} contact form submission from {}".format(
                site.name, form.cleaned_data['sender_name']
            )
        else:
            subject = "A message from {} on {}".format(form.cleaned_data['sender_name'], site.name)
        body = form.cleaned_data['body']

        sender_email = form.cleaned_data['sender_email']

        if 'send_a_copy' in request.POST:
            recipients.append(sender_email)
            logger.debug('Recipients should be match prior + sender email: %s' % recipients)

        mail = EmailMessage(
            subject=subject,
            body=body,
            from_email=sender_email,
            to=recipients
        )
        mail.send()
        return HttpResponseRedirect(success_url)
    return render(request, 'contact/simple_form.html', {
        'form': form,
        'site': site,
        'member': member
    })