# Path: src/app/models.py
# class Build(models.Model):
# 
#     class Meta:
#         db_table = 'builds'
# 
#     number = models.IntegerField()
#     job = models.ForeignKey(Job, related_name="builds")
#     created = models.DateTimeField(auto_now_add=True)
#     result = models.TextField(default="")
# 
#     def __str__(self):
#         return "{0}:{1}".format(self.job.name, self.number)
# 
# class Job(models.Model):
# 
#     class Meta:
#         db_table = 'jobs'
# 
#     name = models.CharField(unique=True, max_length=250)
#     description = models.TextField(blank=True, default='')
#     svn_url = models.TextField()
#     svn_username = models.TextField(blank=True, default='')
#     svn_password = models.TextField(blank=True, default='')
# 
#     recipient = models.TextField()
#     violation_threshold_num = models.IntegerField(default=888)
# 
#     def __str__(self):
#         return self.name


import json
from datetime import date, datetime
from django.conf import settings
from django.contrib.auth import get_user_model
from rest_framework import serializers
from rest_framework.reverse import reverse
from .models import Build, Job
        if not last_builds:
            return violation_info
        last_build = last_builds[0]
        build_info = json.loads(last_build.result)

        violation_info = build_info['violation_info']
        if violation_info['violation_num'] >= obj.violation_threshold_num:
            health_url = '/static/img/rain.png'
        else:
            health_url = '/static/img/sun.png'

        violation_info.update({
            'created': build_info['datetime'],
            'health_url': health_url,
            'report_url': settings.JENKINS_URL + '/job/{job_name}/violations/'.format(job_name=obj.name)
        })

        return violation_info

    def get_links(self, obj):
        request = self.context['request']
        return {
            'self': reverse('job-detail', kwargs={'pk': obj.pk}, request=request)
        }


class BuildSerializer(serializers.ModelSerializer):
    links = serializers.SerializerMethodField()

    class Meta:

# Path: src/app/models.py
# class Build(models.Model):
# 
#     class Meta:
#         db_table = 'builds'
# 
#     number = models.IntegerField()
#     job = models.ForeignKey(Job, related_name="builds")
#     created = models.DateTimeField(auto_now_add=True)
#     result = models.TextField(default="")
# 
#     def __str__(self):
#         return "{0}:{1}".format(self.job.name, self.number)
# 
# class Job(models.Model):
# 
#     class Meta:
#         db_table = 'jobs'
# 
#     name = models.CharField(unique=True, max_length=250)
#     description = models.TextField(blank=True, default='')
#     svn_url = models.TextField()
#     svn_username = models.TextField(blank=True, default='')
#     svn_password = models.TextField(blank=True, default='')
# 
#     recipient = models.TextField()
#     violation_threshold_num = models.IntegerField(default=888)
# 
#     def __str__(self):
#         return self.name


# Path: src/app/serializers.py
import json
from datetime import date, datetime
from django.conf import settings
from django.contrib.auth import get_user_model
from rest_framework import serializers
from rest_framework.reverse import reverse
from .models import Build, Job

        if not last_builds:
            return violation_info
        last_build = last_builds[0]
        build_info = json.loads(last_build.result)

        violation_info = build_info['violation_info']
        if violation_info['violation_num'] >= obj.violation_threshold_num:
            health_url = '/static/img/rain.png'
        else:
            health_url = '/static/img/sun.png'

        violation_info.update({
            'created': build_info['datetime'],
            'health_url': health_url,
            'report_url': settings.JENKINS_URL + '/job/{job_name}/violations/'.format(job_name=obj.name)
        })

        return violation_info

    def get_links(self, obj):
        request = self.context['request']
        return {
            'self': reverse('job-detail', kwargs={'pk': obj.pk}, request=request)
        }


class BuildSerializer(serializers.ModelSerializer):
    links = serializers.SerializerMethodField()

    class Meta:

        model = Build