from django.conf.urls.defaults import *

TITLE_LETTERS = '[a-zA-Z]'

title_urlpatterns = patterns('findingaids.fa.views',
    url('^$', 'browse_titles', name='browse-titles'),
    url(r'^(?P<letter>%s)/$' % TITLE_LETTERS, 'titles_by_letter', name='titles-by-letter')
)

# patterns for ead document id and series id
# defined here for use in urls and in custom management commands that check id patterns
EADID_URL_REGEX = "(?P<id>[-_A-Za-z0-9.]+)"
series_id = "[a-zA-Z0-9-._]+"

# urls under a single document url (e.g., /documents/abbey244/ )
findingaid_parts = patterns('findingaids.fa.views',
    url(r'^$', 'findingaid', name='findingaid'),
    url(r'^EAD/$', 'eadxml', name='eadxml'),
    # full finding aid as simple html (html version of pdf, for testing)
    url(r'^full/$', 'full_findingaid', {'mode': 'html'}, name='full-findingaid'),
    # view access to XSL-FO used to generate pdf (for testing)
    url(r'^xsl-fo/$', 'full_findingaid', {'mode': 'xsl-fo'}, name='xslfo'),
    url(r'^printable/$', 'full_findingaid', {'mode': 'pdf'}, name='printable'),
    url(r'^items/$', 'document_search', name='singledoc-search'),
    url(r'^(?P<series_id>%s)/$' % series_id, 'series_or_index', name='series-or-index'),
    # NOTE: django can't reverse url patterns with optional parameters
    # so series, subseries, and sub-subseries urls have to be defined separately
    url(r'^(?P<series_id>%(re)s)/(?P<series2_id>%(re)s)/$' % {'re': series_id},
        'series_or_index', name='series2'),
    url(r'^(?P<series_id>%(re)s)/(?P<series2_id>%(re)s)/(?P<series3_id>%(re)s)/$' \
        % {'re': series_id}, 'series_or_index', name='series3'),
)

findingaid_urlpatterns = patterns('findingaids.fa.views',
    (r'^%s/' % EADID_URL_REGEX, include(findingaid_parts)),
)

urlpatterns = patterns('findingaids.fa.views',
    (r'^titles/', include(title_urlpatterns)),
    (r'^documents/', include(findingaid_urlpatterns)),
    url(r'^search/?', 'search', name='search')
)

from django.conf.urls.defaults import *

TITLE_LETTERS = '[a-zA-Z]'

title_urlpatterns = patterns('findingaids.fa.views',
    url('^$', 'browse_titles', name='browse-titles'),
    url(r'^(?P<letter>%s)/$' % TITLE_LETTERS, 'titles_by_letter', name='titles-by-letter')
)

# patterns for ead document id and series id
# defined here for use in urls and in custom management commands that check id patterns
EADID_URL_REGEX = "(?P<id>[-_A-Za-z0-9.]+)"
series_id = "[a-zA-Z0-9-._]+"

# urls under a single document url (e.g., /documents/abbey244/ )
findingaid_parts = patterns('findingaids.fa.views',
    url(r'^$', 'findingaid', name='findingaid'),
    url(r'^EAD/$', 'eadxml', name='eadxml'),
    # full finding aid as simple html (html version of pdf, for testing)
    url(r'^full/$', 'full_findingaid', {'mode': 'html'}, name='full-findingaid'),
    # view access to XSL-FO used to generate pdf (for testing)
    url(r'^xsl-fo/$', 'full_findingaid', {'mode': 'xsl-fo'}, name='xslfo'),
    url(r'^printable/$', 'full_findingaid', {'mode': 'pdf'}, name='printable'),
    url(r'^items/$', 'document_search', name='singledoc-search'),
    url(r'^(?P<series_id>%s)/$' % series_id, 'series_or_index', name='series-or-index'),
    # NOTE: django can't reverse url patterns with optional parameters
    # so series, subseries, and sub-subseries urls have to be defined separately
    url(r'^(?P<series_id>%(re)s)/(?P<series2_id>%(re)s)/$' % {'re': series_id},
        'series_or_index', name='series2'),
    url(r'^(?P<series_id>%(re)s)/(?P<series2_id>%(re)s)/(?P<series3_id>%(re)s)/$' \
        % {'re': series_id}, 'series_or_index', name='series3'),
)

findingaid_urlpatterns = patterns('findingaids.fa.views',
    (r'^%s/' % EADID_URL_REGEX, include(findingaid_parts)),
)

urlpatterns = patterns('findingaids.fa.views',
    (r'^titles/', include(title_urlpatterns)),
    (r'^documents/', include(findingaid_urlpatterns)),
    url(r'^search/', 'search', name='search')
)

correct search url to work like others according to django standard with trailing slash