-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add CheckoutsSerializer and TreeSerializer
- Loading branch information
1 parent
3414bea
commit 866fb07
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from rest_framework import serializers | ||
from kernelCI_app.models import Checkouts | ||
from kernelCI_app.utils import get_visible_record_config | ||
|
||
|
||
class CheckoutsSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Checkouts | ||
fields = [ | ||
'field_timestamp', 'id', 'origin', 'tree_name', | ||
'git_repository_url', 'git_commit_hash', 'git_commit_name', | ||
'git_repository_branch', 'patchset_files', 'patchset_hash', | ||
'message_id', 'comment', 'start_time', 'contacts', | ||
'log_url', 'log_excerpt', 'valid', 'misc' | ||
] | ||
|
||
|
||
class TreeSerializer(CheckoutsSerializer): | ||
build_status = serializers.SerializerMethodField(method_name="get_build_status") | ||
test_status = serializers.SerializerMethodField(method_name="get_test_status") | ||
|
||
def get_config(self, obj): | ||
return get_visible_record_config('checkouts', obj.id) | ||
|
||
def get_build_status(self, obj): | ||
config = self.get_config(obj) | ||
return config.get('build_status') | ||
|
||
def get_test_status(self, obj): | ||
config = self.get_config(obj) | ||
return config.get('test_status') | ||
|
||
class Meta(CheckoutsSerializer.Meta): | ||
fields = CheckoutsSerializer.Meta.fields + ['build_status', 'test_status'] |