Added a DB consistency check, and 2 new doc.statetype values found by the check for consistency.

- Legacy-Id: 12451
This commit is contained in:
Henrik Levkowetz 2016-12-05 14:12:19 +00:00
parent 8cf6b0010b
commit 1d5a7a692a
2 changed files with 29 additions and 0 deletions

View file

@ -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()

View file

@ -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,