Test coverage report: frequently.models

# frequently.models: 49 total statements, 100.0% covered

Generated: Fri 2015-09-11 18:53 CEST

Source file: /home/tyrdall/projects/django-frequently/src/frequently/models.py

Stats: 34 executed, 0 missed, 15 excluded, 154 ignored

1. `"""Models for the ``frequently`` app."""`
2. `from django.conf import settings`
3. `from django.core.urlresolvers import reverse`
4. `from django.db import models`
5. `from django.utils.translation import ugettext_lazy as _`
6. ``
7. `from ckeditor.fields import RichTextField`
8. ``
9. ``
10. `class EntryCategory(models.Model):`
11. `"""`
12. `Model to gather answers in topic groups.`
13. ``
14. `:name: Name or title of the category.`
15. `:slug: Slugified name of the category.`
16. `:fixed_position: Set a position to avoid ordering by views.`
17. `:last_rank: Last rank calculated at the category list view.`
18. ``
19. `"""`
20. `name = models.CharField(`
21. `max_length=100,`
22. `verbose_name=_('Name'),`
23. `)`
24. ``
25. `slug = models.SlugField(`
26. `max_length=100,`
27. `unique=True,`
28. `verbose_name=_('Slug'),`
29. `)`
30. ``
31. `fixed_position = models.PositiveIntegerField(`
32. `verbose_name=_('Fixed position'),`
33. `blank=True, null=True,`
34. `)`
35. ``
36. `last_rank = models.FloatField(`
37. `default=0,`
38. `verbose_name=_('Last calculated rank'),`
39. `)`
40. ``
41. `def __unicode__(self):`
42. `return self.name`
43. ``
44. `class Meta:`
45. `ordering = ['fixed_position', 'name']`
46. ``
47. `def get_entries(self):`
48. `return self.entries.filter(published=True).annotate(`
49. `null_position=models.Count('fixed_position')).order_by(`
50. `'-null_position', 'fixed_position', '-amount_of_views')`
51. ``
52. ``
53. `class Entry(models.Model):`
54. `"""`
55. `Entry model. Can be added to a category group.`
56. ``
57. `:owner: Foreign key to django auth user.`
58. `:category: Entry can appear in different categories.`
59. `:question: Title or question of the entry.`
60. `:slug: Slugified question of the category.`
61. `:answer: Answer or content of the entry.`
62. `:creation_date: Date of entry creation.`
63. `:last_view_date: Date of the last click/view.`
64. `:amount_of_views: Amount of views/clicks.`
65. `:fixed_position: Set a position to avoid ordering by views.`
66. `:upvotes: Positive vote amount for this entry.`
67. `:downvotes: Negative vote amount for this entry.`
68. `:published: Shows/hides entries.`
69. ``
70. `"""`
71. `owner = models.ForeignKey(`
72. `'auth.User',`
73. `verbose_name=_('Owner'),`
74. `blank=True, null=True,`
75. `)`
76. ``
77. `category = models.ManyToManyField(`
78. `EntryCategory,`
79. `verbose_name=_('Category'),`
80. `related_name='entries',`
81. `)`
82. ``
83. `question = models.TextField(`
84. `max_length=2000,`
85. `verbose_name=_('Question'),`
86. `)`
87. ``
88. `slug = models.SlugField(`
89. `max_length=200,`
90. `unique=True,`
91. `verbose_name=_('Slug'),`
92. `)`
93. ``
94. `answer = RichTextField(`
95. `verbose_name=_('Answer'),`
96. `blank=True,`
97. `)`
98. ``
99. `creation_date = models.DateTimeField(`
100. `auto_now_add=True,`
101. `verbose_name=_('Creation date'),`
102. `)`
103. ``
104. `last_view_date = models.DateTimeField(`
105. `auto_now_add=True,`
106. `verbose_name=_('Date of last view'),`
107. `)`
108. ``
109. `amount_of_views = models.PositiveIntegerField(`
110. `default=0,`
111. `verbose_name=_('Amount of views'),`
112. `)`
113. ``
114. `fixed_position = models.PositiveIntegerField(`
115. `verbose_name=_('Fixed position'),`
116. `blank=True, null=True,`
117. `)`
118. ``
119. `upvotes = models.PositiveIntegerField(`
120. `default=0,`
121. `verbose_name=_('Upvotes'),`
122. `)`
123. ``
124. `downvotes = models.PositiveIntegerField(`
125. `default=0,`
126. `verbose_name=_('Downvotes'),`
127. `)`
128. ``
129. `published = models.BooleanField(`
130. `default=False,`
131. `verbose_name=_('is published'),`
132. `)`
133. ``
134. `submitted_by = models.EmailField(`
135. `max_length=100,`
136. `verbose_name=_('Submitted by'),`
137. `blank=True,`
138. `)`
139. ``
140. `class Meta:`
141. `ordering = ['fixed_position', 'question']`
142. ``
143. `def __unicode__(self):`
144. `return self.question`
145. ``
146. `def get_absolute_url(self):`
147. `return reverse('frequently_entry_detail', kwargs={'slug': self.slug, })`
148. ``
149. `def rating(self):`
150. `return self.upvotes - self.downvotes`
151. ``
152. ``
153. `class Feedback(models.Model):`
154. `"""`
155. `Feedback model to save and store user feedback related to an entry.`
156. ``
157. `This model can also be used to store general feedback.`
158. ``
159. `:user: Stores user if authenticated at submission.`
160. `:entry: Related entry.`
161. `:remark: User's feedback text.`
162. `:submission_date: Date of feedback creation.`
163. `:validation: Is this a positive or negative feedback.`
164. ``
165. `"""`
166. `user = models.ForeignKey(`
167. `'auth.User',`
168. `verbose_name=_('User'),`
169. `blank=True, null=True,`
170. `)`
171. ``
172. `entry = models.ForeignKey(`
173. `Entry,`
174. `verbose_name=_('Related entry'),`
175. `blank=True, null=True,`
176. `)`
177. ``
178. `remark = models.TextField(`
179. `verbose_name=_('Remark'),`
180. `blank=True,`
181. `)`
182. ``
183. `submission_date = models.DateTimeField(`
184. `auto_now_add=True,`
185. `verbose_name=_('Submission date'),`
186. `)`
187. ``
188. `validation = models.CharField(`
189. `max_length=1,`
190. `choices=(('P', _('Positive')), ('N', _('Negative'))),`
191. `verbose_name=_('Validation mood'),`
192. `)`
193. ``
194. `def __unicode__(self):`
195. `return "%s - %s" % (self.entry, self.submission_date)`
196. ``
197. ``
198. `is_ready = getattr(settings, 'FREQUENTLY_READY_FOR_V1', False)`
199. `if not is_ready: # pragma: nocover`
200. `raise Exception(`
201. `'ERROR: There are backwards incompatible changes in django-frequently.'`
202. `' Please visit http://github.com/bitmazk/cmsplugin-frequently/ to'`
203. `' find out more')`