# Path: findingaids/fa/models.py
# def title_rdf_identifier(src, idno):
#     ''''Generate an RDF identifier for a title, based on source and id
#     attributes.  Currently supports ISSN, ISBN, and OCLC.'''
#     # if either src or idno is None, bail out right away
#     if src is None or idno is None:
#         return
#     src = src.lower()
#     idno = idno.strip()  # remove whitespace, just in case of errors in entry
# 
#     if src in ['isbn', 'issn']:  # isbn and issn URNs have same format
#         return 'urn:%s:%s' % (src.upper(), idno)
#     elif src == 'oclc':
#         return 'http://www.worldcat.org/oclc/%s' % idno


from django import template
from django.utils.html import conditional_escape, escape
from django.utils.safestring import mark_safe
from eulxml.xmlmap.eadmap import EAD_NAMESPACE
from findingaids.fa.models import title_rdf_identifier
    # just use the generic "mentions" relation
    if node.xpath('ancestor::e:scopecontent', **eadns):
        # mark as a generic document or periodical and include whatever meta tags are available
        itemtype = 'bibo:Periodical' if title_source == 'issn' else 'bibo:Document'
        start = '<span rel="schema:mentions" typeof="%s"%s><span property="dc:title">' \
                 % (itemtype, resource)
        end = '</span>%s</span>' % meta_tags

    # if default rel is set to mention, assume we are patching in extra titles
    # after file item unittitle context
    elif default_rel == 'schema:mentions':
        if title_source == 'issn':
            itemtype = 'bibo:Periodical'
        elif title_source in ['isbn', 'oclc']:
            itemtype = 'bibo:Document'
        else:
            # technically we should be checking if this is a printed materials series...
            itemtype = 'bibo:Manuscript'

        # if this title has a type but no authfilenumber and there is a
        # sibling title with an id, relate them
        if title_type is not None and title_authfileno is None \
                      and node.xpath('parent::e:unittitle/e:title[@authfilenumber]',
                                     **eadns):
            rel_id = None
            rel_authfileno = node.xpath('normalize-space(parent::e:unittitle/e:title/@authfilenumber)',
                                        **eadns).strip()
            rel_source = node.xpath('normalize-space(parent::e:unittitle/e:title/@source)',
                                    **eadns).lower()


# Path: findingaids/fa/models.py
# def title_rdf_identifier(src, idno):
#     ''''Generate an RDF identifier for a title, based on source and id
#     attributes.  Currently supports ISSN, ISBN, and OCLC.'''
#     # if either src or idno is None, bail out right away
#     if src is None or idno is None:
#         return
#     src = src.lower()
#     idno = idno.strip()  # remove whitespace, just in case of errors in entry
# 
#     if src in ['isbn', 'issn']:  # isbn and issn URNs have same format
#         return 'urn:%s:%s' % (src.upper(), idno)
#     elif src == 'oclc':
#         return 'http://www.worldcat.org/oclc/%s' % idno


# Path: findingaids/fa/templatetags/ead.py
from django import template
from django.utils.html import conditional_escape, escape
from django.utils.safestring import mark_safe
from eulxml.xmlmap.eadmap import EAD_NAMESPACE
from findingaids.fa.models import title_rdf_identifier

    # just use the generic "mentions" relation
    if node.xpath('ancestor::e:scopecontent', **eadns):
        # mark as a generic document or periodical and include whatever meta tags are available
        itemtype = 'bibo:Periodical' if title_source == 'issn' else 'bibo:Document'
        start = '<span rel="schema:mentions" typeof="%s"%s><span property="dc:title">' \
                 % (itemtype, resource)
        end = '</span>%s</span>' % meta_tags

    # if default rel is set to mention, assume we are patching in extra titles
    # after file item unittitle context
    elif default_rel == 'schema:mentions':
        if title_source == 'issn':
            itemtype = 'bibo:Periodical'
        elif title_source in ['isbn', 'oclc']:
            itemtype = 'bibo:Document'
        else:
            # technically we should be checking if this is a printed materials series...
            itemtype = 'bibo:Manuscript'

        # if this title has a type but no authfilenumber and there is a
        # sibling title with an id, relate them
        if title_type is not None and title_authfileno is None \
                      and node.xpath('parent::e:unittitle/e:title[@authfilenumber]',
                                     **eadns):
            rel_id = None
            rel_authfileno = node.xpath('normalize-space(parent::e:unittitle/e:title/@authfilenumber)',
                                        **eadns).strip()
            rel_source = node.xpath('normalize-space(parent::e:unittitle/e:title/@source)',
                                    **eadns).lower()


            rel_id = title_rdf_identifier(rel_source, rel_authfileno)