<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 akvo.iati.exports.iati_org_export import IatiOrgXML
from akvo.rsr.models import Organisation

from django.http import Http404, HttpResponse
from django.shortcuts import get_object_or_404, render

from lxml import etree


###############################################################################
# Organisation directory
###############################################################################

def directory(request):
    """The Organisation list view."""
    return render(request, 'organisation_directory.html', {})


###############################################################################
# Organisation main
###############################################################################

def main(request, organisation_id):
    """The organisation main view."""
    return render(request, 'organisation_main.html', {
        'organisation': get_object_or_404(Organisation, pk=organisation_id)})


###############################################################################
# Organisation IATI files
###############################################################################

def iati(request, organisation_id):
    """Retrieve the latest public IATI XML file."""
    organisation = get_object_or_404(Organisation, pk=organisation_id)
    exports = organisation.iati_exports.filter(is_public=True).exclude(iati_file='')
    if exports:
        latest_export = exports.order_by('-id')[0]
        return HttpResponse(latest_export.iati_file, content_type="text/xml")
    raise Http404


def iati_org(request, organisation_id):
    """Generate the IATI Organisation file on-the-fly and return the XML."""
    organisation = get_object_or_404(Organisation, pk=organisation_id)
    xml_data = etree.tostring(etree.ElementTree(
        IatiOrgXML(request, [organisation]).iati_organisations))
    return HttpResponse(xml_data, content_type="text/xml")<commit_msg>[#4364] Remove reference to IatiExport.is_public in Organisation iati view<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 akvo.iati.exports.iati_org_export import IatiOrgXML
from akvo.rsr.models import Organisation

from django.http import Http404, HttpResponse
from django.shortcuts import get_object_or_404, render

from lxml import etree


###############################################################################
# Organisation directory
###############################################################################

def directory(request):
    """The Organisation list view."""
    return render(request, 'organisation_directory.html', {})


###############################################################################
# Organisation main
###############################################################################

def main(request, organisation_id):
    """The organisation main view."""
    return render(request, 'organisation_main.html', {
        'organisation': get_object_or_404(Organisation, pk=organisation_id)})


###############################################################################
# Organisation IATI files
###############################################################################

def iati(request, organisation_id):
    """Retrieve the latest public IATI XML file."""
    organisation = get_object_or_404(Organisation, pk=organisation_id)
    exports = organisation.iati_exports.filter(latest=True).exclude(iati_file='')
    if exports.exists():
        latest_export = exports.order_by('-id')[0]
        return HttpResponse(latest_export.iati_file, content_type="text/xml")
    raise Http404


def iati_org(request, organisation_id):
    """Generate the IATI Organisation file on-the-fly and return the XML."""
    organisation = get_object_or_404(Organisation, pk=organisation_id)
    xml_data = etree.tostring(etree.ElementTree(
        IatiOrgXML(request, [organisation]).iati_organisations))
    return HttpResponse(xml_data, content_type="text/xml")
{'fraction_non_alphanumeric': 0.292349113753646, 'fraction_numerical': 0.00987211128561813, 'mean_word_length': 6.2724306688417615, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '641820', 'n_tokens_mistral': 1191, 'n_tokens_neox': 1108, 'n_words': 285}