From: Stephen Finucane Date: Mon, 29 Jun 2015 20:38:18 +0000 (+0100) Subject: models: Add 'check' model X-Git-Tag: v1.1.0~132 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fc708e1db1274f030004fbe4f395c55c4c29a5bf;p=thirdparty%2Fpatchwork.git models: Add 'check' model This will represent the status of tests executed (or executing) against a patch. This includes a suitable migration and admin view. Signed-off-by: Stephen Finucane -- v3: Remove manual SQL migrations - they're not necessary/possible for Django 1.7/1.8, respectively --- diff --git a/patchwork/admin.py b/patchwork/admin.py index 04a8ff8f..d32edbab 100644 --- a/patchwork/admin.py +++ b/patchwork/admin.py @@ -20,7 +20,7 @@ from django.contrib import admin from patchwork.models import ( - Project, Person, UserProfile, State, Patch, Comment, Bundle, Tag) + Project, Person, UserProfile, State, Patch, Comment, Bundle, Tag, Check) class ProjectAdmin(admin.ModelAdmin): @@ -74,6 +74,15 @@ class CommentAdmin(admin.ModelAdmin): admin.site.register(Comment, CommentAdmin) +class CheckAdmin(admin.ModelAdmin): + list_display = ('patch', 'user', 'state', 'target_url', + 'description', 'context') + exclude = ('date', ) + search_fields = ('patch__name', 'project__name') + date_hierarchy = 'date' +admin.site.register(Check, CheckAdmin) + + class BundleAdmin(admin.ModelAdmin): list_display = ('name', 'owner', 'project', 'public') list_filter = ('public', 'project') diff --git a/patchwork/migrations/0003_add_check_model.py b/patchwork/migrations/0003_add_check_model.py new file mode 100644 index 00000000..50bd72b2 --- /dev/null +++ b/patchwork/migrations/0003_add_check_model.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations +import datetime +from django.conf import settings + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('patchwork', '0002_fix_patch_state_default_values'), + ] + + operations = [ + migrations.CreateModel( + name='Check', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('date', models.DateTimeField(default=datetime.datetime.now)), + ('state', models.SmallIntegerField(default=0, help_text=b'The state of the check.', choices=[(0, b'pending'), (1, b'success'), (2, b'warning'), (3, b'fail')])), + ('target_url', models.URLField(help_text=b'The target URL to associate with this check. This should be specific to the patch.', null=True, blank=True)), + ('description', models.TextField(help_text=b'A brief description of the check.', null=True, blank=True)), + ('context', models.CharField(default=b'default', max_length=255, null=True, help_text=b'A label to discern check from checks of other testing systems.', blank=True)), + ('patch', models.ForeignKey(to='patchwork.Patch')), + ('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)), + ], + options={ + }, + bases=(models.Model,), + ), + ] diff --git a/patchwork/models.py b/patchwork/models.py index d0b34477..80f1eff0 100644 --- a/patchwork/models.py +++ b/patchwork/models.py @@ -1,5 +1,6 @@ # Patchwork - automated patch tracking system # Copyright (C) 2008 Jeremy Kerr +# Copyright (C) 2015 Intel Corporation # # This file is part of the Patchwork package. # @@ -430,6 +431,50 @@ class BundlePatch(models.Model): ordering = ['order'] +class Check(models.Model): + """Check for a patch. + + Checks store the results of any tests executed (or executing) for a + given patch. This is useful, for example, when using a continuous + integration (CI) system to test patches. + """ + STATE_PENDING = 0 + STATE_SUCCESS = 1 + STATE_WARNING = 2 + STATE_FAIL = 3 + STATE_CHOICES = ( + (STATE_PENDING, 'pending'), + (STATE_SUCCESS, 'success'), + (STATE_WARNING, 'warning'), + (STATE_FAIL, 'fail'), + ) + + patch = models.ForeignKey(Patch) + user = models.ForeignKey(User) + date = models.DateTimeField(default=datetime.datetime.now) + + state = models.SmallIntegerField( + choices=STATE_CHOICES, default=STATE_PENDING, + help_text='The state of the check.') + target_url = models.URLField( + blank=True, null=True, + help_text='The target URL to associate with this check. This should' + ' be specific to the patch.') + description = models.TextField( + blank=True, null=True, help_text='A brief description of the check.') + context = models.CharField( + max_length=255, default='default', blank=True, null=True, + help_text='A label to discern check from checks of other testing ' + 'systems.') + + def __repr__(self): + return "