Test coverage report: frequently.models

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

Generated: Tue 2013-12-10 08:42 CET

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

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