Replace category string in instrument type with proper model
This commit is contained in:
parent
d172e9a005
commit
d1c4d63179
|
|
@ -0,0 +1,31 @@
|
||||||
|
# Generated by Django 3.2.13 on 2022-09-08 15:17
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
LANGUAGE_COMMUNICATION = 'language_communication'
|
||||||
|
SOCIETY = 'society'
|
||||||
|
INTERDISCIPLINARY = 'interdisciplinary'
|
||||||
|
|
||||||
|
CATEGORY_CHOICES = (
|
||||||
|
(LANGUAGE_COMMUNICATION, '#DAA009', '#FFF5D9', 'Sprache & Kommunikation'),
|
||||||
|
(SOCIETY, '#0F7CAC', '#DBEEF6', 'Gesellschaft'),
|
||||||
|
(INTERDISCIPLINARY, '#99B53E', '#F3F9E3', 'Überfachliches Instrument'),
|
||||||
|
)
|
||||||
|
|
||||||
|
def create_categories(apps, schema_editor):
|
||||||
|
InstrumentCategory = apps.get_model('basicknowledge', 'InstrumentCategory')
|
||||||
|
InstrumentType = apps.get_model('basicknowledge', 'InstrumentType')
|
||||||
|
for code, foreground, background, category in CATEGORY_CHOICES:
|
||||||
|
instrument_category = InstrumentCategory.objects.create(name=category, background=background, foreground=foreground)
|
||||||
|
InstrumentType.objects.filter(category=code).update(new_category=instrument_category)
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('basicknowledge', '0019_auto_20220913_0820'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(create_categories, migrations.RunPython.noop)
|
||||||
|
]
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
# Generated by Django 3.2.13 on 2022-09-13 08:52
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('basicknowledge', '0020_auto_20220908_1517'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='instrumenttype',
|
||||||
|
name='category',
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 3.2.13 on 2022-09-13 08:52
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('basicknowledge', '0021_remove_instrumenttype_category'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='instrumenttype',
|
||||||
|
old_name='new_category',
|
||||||
|
new_name='category',
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
# Generated by Django 3.2.13 on 2022-09-13 09:01
|
||||||
|
|
||||||
|
import basicknowledge.models
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('basicknowledge', '0022_rename_new_category_instrumenttype_category'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='instrumenttype',
|
||||||
|
name='category',
|
||||||
|
field=models.ForeignKey(default=basicknowledge.models.default_category, on_delete=django.db.models.deletion.PROTECT, to='basicknowledge.instrumentcategory'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -13,6 +13,9 @@ from core.wagtail_utils import StrictHierarchyPage
|
||||||
LANGUAGE_COMMUNICATION = 'language_communication'
|
LANGUAGE_COMMUNICATION = 'language_communication'
|
||||||
SOCIETY = 'society'
|
SOCIETY = 'society'
|
||||||
INTERDISCIPLINARY = 'interdisciplinary'
|
INTERDISCIPLINARY = 'interdisciplinary'
|
||||||
|
LANGUAGE_COMMUNICATION_LABEL = 'Sprache & Kommunikation'
|
||||||
|
SOCIETY_LABEL = 'Gesellschaft'
|
||||||
|
INTERDISCIPLINARY_LABEL = 'Überfachliche Instrumente'
|
||||||
|
|
||||||
|
|
||||||
class InstrumentCategory(models.Model):
|
class InstrumentCategory(models.Model):
|
||||||
|
|
@ -27,23 +30,22 @@ class InstrumentCategory(models.Model):
|
||||||
verbose_name_plural = 'instrument categories'
|
verbose_name_plural = 'instrument categories'
|
||||||
|
|
||||||
|
|
||||||
|
def default_category():
|
||||||
|
return InstrumentCategory.objects.first().pk
|
||||||
|
|
||||||
class InstrumentType(models.Model):
|
class InstrumentType(models.Model):
|
||||||
CATEGORY_CHOICES = (
|
CATEGORY_CHOICES = (
|
||||||
(LANGUAGE_COMMUNICATION, 'Sprache & Kommunikation'),
|
(LANGUAGE_COMMUNICATION, LANGUAGE_COMMUNICATION_LABEL),
|
||||||
(SOCIETY, 'Gesellschaft'),
|
(SOCIETY, SOCIETY_LABEL),
|
||||||
(INTERDISCIPLINARY, 'Überfachliches Instrument'),
|
(INTERDISCIPLINARY, INTERDISCIPLINARY_LABEL),
|
||||||
)
|
)
|
||||||
|
|
||||||
name = models.CharField(max_length=255, unique=True)
|
name = models.CharField(max_length=255, unique=True)
|
||||||
category = models.CharField(
|
category = models.ForeignKey(
|
||||||
max_length=100,
|
|
||||||
choices=CATEGORY_CHOICES
|
|
||||||
)
|
|
||||||
new_category = models.ForeignKey(
|
|
||||||
InstrumentCategory,
|
InstrumentCategory,
|
||||||
on_delete=models.PROTECT,
|
on_delete=models.PROTECT,
|
||||||
null=True,
|
null=False,
|
||||||
default=None
|
default=default_category
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,18 @@ from api.graphene_wagtail import GenericStreamFieldType
|
||||||
from api.utils import get_object
|
from api.utils import get_object
|
||||||
from notes.models import InstrumentBookmark
|
from notes.models import InstrumentBookmark
|
||||||
from notes.schema import InstrumentBookmarkNode
|
from notes.schema import InstrumentBookmarkNode
|
||||||
from .models import BasicKnowledge, InstrumentType
|
from .models import BasicKnowledge, InstrumentCategory, InstrumentType
|
||||||
|
|
||||||
|
class InstrumentCategoryNode(DjangoObjectType):
|
||||||
|
class Meta:
|
||||||
|
model = InstrumentCategory
|
||||||
|
only_fields = [
|
||||||
|
'name', 'foreground', 'background', 'id'
|
||||||
|
]
|
||||||
|
|
||||||
class InstrumentTypeNode(DjangoObjectType):
|
class InstrumentTypeNode(DjangoObjectType):
|
||||||
type = graphene.String(required=True)
|
type = graphene.String(required=True)
|
||||||
|
category = graphene.Field(InstrumentCategoryNode)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = InstrumentType
|
model = InstrumentType
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,12 @@ query InstrumentTypesQuery {
|
||||||
instrumentTypes {
|
instrumentTypes {
|
||||||
name
|
name
|
||||||
type
|
type
|
||||||
category
|
category {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
foreground
|
||||||
|
background
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
from wagtail.contrib.modeladmin.options import ModelAdmin, modeladmin_register
|
from wagtail.contrib.modeladmin.options import ModelAdmin, modeladmin_register
|
||||||
from .models import BasicKnowledge
|
from .models import BasicKnowledge, InstrumentCategory, InstrumentType
|
||||||
|
|
||||||
|
|
||||||
class InstrumentAdmin(ModelAdmin):
|
class InstrumentAdmin(ModelAdmin):
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,9 @@ from wagtail.core.models import Page, Site
|
||||||
from wagtail.core.rich_text import RichText
|
from wagtail.core.rich_text import RichText
|
||||||
|
|
||||||
from assignments.models import Assignment
|
from assignments.models import Assignment
|
||||||
from basicknowledge.models import BasicKnowledge, INTERDISCIPLINARY, InstrumentCategory, InstrumentType, \
|
from basicknowledge.models import BasicKnowledge, INTERDISCIPLINARY, INTERDISCIPLINARY_LABEL, InstrumentCategory, \
|
||||||
LANGUAGE_COMMUNICATION, SOCIETY
|
InstrumentType, \
|
||||||
|
LANGUAGE_COMMUNICATION, LANGUAGE_COMMUNICATION_LABEL, SOCIETY, SOCIETY_LABEL
|
||||||
from books.blocks import AssignmentBlock, BasicKnowledgeBlock, ImageUrlBlock, LinkBlock, VideoBlock
|
from books.blocks import AssignmentBlock, BasicKnowledgeBlock, ImageUrlBlock, LinkBlock, VideoBlock
|
||||||
from books.models import Book, Chapter, ContentBlock, Module, TextBlock, Topic
|
from books.models import Book, Chapter, ContentBlock, Module, TextBlock, Topic
|
||||||
from core.factories import BasePageFactory, DummyImageFactory, fake, fake_paragraph, fake_title
|
from core.factories import BasePageFactory, DummyImageFactory, fake, fake_paragraph, fake_title
|
||||||
|
|
@ -76,7 +77,7 @@ class InstrumentCategoryFactory(factory.DjangoModelFactory):
|
||||||
model = InstrumentCategory
|
model = InstrumentCategory
|
||||||
django_get_or_create = ('name',)
|
django_get_or_create = ('name',)
|
||||||
|
|
||||||
name = factory.Iterator([LANGUAGE_COMMUNICATION, SOCIETY, INTERDISCIPLINARY])
|
name = factory.Iterator([LANGUAGE_COMMUNICATION_LABEL, SOCIETY_LABEL, INTERDISCIPLINARY_LABEL])
|
||||||
foreground = factory.Iterator(['FF0000', 'FFFFFF', '000000'])
|
foreground = factory.Iterator(['FF0000', 'FFFFFF', '000000'])
|
||||||
background = factory.Iterator(['FF0000', 'FFFFFF', '000000'])
|
background = factory.Iterator(['FF0000', 'FFFFFF', '000000'])
|
||||||
|
|
||||||
|
|
@ -84,7 +85,7 @@ class InstrumentTypeFactory(factory.DjangoModelFactory):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = InstrumentType
|
model = InstrumentType
|
||||||
|
|
||||||
category = factory.Iterator([LANGUAGE_COMMUNICATION, SOCIETY, INTERDISCIPLINARY])
|
category = factory.SubFactory(InstrumentCategoryFactory)
|
||||||
name = factory.LazyAttribute(lambda x: fake.text(max_nb_chars=20))
|
name = factory.LazyAttribute(lambda x: fake.text(max_nb_chars=20))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -538,16 +538,10 @@ type InstrumentNodeEdge {
|
||||||
cursor: String!
|
cursor: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
enum InstrumentTypeCategory {
|
|
||||||
LANGUAGE_COMMUNICATION
|
|
||||||
SOCIETY
|
|
||||||
INTERDISCIPLINARY
|
|
||||||
}
|
|
||||||
|
|
||||||
type InstrumentTypeNode {
|
type InstrumentTypeNode {
|
||||||
id: ID!
|
id: ID!
|
||||||
name: String!
|
name: String!
|
||||||
category: InstrumentTypeCategory!
|
category: InstrumentCategoryNode
|
||||||
type: String!
|
type: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue