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# Imports 

2 

3from django.conf import settings 

4# from django.contrib.auth.models import Group 

5from django.db import models 

6# from django.utils.timezone import now 

7from django.utils.translation import gettext_lazy as _ 

8from superdjango.db.audit.models import AddedByModel, ModifiedByModel 

9from superdjango.db.datetime.fields import AutoNowAddDateTimeField, AutoNowDateTimeField 

10 

11# Exports 

12 

13__all__ = ( 

14 "HelpComment", 

15 "HelpRanking", 

16 "SearchCatalog", 

17 "SearchResult", 

18) 

19 

20# Constants 

21 

22AUTH_USER_MODEL = settings.AUTH_USER_MODEL 

23 

24# Models 

25 

26 

27class HelpComment(AddedByModel, ModifiedByModel): 

28 """A user comment on a specific help page.""" 

29 

30 body = models.TextField( 

31 _("body"), 

32 blank=True, 

33 help_text=_("The comment body."), 

34 null=True 

35 ) 

36 

37 page = models.CharField( 

38 _("page"), 

39 help_text=_("The page identifier where the comment was made."), 

40 max_length=256 

41 ) 

42 

43 subject = models.CharField( 

44 _("subject"), 

45 help_text=_("The title, question, or subject of the comment."), 

46 max_length=128 

47 ) 

48 

49 class Meta: 

50 verbose_name = _("Help Comment") 

51 verbose_name_plural = _("Help Comments") 

52 

53 def __str__(self): 

54 return self.subject 

55 

56 

57class HelpRanking(AddedByModel, ModifiedByModel): 

58 """A user ranking of the usefulness of a specific help page.""" 

59 

60 page = models.CharField( 

61 _("page"), 

62 help_text=_("The page identifier where the ranking was made."), 

63 max_length=256 

64 ) 

65 

66 score = models.PositiveSmallIntegerField( 

67 _("score"), 

68 help_text=_("The score."), 

69 ) 

70 

71 class Meta: 

72 verbose_name = _("Help Ranking") 

73 verbose_name_plural = _("Help Rankings") 

74 

75 def __str__(self): 

76 return str(self.score) 

77 

78 

79class SearchCatalog(models.Model): 

80 """Stores search terms, source files, and URLs used to create search results.""" 

81 

82 added_dt = AutoNowAddDateTimeField( 

83 _("added date/time"), 

84 help_text=_("Date and time the entry was created.") 

85 ) 

86 

87 modified_dt = AutoNowDateTimeField( 

88 _("modified date/time"), 

89 help_text=_("Date and time the entry was last modified.") 

90 ) 

91 

92 page = models.CharField( 

93 _("page"), 

94 help_text=_("The page identifier where the match was found."), 

95 max_length=256 

96 ) 

97 

98 source_file = models.CharField( 

99 _("source file"), 

100 help_text=_("The original source file/path where the search terms. Note this may change."), 

101 max_length=1024 

102 ) 

103 

104 terms = models.CharField( 

105 _("terms"), 

106 help_text=_("The matching search terms."), 

107 max_length=128 

108 ) 

109 

110 total_matches = models.PositiveSmallIntegerField( 

111 _("total matches"), 

112 help_text=_("The total number of matches on the page.") 

113 ) 

114 

115 class Meta: 

116 unique_together = ["page", "terms"] 

117 verbose_name = _("Search Catalog Entry") 

118 verbose_name_plural = _("Search Catalog Entries") 

119 

120 def __str__(self): 

121 return self.terms 

122 

123 

124class SearchResult(AddedByModel): 

125 """Optionally stores user search results. Useful for improving help and the search catalog.""" 

126 

127 added_dt = AutoNowAddDateTimeField( 

128 _("added date/time"), 

129 help_text=_("Date and time the entry was created.") 

130 ) 

131 

132 terms = models.CharField( 

133 _("terms"), 

134 help_text=_("The matching search terms."), 

135 max_length=128 

136 ) 

137 

138 total_matches = models.PositiveSmallIntegerField( 

139 _("total matches"), 

140 default=0, 

141 help_text=_("The total number of matches found for the search.") 

142 ) 

143 

144 class Meta: 

145 verbose_name = _("Help Comment") 

146 verbose_name_plural = _("Help Comments") 

147 

148 def __str__(self): 

149 return self.terms