basicModule.py 1.23 KB
Newer Older
1
from django.db import models
2 3 4 5 6
from backend_app.models.abstract.my_model import (
    MyModelVersionned,
    MyModelVersionnedSerializer,
    MyModelVersionnedViewSet,
)
Florent Chehab's avatar
Florent Chehab committed
7 8 9
from backend_app.fields import JSONField
from backend_app.validators.tag import validate_content_against_config
from backend_app.validators.tag.tags_config import USEFULL_LINKS_CONFIG
10

11
IMPORTANCE_LEVEL = (("-", "normal"), ("+", "important"), ("++", "IMPORTANT"))
12

13

14
class BasicModule(MyModelVersionned):
15 16
    title = models.CharField(default="", blank=True, max_length=150)
    comment = models.CharField(default="", blank=True, max_length=5000)
Florent Chehab's avatar
Florent Chehab committed
17
    useful_links = JSONField(default=list)
18
    importance_level = models.CharField(
19
        max_length=2, choices=IMPORTANCE_LEVEL, default="-"
20
    )
21

22 23
    class Meta:
        abstract = True
Florent Chehab's avatar
Florent Chehab committed
24 25


26
class BasicModuleSerializer(MyModelVersionnedSerializer):
Florent Chehab's avatar
Florent Chehab committed
27
    def my_validate(self, attrs):
28 29
        content = {"useful_links": attrs["useful_links"]}
        config = {"useful_links": USEFULL_LINKS_CONFIG}
30 31 32
        validate_content_against_config(config, content)
        return attrs

Florent Chehab's avatar
Florent Chehab committed
33 34
    class Meta:
        model = BasicModule
35
        fields = "__all__"
36 37 38 39


class BasicModuleViewSet(MyModelVersionnedViewSet):
    serializer_class = BasicModuleSerializer