aboutsummaryrefslogtreecommitdiff
path: root/testmanager/api/serializers.py
blob: a231cbb8f9c665aed1b88017cb89176e2d4f7811 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Copyright (C) 2014 Linaro Limited
#
# Author: Milosz Wasilewski <milosz.wasilewski@linaro.org>
#
# This file is part of Testmanager.
#
# Testmanager is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License version 3
# as published by the Free Software Foundation
#
# Testmanager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Testmanager.  If not, see <http://www.gnu.org/licenses/>.

from django.db.models import Max
from rest_framework import serializers
from testmanager.buildtestresults import models
from taggit_serializer.serializers import (
    TagListSerializerField,
    TaggitSerializer)
from taggit.models import Tag

class LastBuildNumberField(serializers.Field):
    def to_representation(self, value):
        print "here"
        return value.aggregate(Max('number'))["number__max"]


class BuildSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Build


class TestSuiteSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.TestSuite


class TestSuiteCommentSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.TestSuiteComment


class TestmanagerTagSerializer(serializers.ModelSerializer, TaggitSerializer):
    class Meta:
        model = Tag
        #fields = ('name',)


class ProjectConfigSerializer(serializers.ModelSerializer, TaggitSerializer):
    last_build_number = serializers.IntegerField(
        read_only=True
    )
    last_build_status = serializers.CharField(
        read_only=True
    )
    last_build_timestamp = serializers.DateTimeField(
        read_only=True
    )
    last_boot_status = serializers.CharField(
        read_only=True
    )
    last_test_status = serializers.CharField(
        read_only=True
    )
    # for some reason TagListSerializer doesn't work in django 1.6
    #tags = TagListSerializerField()
    class Meta:
        model = models.ProjectConfig