-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcontent.py
44 lines (38 loc) · 1.69 KB
/
content.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
"""
Content resource for API endpoint
"""
from tastypie import fields
from tastypie.resources import ModelResource, ALL_WITH_RELATIONS
from app.models import Content
#from api.grammar import GrammarResource
from api.language import LanguageResource
from api.shallow_content import ShallowContentResource
import markdown
class ContentResource(ModelResource):
source_lang = fields.ForeignKey(LanguageResource,
'source_lang',
null=True,
blank=True,
full=True)
target_lang = fields.ForeignKey(LanguageResource,
'target_lang',
null=True,
blank=True,
full=True)
grammar_ref = fields.ToOneField('api.grammar.GrammarResource',
'grammar_ref',
null=True,
blank=True)
# This is to prevent infinite recursive includes
related_content = fields.ManyToManyField(ShallowContentResource,
'related_content',
null=True,
blank=True,
full=True)
class Meta:
queryset = Content.objects.all()
allowed_methods = ['get']
filtering = { 'source_lang': ALL_WITH_RELATIONS }
def dehydrate_content(self, bundle):
return markdown.markdown(bundle.data['content'],
['markdown.extensions.tables', 'markdown.extensions.attr_list'])