<commit_before>from __future__ import unicode_literals, absolute_import
from babel.dates import format_timedelta
from django.conf import settings
import itertools
import json
from oim_cms.utils import CSVDjangoResource
from restless.dj import DjangoResource
from restless.resources import skip_prepare

from .models import ITSystem, Hardware, ITSystemDependency, ITSystemVendor


class ITSystemResource(CSVDjangoResource):

    def prepare(self, data):
        """Prepare a custom API response for ITSystemResource objects.
        """
        # Owner > CC > Division > Manager
        cost_centre__division__manager__name = ''
        cost_centre__division__manager__email = ''
        cost_centre__division__manager__title = ''
        cost_centre__division__name = ''
        cost_centre__name = ''
        cost_centre__code = ''
        # Every damn field is nullable!
        if data.owner:<commit_msg>For ITSystemResource response, return cost_centre details in preference to owner.cost_centre.<commit_after>from __future__ import unicode_literals, absolute_import
from babel.dates import format_timedelta
from django.conf import settings
import itertools
import json
from oim_cms.utils import CSVDjangoResource
from restless.dj import DjangoResource
from restless.resources import skip_prepare

from .models import ITSystem, Hardware, ITSystemDependency, ITSystemVendor


class ITSystemResource(CSVDjangoResource):

    def prepare(self, data):
        """Prepare a custom API response for ITSystemResource objects.
        """
        # Owner > CC > Division > Manager
        cost_centre__division__manager__name = ''
        cost_centre__division__manager__email = ''
        cost_centre__division__manager__title = ''
        cost_centre__division__name = ''
        cost_centre__name = ''
        cost_centre__code = ''
        # Every damn field is nullable!
        if data.cost_centre:  # Use this field first.
            cost_centre__name = data.cost_centre.name
            cost_centre__code = data.cost_centre.code
            if data.cost_centre.division:
                cost_centre__division__name = data.cost_centre.division.name
                if data.cost_centre.division.manager:
                    cost_centre__division__manager__name = data.cost_centre.division.manager.name
                    cost_centre__division__manager__email = data.cost_centre.division.manager.email
                    cost_centre__division__manager__title = data.cost_centre.division.manager.title
        elif data.owner:  # Use this second.
{'fraction_non_alphanumeric': 0.05766967438211063, 'fraction_numerical': 0.0, 'mean_word_length': 3.3664383561643834, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': 2, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2080197', 'n_tokens_mistral': 715, 'n_tokens_neox': 675, 'n_words': 165}