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#!/usr/local/bin/python 

2# encoding: utf-8 

3""" 

4*The comments block for the comments tab of the PESSTO Marshall object ticket* 

5 

6:Author: 

7 David Young 

8""" 

9import sys 

10import os 

11import re 

12import datetime 

13import khufu 

14from fundamentals import times 

15 

16 

17def comments_block( 

18 log, 

19 request, 

20 discoveryDataDictionary, 

21 objectComments 

22): 

23 """comments_block 

24 

25 **Key Arguments** 

26 

27 - ``log`` -- the logger 

28 - ``request`` -- the pyramid request 

29 - ``discoveryDataDictionary`` -- a dictionary of the discovery data for this transient. 

30 - ``objectComments`` -- the comments for the object 

31 

32 

33 **Return** 

34 

35 - ``commentBlock`` -- the comments block for the transient ticket in the transient listings pages 

36 

37 """ 

38 commentBlock = "" 

39 count = 0 

40 

41 for row in objectComments: 

42 if row["pesstoObjectsId"] != discoveryDataDictionary["transientBucketId"]: 

43 continue 

44 count += 1 

45 # AUTHOR 

46 author = row["commentAuthor"].replace(".", " ").replace( 

47 "_", " ").title().replace("Atel", "ATel") 

48 

49 author = khufu.coloredText( 

50 text="""%(author)s: """ % locals(), 

51 color="red", 

52 size=False, # 1-10 

53 pull=False, # "left" | "right" 

54 ) 

55 

56 # COMMENT 

57 comment = row["comment"].replace("<", "&lt;").replace("&lt;a", "<a").replace( 

58 "&gt;ATEL", ">ATEL").replace("&lt;/a&gt;", "</a>").replace("&lt;/a", "</a").replace("&quot;", '"').replace("&gt;", ">").replace('href=http', 'href="http') 

59 regex = re.compile(r'(href\=\"http[\w\d\.~/:?=]*?)\>', re.S) 

60 comment = regex.sub('\g<1>">', comment) 

61 

62 # print comment 

63 comment = khufu.coloredText( 

64 text=comment, 

65 color="grey", 

66 size=False, # 1-10 

67 pull=False, # "left" | "right" 

68 ) 

69 

70 # DATE 

71 from datetime import datetime, date, time 

72 now = datetime.now() 

73 delta = now - row["dateCreated"] 

74 delta = delta.days 

75 if (delta < 13): 

76 

77 thisDate = times.datetime_relative_to_now(row["dateCreated"]) 

78 if thisDate[-1:] == "d": 

79 thisDate = thisDate[2:-1] 

80 thisDate = """%(thisDate)s days ago""" % locals() 

81 else: 

82 thisDate = str(row["dateCreated"])[:10] 

83 thisDate = khufu.coloredText( 

84 text="""(%(thisDate)s) """ % locals(), 

85 color="green", 

86 size=False, # 1-10 

87 pull=False, # "left" | "right" 

88 ) 

89 

90 commentRow = khufu.grid_row( 

91 responsive=True, 

92 columns="""%(author)s %(comment)s %(thisDate)s """ % locals(), 

93 htmlId=False, 

94 htmlClass=False, 

95 onPhone=True, 

96 onTablet=True, 

97 onDesktop=True 

98 ) 

99 

100 commentBlock = """%(commentBlock)s %(commentRow)s""" % locals() 

101 

102 return count, commentBlock