Beispiel #1
0
def process_work_title(dctype, worktitle):
    if dctype:
        return DCTYPE_WORK_TITLE_TEMPLATE % {
            'dctype_url': get_dctype_url(dctype),
            'worktitle': util.escape(worktitle)}
    else:
        return NO_DCTYPE_WORK_TITLE_TEMPLATE % {
            'worktitle': util.escape(worktitle)}
Beispiel #2
0
def process_work_type(gettext, dctype):
    work_word = gettext('work')
    if dctype:
        return WORK_TYPE_TEMPLATE % (
            {'dctype_url': get_dctype_url(dctype),
             'work': util.escape(work_word)})
    else:
        return util.escape(work_word)
Beispiel #3
0
def process_work_type(gettext, dctype):
    work_word = gettext('work')
    if dctype:
        return WORK_TYPE_TEMPLATE % ({
            'dctype_url': get_dctype_url(dctype),
            'work': util.escape(work_word)
        })
    else:
        return util.escape(work_word)
Beispiel #4
0
def process_work_author(attribution_url, attribution_name):
    if attribution_url:
        return WORK_AUTHOR_TEMPLATE % {
            'attribution_name': util.escape(
                attribution_name or attribution_url),
            'attribution_url': util.escape(attribution_url)}
    else:
        return WORK_AUTHOR_TEMPLATE_NO_URL % {
            'attribution_name': util.escape(attribution_name)}
Beispiel #5
0
def process_work_title(dctype, worktitle):
    if dctype:
        return DCTYPE_WORK_TITLE_TEMPLATE % {
            'dctype_url': get_dctype_url(dctype),
            'worktitle': util.escape(worktitle)
        }
    else:
        return NO_DCTYPE_WORK_TITLE_TEMPLATE % {
            'worktitle': util.escape(worktitle)
        }
Beispiel #6
0
def process_work_author(attribution_url, attribution_name):
    if attribution_url:
        return WORK_AUTHOR_TEMPLATE % {
            'attribution_name': util.escape(attribution_name
                                            or attribution_url),
            'attribution_url': util.escape(attribution_url)
        }
    else:
        return WORK_AUTHOR_TEMPLATE_NO_URL % {
            'attribution_name': util.escape(attribution_name)
        }
Beispiel #7
0
    def format(self, license, work_dict=None, locale='en'):
        work_dict = work_dict or {}

        gettext = ugettext_for_locale(locale)

        dctype = None
        if work_dict.get('format'):
            dctype = _translate_dctype(work_dict['format'].lower())

        image_header = IMAGE_HEADER_TEMPLATE % {
            'license_url':
            license.uri,
            'util.Creative_Commons_License':
            util.escape(gettext(u'Creative Commons License')),
            'license_logo':
            license.logo
        }

        body_template = gettext(
            u'This %(work_type)s is in the '
            u'<a rel="license" href="http://creativecommons.org/licenses/publicdomain/">Public Domain</a>.'
        )
        body_vars = {'work_type': process_work_type(gettext, dctype)}

        message = image_header + body_template % body_vars

        return message
Beispiel #8
0
    def format(self, license, work_dict=None, locale='en'):
        work_dict = work_dict or {}

        gettext = ugettext_for_locale(locale)

        dctype = None
        if work_dict.get('format'):
            dctype = _translate_dctype(work_dict['format'].lower())

        image_header = IMAGE_HEADER_TEMPLATE % {
            'license_url': license.uri,
            'util.Creative_Commons_License': util.escape(gettext(
                u'Creative Commons License')),
            'license_logo': license.logo}

        body_template = gettext(
            u'This %(work_type)s is in the '
            u'<a rel="license" href="http://creativecommons.org/licenses/publicdomain/">Public Domain</a>.')
        body_vars = {'work_type': process_work_type(gettext, dctype)}

        message = image_header + body_template % body_vars

        return message
Beispiel #9
0
    def format(self, license, work_dict=None, locale='en'):
        """
        Return an HTML + RDFa string of text for the license.

        work_dict takes the following keys:
         - work_title: Name of the work
         - author_title: Original author of the work
         - author_href: Link to the original author of the work
         - curator_title: The person who identified this work
         - curator_href: Link to the person who identified this work
         - waive_cc0: Whether the author has also waived their rights
           under CC0 (boolean)
        """
        gettext = ugettext_for_locale(locale)

        # Property gathering
        # ------------------
        work_dict = work_dict or {}

        work_title = work_dict.get('work_title', False)

        author_title = work_dict.get('author_title', '').strip()
        author_href = work_dict.get('author_href', '').strip()

        curator_title = work_dict.get('curator_title', '').strip()
        curator_href = work_dict.get('curator_href', '').strip()

        waive_cc0 = work_dict.get('waive_cc0', False)

        # Find the "body" template
        # ------------------------

        has_author = bool(author_title or author_href)
        has_curator = bool(curator_title or curator_href)

        # All (work_title and author and curator)
        if work_title and has_author and has_curator:
            body_msg = PDMARK_WORKTITLE_AUTHOR_CURATOR
        # Only work_title
        elif work_title and not has_author and not has_curator:
            body_msg = PDMARK_WORKTITLE
        # Only author
        elif has_author and not work_title and not has_curator:
            body_msg = PDMARK_AUTHOR
        # Only curator
        elif has_curator and not work_title and not has_author:
            body_msg = PDMARK_CURATOR
        # work_title and author
        elif work_title and has_author and not has_curator:
            body_msg = PDMARK_WORKTITLE_AUTHOR
        # work_title and curator
        elif work_title and has_curator and not has_author:
            body_msg = PDMARK_WORKTITLE_CURATOR
        # author and curator
        elif has_author and has_curator and not work_title:
            body_msg = PDMARK_AUTHOR_CURATOR
        # plain
        else:
            body_msg = PDMARK_PLAIN

        # Translate the body
        # ------------------
        mapping = {}

        if work_title:
            mapping['work_title'] = u'<span property="dct:title">%s</span>' % (
                util.escape(work_title))

        if has_author:
            if author_title and author_href:
                mapping['author'] = PDMARK_AUTHOR_LINK % (
                    {
                        'author_title': util.escape(author_title),
                        'author_href': util.escape(author_href)
                    })
            elif author_title and not author_href:
                mapping['author'] = PDMARK_AUTHOR_NOLINK % ({
                    'author_title':
                    util.escape(author_title)
                })
            elif author_href and not author_title:
                mapping['author'] = PDMARK_AUTHOR_ONLYLINK % ({
                    'author_href':
                    util.escape(author_href)
                })

        if has_curator:
            if curator_title and curator_href:
                mapping['curator'] = PDMARK_CURATOR_LINK % (
                    {
                        'curator_title': util.escape(curator_title),
                        'curator_href': util.escape(curator_href)
                    })
            elif curator_title and not curator_href:
                mapping['curator'] = PDMARK_CURATOR_NOLINK % ({
                    'curator_title':
                    util.escape(curator_title)
                })
            elif curator_href and not curator_title:
                mapping['curator'] = PDMARK_CURATOR_ONLYLINK % ({
                    'curator_href':
                    util.escape(curator_href)
                })

        body = gettext(body_msg) % mapping

        # Add the header and footers
        # --------------------------
        output_sections = []

        # XXX: Norms guidelines may affect opening <p>?
        if work_title or has_author or has_curator:
            output_sections.append(
                u'<p xmlns:dct="http://purl.org/dc/terms/">')
        else:
            output_sections.append(u'<p>')

        # Add logos
        output_sections.append(PDMARK_LOGO_HTML)
        if waive_cc0:
            output_sections.append(CC0_LOGO_HTML)

        output_sections.append(u'<br />')

        # Add body
        output_sections.append(body)

        # Add footer
        output_sections.append(u'</p>')

        return u'\n'.join(output_sections)
Beispiel #10
0
    def format(self, license, work_dict=None, locale='en'):
        """Return an HTML + RDFa string serialization for the license,
            optionally incorporating the work metadata and locale."""
        gettext = ugettext_for_locale(locale)

        work_dict = work_dict or {}

        image_header = IMAGE_HEADER_TEMPLATE % {
            'license_url':
            license.uri,
            'util.Creative_Commons_License':
            util.escape(gettext(u'Creative Commons License')),
            'license_logo':
            license.logo
        }

        dctype = None
        if work_dict.get('format'):
            dctype = _translate_dctype(work_dict['format'].lower())

        body_vars = {
            'license_url':
            license.uri,
            'license_name':
            util.escape(license.title(locale_to_lower_lower(locale)))
        }

        if ((work_dict.get('attribution_url')
             or work_dict.get('attribution_name'))
                and work_dict.get('worktitle')):
            body_template = gettext(
                u'%(work_title)s by %(work_author)s is licensed under a '
                u'<a rel="license" href="%(license_url)s">Creative Commons '
                u'%(license_name)s License</a>.')
            body_vars.update({
                'work_title':
                process_work_title(dctype, work_dict['worktitle']),
                'work_author':
                process_work_author(work_dict.get('attribution_url'),
                                    work_dict.get('attribution_name'))
            })

        elif work_dict.get('attribution_url') \
                or work_dict.get('attribution_name'):
            body_template = gettext(
                u'This %(work_type)s by %(work_author)s is licensed under '
                u'a <a rel="license" href="%(license_url)s">Creative '
                u'Commons %(license_name)s License</a>.')
            body_vars.update({
                'work_type':
                process_work_type(gettext, dctype),
                'work_author':
                process_work_author(work_dict.get('attribution_url'),
                                    work_dict.get('attribution_name'))
            })

        elif work_dict.get('worktitle'):
            body_template = gettext(
                u'%(work_title)s is licensed under a '
                u'<a rel="license" href="%(license_url)s">Creative Commons '
                u'%(license_name)s License</a>.')
            body_vars.update({
                'work_title':
                process_work_title(dctype, work_dict['worktitle'])
            })

        else:
            body_template = gettext(
                u'This %(work_type)s is licensed under a '
                u'<a rel="license" href="%(license_url)s">Creative Commons '
                u'%(license_name)s License</a>.')
            body_vars.update({'work_type': process_work_type(gettext, dctype)})

        message = image_header + body_template % body_vars

        if work_dict.get('source_work'):
            source_work_template = gettext(
                u'Based on a work at %(source_link)s.')
            source_domain = urlparse(work_dict['source_work'])[1]
            if not source_domain.strip():
                source_domain = work_dict['source_work']
            source_work = source_work_template % {
                'source_link': SOURCE_LINK_TEMPLATE % {
                    'source_work': util.escape(work_dict['source_work']),
                    'source_domain': util.escape(source_domain)
                }
            }
            message = message + "<br />" + source_work

        if work_dict.get('more_permissions_url'):
            more_perms_template = gettext(
                u'Permissions beyond the scope of this license may be '
                u'available at %(more_perms_link)s.')
            more_perms = more_perms_template % {
                'more_perms_link': MORE_PERMS_LINK_TEMPATE % {
                    'more_permissions_url':
                    util.escape(work_dict['more_permissions_url'])
                }
            }
            message = message + "<br />" + more_perms

        return message
Beispiel #11
0
    def format(self, license, work_dict=None, locale='en'):
        """
        Return an HTML + RDFa string of text for the license.

        work_dict takes the following keys:
         - work_title: Name of the work
         - author_title: Original author of the work
         - author_href: Link to the original author of the work
         - curator_title: The person who identified this work
         - curator_href: Link to the person who identified this work
         - waive_cc0: Whether the author has also waived their rights
           under CC0 (boolean)
        """
        gettext = ugettext_for_locale(locale)

        # Property gathering
        # ------------------
        work_dict = work_dict or {}

        work_title = work_dict.get('work_title', False)

        author_title = work_dict.get('author_title', '').strip()
        author_href = work_dict.get('author_href', '').strip()

        curator_title = work_dict.get('curator_title', '').strip()
        curator_href = work_dict.get('curator_href', '').strip()

        waive_cc0 = work_dict.get('waive_cc0', False)

        # Find the "body" template
        # ------------------------

        has_author = bool(author_title or author_href)
        has_curator = bool(curator_title or curator_href)

        # All (work_title and author and curator)
        if work_title and has_author and has_curator:
            body_msg = PDMARK_WORKTITLE_AUTHOR_CURATOR
        # Only work_title
        elif work_title and not has_author and not has_curator:
            body_msg = PDMARK_WORKTITLE
        # Only author
        elif has_author and not work_title and not has_curator:
            body_msg = PDMARK_AUTHOR
        # Only curator
        elif has_curator and not work_title and not has_author:
            body_msg = PDMARK_CURATOR
        # work_title and author
        elif work_title and has_author and not has_curator:
            body_msg = PDMARK_WORKTITLE_AUTHOR
        # work_title and curator
        elif work_title and has_curator and not has_author:
            body_msg = PDMARK_WORKTITLE_CURATOR
        # author and curator
        elif has_author and has_curator and not work_title:
            body_msg = PDMARK_AUTHOR_CURATOR
        # plain
        else:
            body_msg = PDMARK_PLAIN

        # Translate the body
        # ------------------
        mapping = {}

        if work_title:
            mapping['work_title'] = u'<span property="dct:title">%s</span>' % (
                util.escape(work_title))

        if has_author:
            if author_title and author_href:
                mapping['author'] = PDMARK_AUTHOR_LINK % (
                    {'author_title': util.escape(author_title),
                     'author_href': util.escape(author_href)})
            elif author_title and not author_href:
                mapping['author'] = PDMARK_AUTHOR_NOLINK % (
                    {'author_title': util.escape(author_title)})
            elif author_href and not author_title:
                mapping['author'] = PDMARK_AUTHOR_ONLYLINK % (
                    {'author_href': util.escape(author_href)})
                
        if has_curator:
            if curator_title and curator_href:
                mapping['curator'] = PDMARK_CURATOR_LINK % (
                    {'curator_title': util.escape(curator_title),
                     'curator_href': util.escape(curator_href)})
            elif curator_title and not curator_href:
                mapping['curator'] = PDMARK_CURATOR_NOLINK % (
                    {'curator_title': util.escape(curator_title)})
            elif curator_href and not curator_title:
                mapping['curator'] = PDMARK_CURATOR_ONLYLINK % (
                    {'curator_href': util.escape(curator_href)})

        body = gettext(body_msg) % mapping

        # Add the header and footers
        # --------------------------
        output_sections = []

        # XXX: Norms guidelines may affect opening <p>?
        if work_title or has_author or has_curator:
            output_sections.append(
                u'<p xmlns:dct="http://purl.org/dc/terms/">')
        else:
            output_sections.append(u'<p>')

        # Add logos
        output_sections.append(PDMARK_LOGO_HTML)
        if waive_cc0:
            output_sections.append(CC0_LOGO_HTML)

        output_sections.append(u'<br />')

        # Add body
        output_sections.append(body)

        # Add footer
        output_sections.append(u'</p>')

        return u'\n'.join(output_sections)
Beispiel #12
0
    def format(self, license, work_dict=None, locale='en'):
        """Return an HTML + RDFa string serialization for the license,
            optionally incorporating the work metadata and locale."""
        gettext = ugettext_for_locale(locale)

        work_dict = work_dict or {}

        localized_deed = license.uri
        default_lang = license.jurisdiction.default_language
        if not default_lang:
            default_lang = "en"
        if locale != default_lang:
            localized_deed += "deed." + locale

        image_header = IMAGE_HEADER_TEMPLATE % {
            'license_url': localized_deed,
            'util.Creative_Commons_License': util.escape(
                gettext(u'Creative Commons License')),
            'license_logo': license.logo}

        dctype = None
        if work_dict.get('format'):
            dctype = _translate_dctype(work_dict['format'].lower())

        body_vars = {
            'license_url': localized_deed,
            'license_name': util.escape(
                license.title(locale_to_lower_lower(locale)))}

        if ((work_dict.get('attribution_url')
             or work_dict.get('attribution_name'))
                and work_dict.get('worktitle')):
            body_template = gettext(
                    u'%(work_title)s by %(work_author)s is licensed under a '
                    u'<a rel="license" href="%(license_url)s">Creative Commons '
                    u'%(license_name)s License</a>.')
            body_vars.update(
                {'work_title': process_work_title(
                        dctype, work_dict['worktitle']),
                 'work_author': process_work_author(
                        work_dict.get('attribution_url'),
                        work_dict.get('attribution_name'))})
                 
        elif work_dict.get('attribution_url') \
                or work_dict.get('attribution_name'):
            body_template = gettext(
                    u'This %(work_type)s by %(work_author)s is licensed under '
                    u'a <a rel="license" href="%(license_url)s">Creative '
                    u'Commons %(license_name)s License</a>.')
            body_vars.update(
                {'work_type': process_work_type(gettext, dctype),
                 'work_author': process_work_author(
                        work_dict.get('attribution_url'),
                        work_dict.get('attribution_name'))})

        elif work_dict.get('worktitle'):
            body_template = gettext(
                    u'%(work_title)s is licensed under a '
                    u'<a rel="license" href="%(license_url)s">Creative Commons '
                    u'%(license_name)s License</a>.')
            body_vars.update(
                {'work_title': process_work_title(
                        dctype, work_dict['worktitle'])})

        else:
            body_template = gettext(
                    u'This %(work_type)s is licensed under a '
                    u'<a rel="license" href="%(license_url)s">Creative Commons '
                    u'%(license_name)s License</a>.')
            body_vars.update(
                {'work_type': process_work_type(gettext, dctype)})

        message = image_header + body_template % body_vars

        if work_dict.get('source_work'):
            source_work_template = gettext(
                u'Based on a work at %(source_link)s.')
            source_domain = urlparse(work_dict['source_work'])[1]
            if not source_domain.strip():
                source_domain = work_dict['source_work']
            source_work = source_work_template % {
                'source_link': SOURCE_LINK_TEMPLATE % {
                    'source_work': util.escape(work_dict['source_work']),
                    'source_domain': util.escape(source_domain)}}
            message = message + "<br />" + source_work

        if work_dict.get('more_permissions_url'):
            more_perms_template = gettext(
                    u'Permissions beyond the scope of this license may be '
                    u'available at %(more_perms_link)s.')
            more_perms = more_perms_template % {
                'more_perms_link': MORE_PERMS_LINK_TEMPATE % {
                    'more_permissions_url': util.escape(
                        work_dict['more_permissions_url'])}}
            message = message + "<br />" + more_perms

        return message
Beispiel #13
0
def test_escape():
    assert util.escape('\'"<>&') == '&#39;&#34;&lt;&gt;&amp;'