# Path: findingaids/utils.py
# def normalize_whitespace(txt):
#     'Normalize whitespace in a string'
#     return re.sub(_normalize_ws_re, ' ', txt)


from datetime import datetime
from django.conf import settings
from django.contrib.sites.models import Site
from django.core.cache import cache
from django.core.urlresolvers import reverse
from django.db import models
from eulxml import xmlmap
from eulxml.xmlmap import eadmap
from eulexistdb.manager import Manager
from eulexistdb.models import XmlModel
from findingaids.utils import normalize_whitespace
import logging
import os
            for use with external services such as Aeon'''

        current_site = Site.objects.get_current()
        return ''.join([
            'http://',
            current_site.domain.rstrip('/'),
            reverse('fa:eadxml', kwargs={"id":self.eadid.value})
            ])

    def request_materials_url(self):
        ''' Construct the absolute url for use with external services such as Aeon'''

        if not hasattr(settings, 'REQUEST_MATERIALS_URL') or not settings.REQUEST_MATERIALS_URL:
            logger.warn("Request materials url is not configured.")
            return

        base = settings.REQUEST_MATERIALS_URL
        return ''.join([base, self.absolute_eadxml_url()])

    def requestable(self):
        ''' Determines if the EAD is applicable for the electronic request service.'''

        # If the request url is not configured, then the request can't be generated.
        if not hasattr(settings, 'REQUEST_MATERIALS_URL') or not settings.REQUEST_MATERIALS_URL:
            return False

        if not hasattr(settings, 'REQUEST_MATERIALS_REPOS') or not settings.REQUEST_MATERIALS_REPOS:
            return False

        # If the item is in on of the libraries defined, then it should be displayed.

# Path: findingaids/utils.py
# def normalize_whitespace(txt):
#     'Normalize whitespace in a string'
#     return re.sub(_normalize_ws_re, ' ', txt)


# Path: findingaids/fa/models.py
from datetime import datetime
from django.conf import settings
from django.contrib.sites.models import Site
from django.core.cache import cache
from django.core.urlresolvers import reverse
from django.db import models
from eulxml import xmlmap
from eulxml.xmlmap import eadmap
from eulexistdb.manager import Manager
from eulexistdb.models import XmlModel
from findingaids.utils import normalize_whitespace
import logging
import os

            for use with external services such as Aeon'''

        current_site = Site.objects.get_current()
        return ''.join([
            'http://',
            current_site.domain.rstrip('/'),
            reverse('fa:eadxml', kwargs={"id":self.eadid.value})
            ])

    def request_materials_url(self):
        ''' Construct the absolute url for use with external services such as Aeon'''

        if not hasattr(settings, 'REQUEST_MATERIALS_URL') or not settings.REQUEST_MATERIALS_URL:
            logger.warn("Request materials url is not configured.")
            return

        base = settings.REQUEST_MATERIALS_URL
        return ''.join([base, self.absolute_eadxml_url()])

    def requestable(self):
        ''' Determines if the EAD is applicable for the electronic request service.'''

        # If the request url is not configured, then the request can't be generated.
        if not hasattr(settings, 'REQUEST_MATERIALS_URL') or not settings.REQUEST_MATERIALS_URL:
            return False

        if not hasattr(settings, 'REQUEST_MATERIALS_REPOS') or not settings.REQUEST_MATERIALS_REPOS:
            return False

        # If the item is in on of the libraries defined, then it should be displayed.

        return any([normalize_whitespace(repo) in settings.REQUEST_MATERIALS_REPOS