# Path: findingaids/fa/utils.py
# def get_findingaid(eadid=None, preview=False, only=None, also=None, order_by=None,
#         filter=None):
#     """Retrieve a  :class:`~findingaids.fa.models.FindingAid` (or
#     :class:`~findingaids.fa.models.FindingAid`  :class:`eulexistdb.manager.Manager`)
#     from eXist by eadid, with any query options specified.  Raises a
#     :class:`django.http.Http404` if the requested document is not found in eXist.
# 
#     Handles switching to preview collection and then switching back when
#     preview is set to True.
# 
#     :param eadid: eadid of the :class:`~findingaids.fa.models.FindingAid` to
#             retrieve; if not specified, a :class:`eulexistdb.manager.Manager`
#             will be returned instead
#     :param preview: optional; set to True to load the finding aid from the
#             preview collection; defaults to False
#     :param only: optional list of fields to return (**only** return the specified fields)
#     :param also: optional list of additional fields to return
#     :param order_by: optional field to use for sorting
#     :param filter: optional queryset filter to apply, in dictionary form
#     :returns: :class:`~findingaids.fa.models.FindingAid` (when eadid is specified)
#             or a :class:`~findingaids.fa.models.FindingAid` :class:`eulexistdb.manager.Manager`
#             (if no eadid is specified)
#     """
#     try:
#         fa = FindingAid.objects.all()   # make sure we always have a queryset to start with
#         if only is not None:
#             fa = fa.only(*only)
#         if also is not None:
#             fa = fa.also(*also)
#         if order_by is not None:
#             fa = fa.order_by(order_by)
#         if filter is not None:
#             fa = fa.filter(**filter)
#         if preview:
#             fa = fa.using(settings.EXISTDB_PREVIEW_COLLECTION)
#         if eadid is not None:
#             fa = fa.get(eadid=eadid)
#     except DoesNotExist:
#         raise http.Http404
#     return fa


from django import forms
from django.conf import settings
from django.core.mail import send_mail
from eullocal.django.forms import captchafield
from findingaids.fa.utils import get_findingaid

            return '"%(name)s" <%(email)s>' % data
        # otherwise, use just email
        else:
            return data['email']
    # if no email was specified, use configured server email
    else:
        return settings.SERVER_EMAIL


class RequestMaterialsForm(forms.Form):
    'Email form where a researcher can request materials for their visit.'
    repo = forms.MultipleChoiceField(settings.REQUEST_MATERIALS_CONTACTS,
            label='Repository', required=True, widget=forms.CheckboxSelectMultiple)
    name = forms.CharField(required=True)
    date = forms.CharField(label='Date of Visit', required=True)
    email = forms.EmailField(label='Email address', required=True)
    phone = forms.CharField(label='Phone Number', required=False)
    request = forms.CharField(label='Materials Requested', widget=forms.Textarea)

    captcha = captchafield.ReCaptchaField()

    email_subject = 'Request for Materials'

    def send_email(self):
        # send an email (should not be used unless form is valid)
        # construct a simple text message with the data from the form
        message = '''
Name:                %(name)s
Date of Visit:       %(date)s
Email:               %(email)s

# Path: findingaids/fa/utils.py
# def get_findingaid(eadid=None, preview=False, only=None, also=None, order_by=None,
#         filter=None):
#     """Retrieve a  :class:`~findingaids.fa.models.FindingAid` (or
#     :class:`~findingaids.fa.models.FindingAid`  :class:`eulexistdb.manager.Manager`)
#     from eXist by eadid, with any query options specified.  Raises a
#     :class:`django.http.Http404` if the requested document is not found in eXist.
# 
#     Handles switching to preview collection and then switching back when
#     preview is set to True.
# 
#     :param eadid: eadid of the :class:`~findingaids.fa.models.FindingAid` to
#             retrieve; if not specified, a :class:`eulexistdb.manager.Manager`
#             will be returned instead
#     :param preview: optional; set to True to load the finding aid from the
#             preview collection; defaults to False
#     :param only: optional list of fields to return (**only** return the specified fields)
#     :param also: optional list of additional fields to return
#     :param order_by: optional field to use for sorting
#     :param filter: optional queryset filter to apply, in dictionary form
#     :returns: :class:`~findingaids.fa.models.FindingAid` (when eadid is specified)
#             or a :class:`~findingaids.fa.models.FindingAid` :class:`eulexistdb.manager.Manager`
#             (if no eadid is specified)
#     """
#     try:
#         fa = FindingAid.objects.all()   # make sure we always have a queryset to start with
#         if only is not None:
#             fa = fa.only(*only)
#         if also is not None:
#             fa = fa.also(*also)
#         if order_by is not None:
#             fa = fa.order_by(order_by)
#         if filter is not None:
#             fa = fa.filter(**filter)
#         if preview:
#             fa = fa.using(settings.EXISTDB_PREVIEW_COLLECTION)
#         if eadid is not None:
#             fa = fa.get(eadid=eadid)
#     except DoesNotExist:
#         raise http.Http404
#     return fa


# Path: findingaids/content/forms.py
from django import forms
from django.conf import settings
from django.core.mail import send_mail
from eullocal.django.forms import captchafield
from findingaids.fa.utils import get_findingaid

            return '"%(name)s" <%(email)s>' % data
        # otherwise, use just email
        else:
            return data['email']
    # if no email was specified, use configured server email
    else:
        return settings.SERVER_EMAIL


class RequestMaterialsForm(forms.Form):
    'Email form where a researcher can request materials for their visit.'
    repo = forms.MultipleChoiceField(settings.REQUEST_MATERIALS_CONTACTS,
            label='Repository', required=True, widget=forms.CheckboxSelectMultiple)
    name = forms.CharField(required=True)
    date = forms.CharField(label='Date of Visit', required=True)
    email = forms.EmailField(label='Email address', required=True)
    phone = forms.CharField(label='Phone Number', required=False)
    request = forms.CharField(label='Materials Requested', widget=forms.Textarea)

    captcha = captchafield.ReCaptchaField()

    email_subject = 'Request for Materials'

    def send_email(self):
        # send an email (should not be used unless form is valid)
        # construct a simple text message with the data from the form
        message = '''
Name:                %(name)s
Date of Visit:       %(date)s
Email:               %(email)s

Phone Number:        %(phone)s
