# 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
        permissions = (
                ("can_publish", "Can publish a finding aid"),
                ("can_preview", "Can preview a finding aid"),
                ("can_delete", "Can delete a finding aid"),
                ("can_prepare", "Can prepare a finding aid"),
                ("can_view_internal_dao", "Can view internal digital archival objects"),
        )

class Archivist(models.Model):
    user = models.OneToOneField(settings.AUTH_USER_MODEL,
        on_delete=models.CASCADE)  # if user is deleted, delete archivist too
    archives = models.ManyToManyField(Archive, blank=True)
    order = models.CommaSeparatedIntegerField(max_length=255, blank=True,
        null=True)

    def __repr__(self):
        return '<Archivist %s: %s>' % (self.user.username,
            ', '.join(arch.label for arch in self.archives.all()))

    def __unicode__(self):
        return u'Archivist %s (%s)' % (unicode(self.user),
            ', '.join(arch.label for arch in self.archives.all()))

    def sorted_archives(self):
        '''List of archives this user is associated with, in order if
        they have specified any order preference.'''
        archives = self.archives.all()
        # if no archives are explicitly defined and this is a superuser,
        # give them access to all
        if not archives and self.user.is_superuser:

# 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

        permissions = (
                ("can_publish", "Can publish a finding aid"),
                ("can_preview", "Can preview a finding aid"),
                ("can_delete", "Can delete a finding aid"),
                ("can_prepare", "Can prepare a finding aid"),
                ("can_view_internal_dao", "Can view internal digital archival objects"),
        )

class Archivist(models.Model):
    user = models.OneToOneField(settings.AUTH_USER_MODEL,
        on_delete=models.CASCADE)  # if user is deleted, delete archivist too
    archives = models.ManyToManyField(Archive, blank=True)
    order = models.CommaSeparatedIntegerField(max_length=255, blank=True,
        null=True)

    def __repr__(self):
        return '<Archivist %s: %s>' % (self.user.username,
            ', '.join(arch.label for arch in self.archives.all()))

    def __unicode__(self):
        return u'Archivist %s (%s)' % (unicode(self.user),
            ', '.join(arch.label for arch in self.archives.all()))

    def sorted_archives(self):
        '''List of archives this user is associated with, in order if
        they have specified any order preference.'''
        archives = self.archives.all()
        # if no archives are explicitly defined and this is a superuser,
        # give them access to all
        if not archives and self.user.is_superuser:

            archives = Archive.objects.all()