basicModule.py 1.14 KB
Newer Older
1
from django.db import models
2
3
from backend.models.abstract.my_model import MyModelVersionned, MyModelVersionnedSerializer, MyModelVersionnedViewSet
from backend.fields import JSONField
4
5
from backend.validators.tag import validate_content_against_config
from backend.validators.tag.tags_config import USEFULL_LINKS_CONFIG
6

7
8
9
10
11
12
IMPORTANCE_LEVEL = (
    ('-', 'normal'),
    ('+', 'important'),
    ('++', 'IMPORTANT')
)

13

14
class BasicModule(MyModelVersionned):
15

16
    comment = models.TextField(blank=True)
Florent Chehab's avatar
Florent Chehab committed
17
    usefull_links = JSONField(default=list)
18
19
20
21
22
    importance_level = models.CharField(
        max_length=2,
        choices=IMPORTANCE_LEVEL,
        default='-',
    )
23

24
25
    class Meta:
        abstract = True
Florent Chehab's avatar
Florent Chehab committed
26
27


28
class BasicModuleSerializer(MyModelVersionnedSerializer):
Florent Chehab's avatar
Florent Chehab committed
29

Florent Chehab's avatar
Florent Chehab committed
30
    def my_validate(self, attrs):
31
        content = {'usefull_links': attrs['usefull_links']}
Florent Chehab's avatar
Florent Chehab committed
32
        config = {'usefull_links': USEFULL_LINKS_CONFIG}
33
34
35
        validate_content_against_config(config, content)
        return attrs

Florent Chehab's avatar
Florent Chehab committed
36
37
    class Meta:
        model = BasicModule
38
        fields = '__all__'
39
40
41
42


class BasicModuleViewSet(MyModelVersionnedViewSet):
    serializer_class = BasicModuleSerializer