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

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

# Copyright 2013-2015 Luc Saffre 

# License: BSD (see file COPYING for details) 

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

 

""" 

 

import logging 

logger = logging.getLogger(__name__) 

 

try: 

    import bleach 

except ImportError: 

    bleach = None 

 

from django.utils.translation import ugettext_lazy as _ 

from django.contrib.humanize.templatetags.humanize import naturaltime 

 

from lino.api import dd 

from lino.modlib.users.mixins import ByUser 

from lino.utils.xmlgen.html import E 

 

 

class Comments(dd.Table): 

    required_roles = dd.required(dd.SiteStaff) 

    slave_grid_format = "summary" 

 

    model = 'comments.Comment' 

 

    insert_layout = dd.FormLayout(""" 

    short_text 

    """, window_size=(40, 10)) 

 

    detail_layout = """ 

    id user created modified owner 

    short_text 

    more_text 

    """ 

 

    #~ column_names = "id date user type event_type subject * body_html" 

    #~ column_names = "id date user event_type type project subject * body" 

    #~ hide_columns = "body" 

    #~ hidden_columns = frozenset(['body']) 

    #~ order_by = ["id"] 

    #~ label = _("Notes") 

 

 

class MyComments(ByUser, Comments): 

    required_roles = dd.required() 

    auto_fit_column_widths = True 

    order_by = ["created"] 

 

 

class CommentsByX(Comments): 

    required_roles = dd.required() 

    order_by = ["-created"] 

 

USE_ETREE = False 

 

 

class CommentsByRFC(CommentsByX): 

    """Shows the comments for a given database object. 

 

    .. attribute:: slave_summary 

 

         

    """ 

    master_key = 'owner' 

    column_names = "short_text created user *" 

    stay_in_grid = True 

 

    @classmethod 

    def get_slave_summary(self, obj, ar): 

        """The :meth:`summary view <lino.core.actors.Actor.get_slave_summary>` 

        for :class:`CommentsByRFC`. 

 

        """ 

        sar = self.request_from(ar, master_instance=obj) 

 

        html = obj.get_rfc_description(ar) 

        sar = self.insert_action.request_from(sar) 

        if sar.get_permission(): 

            btn = sar.ar2button(None, _("Write comment"), icon_name=None) 

            html += "<p>" + E.tostring(btn) + "</p>" 

 

        items = [o.as_li(ar) for o in sar] 

        if len(items) > 0: 

            html += u"<ul>{0}</ul>".format(''.join(items)) 

 

        return u"""<div class="htmlText">{0}</div>""".format(html) 

 

 

def comments_by_owner(obj): 

    return CommentsByRFC.request(master_instance=obj)