Test coverage report: frequently.models

# frequently.models: 44 total statements, 97.1% covered

Generated: Mon 2013-04-29 09:50 CEST

Source file: /home/tobi/Projects/django-frequently/src/frequently/models.py

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