# Path: findingaids/fa/models.py
# class Archive(models.Model):
#     '''Model to define Archives associated with EAD documents, for use with
#     admin user permissions and to identify subversion repositories where
#     content will be published from.'''
#     label = models.CharField(max_length=10,
#         help_text='Short label to identify an archive')
#     name = models.CharField(max_length=255,
#         help_text='repository name (subarea) in EAD to identify finding aids associated with this archive')
#     svn = models.URLField('Subversion Repository',
#         help_text='URL to subversion repository containing EAD for this archive')
#     slug = models.SlugField(help_text='''shorthand id
#         (auto-generated from label; do not modify after initial archive definition)''')
#     contacts = models.ManyToManyField(settings.AUTH_USER_MODEL,
#         help_text='Contact person for display on the Request Materials page (email required)',
#         blank=True)
# 
# 
#     def __unicode__(self):
#         return self.label
# 
#     @property
#     def svn_local_path(self):
#         return os.path.join(settings.SVN_WORKING_DIR, self.slug)
# 
#     def contact_names(self):
#         '''List of contact names method for display in django admin list
#         display.  Shows email if user has no full name.'''
#         return ', '.join([contact.get_full_name() or contact.email
#                           for contact in self.contacts.all()])
#     contact_names.short_description = "Contacts"
# 
# 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 datetime import datetime
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.models import AbstractUser
from django.db import models
from findingaids.fa.models import Archive
from findingaids.fa.utils import get_findingaid
                self._published = False
        return self._published

    def set_published(self, value):
        if value is None:
            self._published = False  # store to prevent xquery lookup
        else:
            self._published = value

    published = property(get_published, set_published)

    def get_previewed(self):
        """Date object was loaded to eXist preview collection, if currently
            available in preview."""
        if self._previewed is None:
            try:
                fa = get_findingaid(filter={'document_name': self.filename},
                                       only=['last_modified'], preview=True)
                if fa.count():
                    self._previewed = fa[0].last_modified
            except Exception:
                pass

            # not found or error - store so we don't look up again
            if self._previewed is None:
                self._previewed = False
        return self._previewed

    def set_previewed(self, value):
        if value is None:

# Path: findingaids/fa/models.py
# class Archive(models.Model):
#     '''Model to define Archives associated with EAD documents, for use with
#     admin user permissions and to identify subversion repositories where
#     content will be published from.'''
#     label = models.CharField(max_length=10,
#         help_text='Short label to identify an archive')
#     name = models.CharField(max_length=255,
#         help_text='repository name (subarea) in EAD to identify finding aids associated with this archive')
#     svn = models.URLField('Subversion Repository',
#         help_text='URL to subversion repository containing EAD for this archive')
#     slug = models.SlugField(help_text='''shorthand id
#         (auto-generated from label; do not modify after initial archive definition)''')
#     contacts = models.ManyToManyField(settings.AUTH_USER_MODEL,
#         help_text='Contact person for display on the Request Materials page (email required)',
#         blank=True)
# 
# 
#     def __unicode__(self):
#         return self.label
# 
#     @property
#     def svn_local_path(self):
#         return os.path.join(settings.SVN_WORKING_DIR, self.slug)
# 
#     def contact_names(self):
#         '''List of contact names method for display in django admin list
#         display.  Shows email if user has no full name.'''
#         return ', '.join([contact.get_full_name() or contact.email
#                           for contact in self.contacts.all()])
#     contact_names.short_description = "Contacts"
# 
# 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/fa_admin/models.py
from datetime import datetime
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.models import AbstractUser
from django.db import models
from findingaids.fa.models import Archive
from findingaids.fa.utils import get_findingaid

                self._published = False
        return self._published

    def set_published(self, value):
        if value is None:
            self._published = False  # store to prevent xquery lookup
        else:
            self._published = value

    published = property(get_published, set_published)

    def get_previewed(self):
        """Date object was loaded to eXist preview collection, if currently
            available in preview."""
        if self._previewed is None:
            try:
                fa = get_findingaid(filter={'document_name': self.filename},
                                       only=['last_modified'], preview=True)
                if fa.count():
                    self._previewed = fa[0].last_modified
            except Exception:
                pass

            # not found or error - store so we don't look up again
            if self._previewed is None:
                self._previewed = False
        return self._previewed

    def set_previewed(self, value):
        if value is None:

            self._previewed = False  # store to prevent xquery lookup