Skip to content
Snippets Groups Projects
Commit 0ea37516 authored by Tanner Prestegard's avatar Tanner Prestegard Committed by GraceDB
Browse files

Add 'protected' column to labels and apply it

Add a boolean column called 'protected' to the Label model.
Protected labels will not be allowed to be directly applied, but
will be applied as a part of another process (like signoffs).
We also create a data migration which sets some existing labels
as protected (ADV(OK|NO), (H1|L1|V1)(OK|NO))
parent 9ce6807a
No related branches found
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
# Generated by Django 1.11.16 on 2018-10-08 17:42
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('events', '0026_increase_channel_maxlength'),
]
operations = [
migrations.AddField(
model_name='label',
name='protected',
field=models.BooleanField(default=False),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.16 on 2018-10-08 17:43
from __future__ import unicode_literals
from django.db import migrations
PROTECTED_LABELS = [
'H1OK',
'H1NO',
'L1OK',
'L1NO',
'V1OK',
'V1NO',
'ADVOK',
'ADVNO',
]
def protect_labels(apps, schema_editor):
Label = apps.get_model('events', 'Label')
for label in PROTECTED_LABELS:
l = Label.objects.get(name=label)
l.protected = True
l.save(update_fields=['protected'])
def unprotect_labels(apps, schema_editor):
Label = apps.get_model('events', 'Label')
for label in PROTECTED_LABELS:
l = Label.objects.get(name=label)
l.protected = False
l.save(update_fields=['protected'])
class Migration(migrations.Migration):
dependencies = [
('events', '0027_label_protected'),
]
operations = [
migrations.RunPython(protect_labels, unprotect_labels),
]
......@@ -89,6 +89,11 @@ class Label(models.Model):
defaultColor = models.CharField(max_length=20, unique=False,
default="black")
description = models.TextField(blank=False)
# protected = True means that the Label should not be "writeable": i.e.,
# users should not be apply to directly apply or remove it. This is useful
# for labels that are added and removed as part of a process, like
# signoffs, for examples.
protected = models.BooleanField(default=False)
def __unicode__(self):
return self.name
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment