<commit_before>from __future__ import unicode_literals, absolute_import
from django.conf.urls import include, url
from mptt.templatetags.mptt_tags import cache_tree_children
from restless.dj import DjangoResource
from restless.preparers import FieldsPreparer
from restless.resources import skip_prepare

from approvals.api import ApprovalResource
from assets.api import HardwareAssetResource
from core.models import UserSession
from mudmap.models import MudMap
from organisation.api import DepartmentUserResource, LocationResource, profile
from organisation.models import DepartmentUser, Location, OrgUnit, CostCentre
from registers.api import ITSystemResource, HardwareResource
from registers.models import ITSystem
from tracking.api import EC2InstanceResource, FreshdeskTicketResource
from forms.api import ITSystemObj, PeopleObj, SaveITSystemRequest
from .utils import CSVDjangoResource


def recursive_node_to_dict(node):
    # http://stackoverflow.com/questions/12556268/fastest-way-to-create-json-to-reflect-a-tree-structure-in-python-django-using
    result = {
        'name': node.name, 'id': node.pk,
        'children': [recursive_node_to_dict(c) for c in node._cached_children]
    }
    if not result['children']:
        del result['children']
    return result


class OptionResource(DjangoResource):
    """Returns serialised lists of object data. Request parameter must include
    ``list`` value of a defined function (below), minus the ``data_`` prefix.
    Example:
    /api/options?list=org_structure
    """

    @skip_prepare
    def list(self):
        return getattr(self, 'data_' + self.request.GET['list'])()

    def data_org_structure(self):
        return [recursive_node_to_dict(cache_tree_children(dept.get_descendants_active(include_self=True))[0])<commit_msg>Fix bug: left-over dud imports.<commit_after>from __future__ import unicode_literals, absolute_import
from django.conf.urls import include, url
from mptt.templatetags.mptt_tags import cache_tree_children
from restless.dj import DjangoResource
from restless.preparers import FieldsPreparer
from restless.resources import skip_prepare

from approvals.api import ApprovalResource
from assets.api import HardwareAssetResource
from core.models import UserSession
from mudmap.models import MudMap
from organisation.api import DepartmentUserResource, LocationResource, profile
from organisation.models import DepartmentUser, Location, OrgUnit, CostCentre
from registers.api import ITSystemResource, HardwareResource
from registers.models import ITSystem
from tracking.api import EC2InstanceResource, FreshdeskTicketResource
from .utils import CSVDjangoResource


def recursive_node_to_dict(node):
    # http://stackoverflow.com/questions/12556268/fastest-way-to-create-json-to-reflect-a-tree-structure-in-python-django-using
    result = {
        'name': node.name, 'id': node.pk,
        'children': [recursive_node_to_dict(c) for c in node._cached_children]
    }
    if not result['children']:
        del result['children']
    return result


class OptionResource(DjangoResource):
    """Returns serialised lists of object data. Request parameter must include
    ``list`` value of a defined function (below), minus the ``data_`` prefix.
    Example:
    /api/options?list=org_structure
    """

    @skip_prepare
    def list(self):
        return getattr(self, 'data_' + self.request.GET['list'])()

    def data_org_structure(self):
        return [recursive_node_to_dict(cache_tree_children(dept.get_descendants_active(include_self=True))[0])
{'fraction_non_alphanumeric': 0.08196721311475409, 'fraction_numerical': 0.005652911249293386, 'mean_word_length': 5.165505226480836, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '4773564', 'n_tokens_mistral': 1028, 'n_tokens_neox': 977, 'n_words': 269}