-
Notifications
You must be signed in to change notification settings - Fork 27
/
documents.py
69 lines (55 loc) · 2.2 KB
/
documents.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from django_elasticsearch_dsl import Document, fields
from django_elasticsearch_dsl.registries import registry
from pydash import get
from core.common.utils import jsonify_safe
from core.sources.models import Source
@registry.register_document
class SourceDocument(Document):
class Index:
name = 'sources'
settings = {'number_of_shards': 1, 'number_of_replicas': 0}
locale = fields.ListField(fields.KeywordField())
last_update = fields.DateField(attr='updated_at')
owner = fields.KeywordField(attr='parent_resource', normalizer='lowercase')
owner_type = fields.KeywordField(attr='parent_resource_type')
public_can_view = fields.TextField(attr='public_can_view')
source_type = fields.KeywordField(attr='source_type', normalizer='lowercase')
is_active = fields.KeywordField(attr='is_active')
version = fields.KeywordField(attr='version')
name = fields.KeywordField(attr='name', normalizer='lowercase')
canonical_url = fields.KeywordField(attr='canonical_url', normalizer='lowercase')
mnemonic = fields.KeywordField(attr='mnemonic', normalizer='lowercase')
extras = fields.ObjectField()
identifier = fields.ObjectField()
jurisdiction = fields.ObjectField()
publisher = fields.KeywordField(attr='publisher', normalizer='lowercase')
content_type = fields.KeywordField(attr='content_type', normalizer='lowercase')
class Django:
model = Source
fields = [
'full_name',
'custom_validation_schema',
'revision_date',
'retired',
]
@staticmethod
def prepare_locale(instance):
return get(instance.supported_locales, [])
@staticmethod
def prepare_extras(instance):
value = {}
if instance.extras:
value = jsonify_safe(instance.extras)
return value or {}
@staticmethod
def prepare_identifier(instance):
value = {}
if instance.identifier:
value = jsonify_safe(instance.identifier)
return value or {}
@staticmethod
def prepare_jurisdiction(instance):
value = {}
if instance.jurisdiction:
value = jsonify_safe(instance.jurisdiction)
return value or {}