<commit_before># -*- coding: utf-8 -*-

# Akvo RSR is covered by the GNU Affero General Public License.
# See more details in the license.txt file located at the root folder of the Akvo RSR module.
# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.

from lxml import etree


def document_link(organisation, request):
    """
    Generate the document-link elements.

    :param organisation: Organisation object
    :param request: Django request object
    :return: A list of Etree elements
    """
    document_link_elements = []

    if organisation.logo:
        logo_element = etree.Element("document-link")
        logo_element.attrib['url'] = request.get_host() + organisation.logo.url
        logo_element.attrib['format'] = "image/jpeg"

        title_element = etree.SubElement(logo_element, "title")
        narrative_element = etree.SubElement(title_element, "narrative")
        narrative_element.text = "Organisation logo"

        category_element = etree.SubElement(logo_element, "category")
        category_element.attrib['code'] = "A12"

        document_link_elements.append(logo_element)

    for document in organisation.documents.all():
        if document.url or document.document or document.format or document.title or \
                document.categories.all() or document.language or document.document_date:
            document_element = etree.Element("document-link")

            if document.url:
                document_element.attrib['url'] = document.url
            elif document.document:
                document_element.attrib['url'] = request.get_host() + document.document.url

            if document.format:
                document_element.attrib['format'] = document.format

            if document.title:
                title_element = etree.SubElement(document_element, "title")
                narrative_element = etree.SubElement(title_element, "narrative")
                narrative_element.text = document.title

                if document.title_language:
                    narrative_element.attrib['{http://www.w3.org/XML/1998/namespace}lang'] = \
                        document.title_language

            for category in document.categories.all():
                category_element = etree.SubElement(document_element, "category")
                category_element.attrib['code'] = category.category

            if document.language:
                language_element = etree.SubElement(document_element, "language")
                language_element.attrib['code'] = document.language

            if document.document_date:<commit_msg>[#1040] Add 'http://' to document links<commit_after># -*- coding: utf-8 -*-

# Akvo RSR is covered by the GNU Affero General Public License.
# See more details in the license.txt file located at the root folder of the Akvo RSR module.
# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.

from lxml import etree


def document_link(organisation, request):
    """
    Generate the document-link elements.

    :param organisation: Organisation object
    :param request: Django request object
    :return: A list of Etree elements
    """
    document_link_elements = []

    if organisation.logo:
        logo_element = etree.Element("document-link")
        logo_element.attrib['url'] = 'http://' + request.get_host() + organisation.logo.url
        logo_element.attrib['format'] = "image/jpeg"

        title_element = etree.SubElement(logo_element, "title")
        narrative_element = etree.SubElement(title_element, "narrative")
        narrative_element.text = "Organisation logo"

        category_element = etree.SubElement(logo_element, "category")
        category_element.attrib['code'] = "A12"

        document_link_elements.append(logo_element)

    for document in organisation.documents.all():
        if document.url or document.document or document.format or document.title or \
                document.categories.all() or document.language or document.document_date:
            document_element = etree.Element("document-link")

            if document.url:
                document_element.attrib['url'] = document.url
            elif document.document:
                document_element.attrib['url'] = 'http://' + request.get_host() + \
                                                 document.document.url

            if document.format:
                document_element.attrib['format'] = document.format

            if document.title:
                title_element = etree.SubElement(document_element, "title")
                narrative_element = etree.SubElement(title_element, "narrative")
                narrative_element.text = document.title

                if document.title_language:
                    narrative_element.attrib['{http://www.w3.org/XML/1998/namespace}lang'] = \
                        document.title_language

            for category in document.categories.all():
                category_element = etree.SubElement(document_element, "category")
                category_element.attrib['code'] = category.category

            if document.language:
                language_element = etree.SubElement(document_element, "language")
                language_element.attrib['code'] = document.language

            if document.document_date:
{'fraction_non_alphanumeric': 0.09600742804085423, 'fraction_numerical': 0.003714020427112349, 'mean_word_length': 2.486084142394822, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7142310', 'n_tokens_mistral': 1421, 'n_tokens_neox': 1365, 'n_words': 320}