<commit_before>from rest_framework import viewsets
from rest_framework.exceptions import ParseError
from rest_framework.response import Response

from treeherder.model.models import JobLog


class JobLogUrlViewSet(viewsets.ViewSet):
    """
    A job_log_url object holds a reference to a job log.
    """

    @staticmethod
    def _log_as_dict(log):
        return {
            'id': log.id,
            'job_id': log.job_id,
            'name': log.name,
            'url': log.url,
            'parse_status': log.get_status_display(),
        }

    def retrieve(self, request, project, pk=None):
        """
        Returns a job_log_url object given its ID
        """
        log = JobLog.objects.get(id=pk)
        return Response(self._log_as_dict(log))

    def list(self, request, project):
        """
        GET method implementation for list view
        job_id -- Mandatory filter indicating which job these log belongs to.
        """
        job_ids = request.query_params.getlist('job_id')
        if not job_ids:
            raise ParseError(
                detail="The job_id parameter is mandatory for this endpoint")
        try:
            job_ids = [int(job_id) for job_id in job_ids]
        except ValueError:
            raise ParseError(detail="The job_id parameter(s) must be integers")

        logs = JobLog.objects.filter(job__repository__name=project,
                                     job__project_specific_id__in=job_ids)

        return Response([self._log_as_dict(log) for log in logs])<commit_msg>Bug 1306903 - Return project specific id from job-log-url endpoint (#1903)<commit_after>from rest_framework import viewsets
from rest_framework.exceptions import ParseError
from rest_framework.response import Response

from treeherder.model.models import JobLog


class JobLogUrlViewSet(viewsets.ViewSet):
    """
    A job_log_url object holds a reference to a job log.
    """

    @staticmethod
    def _log_as_dict(log):
        return {
            'id': log.id,
            'job_id': log.job.project_specific_id,
            'name': log.name,
            'url': log.url,
            'parse_status': log.get_status_display(),
        }

    def retrieve(self, request, project, pk=None):
        """
        Returns a job_log_url object given its ID
        """
        log = JobLog.objects.get(id=pk)
        return Response(self._log_as_dict(log))

    def list(self, request, project):
        """
        GET method implementation for list view
        job_id -- Mandatory filter indicating which job these log belongs to.
        """
        job_ids = request.query_params.getlist('job_id')
        if not job_ids:
            raise ParseError(
                detail="The job_id parameter is mandatory for this endpoint")
        try:
            job_ids = [int(job_id) for job_id in job_ids]
        except ValueError:
            raise ParseError(detail="The job_id parameter(s) must be integers")

        logs = JobLog.objects.filter(job__repository__name=project,
                                     job__project_specific_id__in=job_ids).select_related(
                                         'job__project_specific_id')

        return Response([self._log_as_dict(log) for log in logs])
{'fraction_non_alphanumeric': 0.08433364112034472, 'fraction_numerical': 0.003385657125269314, 'mean_word_length': 2.237051792828685, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3295204', 'n_tokens_mistral': 919, 'n_tokens_neox': 892, 'n_words': 245}