diff --git a/ietf/doc/models.py b/ietf/doc/models.py index 083742ba5..499874bd5 100644 --- a/ietf/doc/models.py +++ b/ietf/doc/models.py @@ -3,6 +3,7 @@ import datetime, os from django.db import models +from django.core import checks from django.core.exceptions import ValidationError from django.core.urlresolvers import reverse as urlreverse from django.core.validators import URLValidator @@ -26,6 +27,20 @@ class StateType(models.Model): def __unicode__(self): return self.slug +@checks.register('db-consistency') +def check_statetype_slugs(app_configs, **kwargs): + errors = [] + state_type_slugs = [ t.slug for t in StateType.objects.all() ] + for type in DocTypeName.objects.all(): + if not type.slug in state_type_slugs: + errors.append(checks.Error( + "The document type '%s (%s)' does not have a corresponding entry in the doc.StateType table" % (type.name, type.slug), + hint="You should add a doc.StateType entry with a slug '%s' to match the DocTypeName slug."%(type.slug), + obj=type, + id='datatracker.doc.E0015', + )) + return errors + class State(models.Model): type = models.ForeignKey(StateType) slug = models.SlugField() diff --git a/ietf/name/fixtures/names.json b/ietf/name/fixtures/names.json index 255631d25..4f92fd7e2 100644 --- a/ietf/name/fixtures/names.json +++ b/ietf/name/fixtures/names.json @@ -2728,6 +2728,20 @@ "model": "doc.statetype", "pk": "review" }, +{ + "fields": { + "label": "Shepherd's writeup state" + }, + "model": "doc.statetype", + "pk": "shepwrit" +}, +{ + "fields": { + "label": "Liaison state" + }, + "model": "doc.statetype", + "pk": "liaison" +}, { "fields": { "used": true,