Test coverage report: frequently.models

# frequently.models: 47 total statements, 97.3% covered

Generated: Fri 2013-09-20 15:24 CEST

Source file: /Users/martin/Repos/django-frequently/frequently/models.py

Stats: 36 executed, 1 missed, 10 excluded, 160 ignored

1. `"""Models for the ``frequently`` app."""`
2. `from django.db import models`
3. `from django.utils import timezone`
4. `from django.utils.translation import ugettext_lazy as _`
5. ``
6. `from cms.models import CMSPlugin`
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 EntryCategoryPlugin(CMSPlugin):`
53. `"""`
54. `CMS related Model to get a group of desired categories.`
55. ``
56. `:categories: Categories, which are selected by the cms user.`
57. ``
58. `"""`
59. `categories = models.ManyToManyField(`
60. `EntryCategory,`
61. `verbose_name=_('Categories'),`
62. `)`
63. ``
64. `def copy_relations(self, oldinstance):`
65. `self.categories = oldinstance.categories.all()`
66. ``
67. ``
68. `class Entry(models.Model):`
69. `"""`
70. `Entry model. Can be added to a category group.`
71. ``
72. `:owner: Foreign key to django auth user.`
73. `:category: Entry can appear in different categories.`
74. `:question: Title or question of the entry.`
75. `:slug: Slugified question of the category.`
76. `:answer: Answer or content of the entry.`
77. `:creation_date: Date of entry creation.`
78. `:last_view_date: Date of the last click/view.`
79. `:amount_of_views: Amount of views/clicks.`
80. `:fixed_position: Set a position to avoid ordering by views.`
81. `:upvotes: Positive vote amount for this entry.`
82. `:downvotes: Negative vote amount for this entry.`
83. `:published: Shows/hides entries.`
84. ``
85. `"""`
86. `owner = models.ForeignKey(`
87. `'auth.User',`
88. `verbose_name=_('Owner'),`
89. `blank=True, null=True,`
90. `)`
91. ``
92. `category = models.ManyToManyField(`
93. `EntryCategory,`
94. `verbose_name=_('Category'),`
95. `related_name='entries',`
96. `)`
97. ``
98. `question = models.CharField(`
99. `max_length=200,`
100. `verbose_name=_('Question'),`
101. `)`
102. ``
103. `slug = models.SlugField(`
104. `max_length=200,`
105. `unique=True,`
106. `verbose_name=_('Slug'),`
107. `)`
108. ``
109. `answer = models.TextField(`
110. `verbose_name=_('Answer'),`
111. `blank=True, null=True,`
112. `)`
113. ``
114. `creation_date = models.DateTimeField(`
115. `default=timezone.now(),`
116. `verbose_name=_('Creation date'),`
117. `)`
118. ``
119. `last_view_date = models.DateTimeField(`
120. `default=timezone.now(),`
121. `verbose_name=_('Date of last view'),`
122. `)`
123. ``
124. `amount_of_views = models.PositiveIntegerField(`
125. `default=0,`
126. `verbose_name=_('Amount of views'),`
127. `)`
128. ``
129. `fixed_position = models.PositiveIntegerField(`
130. `verbose_name=_('Fixed position'),`
131. `blank=True, null=True,`
132. `)`
133. ``
134. `upvotes = models.PositiveIntegerField(`
135. `default=0,`
136. `verbose_name=_('Upvotes'),`
137. `)`
138. ``
139. `downvotes = models.PositiveIntegerField(`
140. `default=0,`
141. `verbose_name=_('Downvotes'),`
142. `)`
143. ``
144. `published = models.BooleanField(`
145. `default=False,`
146. `verbose_name=_('is published'),`
147. `)`
148. ``
149. `submitted_by = models.EmailField(`
150. `max_length=100,`
151. `verbose_name=_('Submitted by'),`
152. `blank=True,`
153. `)`
154. ``
155. `class Meta:`
156. `ordering = ['fixed_position', 'question']`
157. ``
158. `def __unicode__(self):`
159. `return self.question`
160. ``
161. `def rating(self):`
162. `return self.upvotes - self.downvotes`
163. ``
164. ``
165. `class Feedback(models.Model):`
166. `"""`
167. `Feedback model to save and store user feedback related to an entry.`
168. ``
169. `This model can also be used to store general feedback.`
170. ``
171. `:user: Stores user if authenticated at submission.`
172. `:entry: Related entry.`
173. `:remark: User's feedback text.`
174. `:submission_date: Date of feedback creation.`
175. `:validation: Is this a positive or negative feedback.`
176. ``
177. `"""`
178. `user = models.ForeignKey(`
179. `'auth.User',`
180. `verbose_name=_('User'),`
181. `blank=True, null=True,`
182. `)`
183. ``
184. `entry = models.ForeignKey(`
185. `Entry,`
186. `verbose_name=_('Related entry'),`
187. `blank=True, null=True,`
188. `)`
189. ``
190. `remark = models.TextField(`
191. `verbose_name=_('Remark'),`
192. `blank=True,`
193. `)`
194. ``
195. `submission_date = models.DateTimeField(`
196. `default=timezone.now(),`
197. `verbose_name=_('Submission date'),`
198. `)`
199. ``
200. `validation = models.CharField(`
201. `max_length=1,`
202. `choices=(('P', _('Positive')), ('N', _('Negative'))),`
203. `verbose_name=_('Validation mood'),`
204. `)`
205. ``
206. `def __unicode__(self):`
207. `return "%s - %s" % (self.entry, self.submission_date)`