Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

# -*- coding: UTF-8 -*- 

# Copyright 2013-2015 Luc Saffre 

# License: BSD (see file COPYING for details) 

 

"""Database models for `lino.modlib.concepts`. 

 

""" 

 

from __future__ import unicode_literals 

from builtins import object 

 

 

import logging 

logger = logging.getLogger(__name__) 

 

 

from django.db import models 

from django.utils.translation import ugettext_lazy as _ 

 

from lino.api import dd, rt 

 

from lino import mixins 

 

 

class LinkTypes(dd.ChoiceList): 

    verbose_name = _("Link Type") 

    verbose_name_plural = _("Link Types") 

 

add = LinkTypes.add_item 

#~ add('10', _("Context"),'context') 

add('10', _("Jargon"), 'jargon') 

add('20', _("Obsoletes"), 'obsoletes') 

 

 

class Concept(mixins.BabelNamed): 

    """A word and its translation in different languages. 

    """ 

 

    class Meta(object): 

        verbose_name = _("Concept") 

        verbose_name_plural = _("Concepts") 

 

    abbr = dd.BabelCharField(_("Abbreviation"), max_length=30, blank=True) 

    wikipedia = dd.BabelCharField(_("Wikipedia"), max_length=200, blank=True) 

 

    definition = dd.BabelTextField(_("Definition"), blank=True) 

    is_jargon_domain = models.BooleanField( 

        _("Jargon domain"), 

        help_text=_( 

            "Whether this concept designates a domain of specialized vocabulary."), 

        default=False) 

 

    def summary_row(self, ar=None): 

        if self.abbr: 

            return ["%s (%s)" % (dd.babelattr(self, 'name'), dd.babelattr(self, 'abbr'))] 

        return [dd.babelattr(self, 'name')] 

 

 

class Concepts(dd.Table): 

    model = Concept 

    column_names = 'name id abbr' 

    detail_layout = """ 

    name 

    abbr 

    definition 

    wikipedia 

    Parents Children 

    """ 

 

 

class TopLevelConcepts(Concepts): 

    label = _("Top-level concepts") 

    filter = models.Q(is_jargon_domain=True) 

 

 

class Link(dd.Model): 

 

    class Meta(object): 

        verbose_name = _("Link") 

        verbose_name_plural = _("Links") 

 

    type = LinkTypes.field(blank=True, default=LinkTypes.jargon.as_callable) 

    parent = dd.ForeignKey(Concept, related_name="children") 

    child = dd.ForeignKey(Concept, related_name="parents") 

 

    @dd.chooser() 

    def child_choices(cls): 

        return Concept.objects.filter(is_jargon_domain=True) 

 

 

class Links(dd.Table): 

    model = Link 

 

 

class Parents(Links): 

    master_key = 'child' 

    label = _("Parents") 

 

 

class Children(Links): 

    master_key = 'parent' 

    label = _("Children")