From: Stephen Finucane <stephenfinuc...@hotmail.com> This will represent the status of a patch. This includes a suitable migration and admin view.
Signed-off-by: Stephen Finucane <stephenfinuc...@hotmail.com> --- lib/sql/grant-all.mysql.sql | 5 +-- lib/sql/grant-all.postgres.sql | 11 ++++--- lib/sql/migration/016-add-status-model.sql | 6 ++++ patchwork/admin.py | 11 ++++++- patchwork/migrations/0003_add_status_model.py | 33 +++++++++++++++++++ patchwork/models.py | 46 +++++++++++++++++++++++++++ 6 files changed, 105 insertions(+), 7 deletions(-) create mode 100644 lib/sql/migration/016-add-status-model.sql create mode 100644 patchwork/migrations/0003_add_status_model.py diff --git a/lib/sql/grant-all.mysql.sql b/lib/sql/grant-all.mysql.sql index 6a3d547..ab65457 100644 --- a/lib/sql/grant-all.mysql.sql +++ b/lib/sql/grant-all.mysql.sql @@ -25,15 +25,16 @@ GRANT SELECT, UPDATE, INSERT, DELETE ON patchwork_emailoptout TO 'www-data'@loca GRANT SELECT, UPDATE, INSERT, DELETE ON patchwork_patchchangenotification TO 'www-data'@localhost; GRANT SELECT, UPDATE, INSERT, DELETE ON patchwork_tag TO 'www-data'@localhost; GRANT SELECT, UPDATE, INSERT, DELETE ON patchwork_patchtag TO 'www-data'@localhost; +GRANT SELECT, UPDATE, INSERT, DELETE ON patchwork_status TO 'www-data'@localhost; --- allow the mail user (in this case, 'nobody') to add patches +-- allow the mail user (in this case, 'nobody') to add patches and statuses GRANT INSERT, SELECT ON patchwork_patch TO 'nobody'@localhost; GRANT INSERT, SELECT ON patchwork_comment TO 'nobody'@localhost; GRANT INSERT, SELECT ON patchwork_person TO 'nobody'@localhost; +GRANT INSERT, SELECT ON patchwork_status TO 'nobody'@localhost; GRANT INSERT, SELECT, UPDATE, DELETE ON patchwork_patchtag TO 'nobody'@localhost; GRANT SELECT ON patchwork_project TO 'nobody'@localhost; GRANT SELECT ON patchwork_state TO 'nobody'@localhost; GRANT SELECT ON patchwork_tag TO 'nobody'@localhost; COMMIT; - diff --git a/lib/sql/grant-all.postgres.sql b/lib/sql/grant-all.postgres.sql index 477e10a..204eca0 100644 --- a/lib/sql/grant-all.postgres.sql +++ b/lib/sql/grant-all.postgres.sql @@ -25,7 +25,8 @@ GRANT SELECT, UPDATE, INSERT, DELETE ON patchwork_emailoptout, patchwork_patchchangenotification, patchwork_tag, - patchwork_patchtag + patchwork_patchtag, + patchwork_status TO "www-data"; GRANT SELECT, UPDATE ON auth_group_id_seq, @@ -49,13 +50,15 @@ GRANT SELECT, UPDATE ON patchwork_userprofile_maintainer_projects_id_seq, patchwork_tag_id_seq, patchwork_patchtag_id_seq + patchwork_status_id_seq TO "www-data"; -- allow the mail user (in this case, 'nobody') to add patches GRANT INSERT, SELECT ON patchwork_patch, patchwork_comment, - patchwork_person + patchwork_person, + patchwork_status TO "nobody"; GRANT INSERT, SELECT, UPDATE, DELETE ON patchwork_patchtag @@ -69,8 +72,8 @@ GRANT UPDATE, SELECT ON patchwork_patch_id_seq, patchwork_person_id_seq, patchwork_comment_id_seq, - patchwork_patchtag_id_seq + patchwork_patchtag_id_seq, + patchwork_status_id_seq TO "nobody"; COMMIT; - diff --git a/lib/sql/migration/016-add-status-model.sql b/lib/sql/migration/016-add-status-model.sql new file mode 100644 index 0000000..aa116c6 --- /dev/null +++ b/lib/sql/migration/016-add-status-model.sql @@ -0,0 +1,6 @@ +BEGIN; +CREATE TABLE `patchwork_status` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `date` datetime NOT NULL, `state` smallint NOT NULL, `target_url` varchar(200) NULL, `description` longtext NULL, `context` varchar(255) NULL, `patch_id` integer NOT NULL, `user_id` integer NOT NULL); +ALTER TABLE `patchwork_status` ADD CONSTRAINT `patchwork_status_patch_id_32968640b7a49ecf_fk_patchwork_patch_id` FOREIGN KEY (`patch_id`) REFERENCES `patchwork_patch` (`id`); +ALTER TABLE `patchwork_status` ADD CONSTRAINT `patchwork_status_user_id_72be31b021e2a9db_fk_auth_user_id` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`); + +COMMIT; diff --git a/patchwork/admin.py b/patchwork/admin.py index 04a8ff8..749e358 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, Status) class ProjectAdmin(admin.ModelAdmin): @@ -74,6 +74,15 @@ class CommentAdmin(admin.ModelAdmin): admin.site.register(Comment, CommentAdmin) +class StatusAdmin(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(Status, StatusAdmin) + + class BundleAdmin(admin.ModelAdmin): list_display = ('name', 'owner', 'project', 'public') list_filter = ('public', 'project') diff --git a/patchwork/migrations/0003_add_status_model.py b/patchwork/migrations/0003_add_status_model.py new file mode 100644 index 0000000..2659210 --- /dev/null +++ b/patchwork/migrations/0003_add_status_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='Status', + 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 status.', 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 status. This should be specific to the patch.', null=True, blank=True)), + ('description', models.TextField(help_text=b'A brief description of the status.', null=True, blank=True)), + ('context', models.CharField(default=b'default', max_length=255, null=True, help_text=b'A label to discern status from statuses of other systems.', blank=True)), + ('patch', models.ForeignKey(to='patchwork.Patch')), + ('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)), + ], + options={ + 'verbose_name_plural': 'statuses', + }, + ), + ] diff --git a/patchwork/models.py b/patchwork/models.py index eb9a700..ef5f13c 100644 --- a/patchwork/models.py +++ b/patchwork/models.py @@ -1,5 +1,6 @@ # Patchwork - automated patch tracking system # Copyright (C) 2008 Jeremy Kerr <j...@ozlabs.org> +# Copyright (C) 2015 Intel Corporation # # This file is part of the Patchwork package. # @@ -414,6 +415,51 @@ class BundlePatch(models.Model): ordering = ['order'] +class Status(models.Model): + """Status for a patch. + + Statuses define a state for patches. 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 status.') + target_url = models.URLField( + blank=True, null=True, + help_text='The target URL to associate with this status. This should' + ' be specific to the patch.') + description = models.TextField( + blank=True, null=True, help_text='A brief description of the status.') + context = models.CharField( + max_length=255, default='default', blank=True, null=True, + help_text='A label to discern status from statuses of other systems.') + + def __repr__(self): + return "<Status id='%d' context='%s' state='%s'" % ( + self.id, self.context, self.get_state_display()) + + def __unicode__(self): + return ('%s (%s)' % (self.context, self.get_state_display())) + + class Meta: + verbose_name_plural = 'statuses' + + class EmailConfirmation(models.Model): validity = datetime.timedelta(days=settings.CONFIRMATION_VALIDITY_DAYS) type = models.CharField(max_length=20, choices=[ -- 2.0.0 _______________________________________________ Patchwork mailing list Patchwork@lists.ozlabs.org https://lists.ozlabs.org/listinfo/patchwork