Test coverage report: enquiry.models

# enquiry.models: 25 total statements, 81.2% covered

Generated: Tue 2013-02-05 19:07 SGT

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

Stats: 13 executed, 3 missed, 9 excluded, 72 ignored

1. `"""Models for the ``enquiry`` app."""`
2. `from django.conf import settings`
3. `from django.db import models`
4. `from django.utils.translation import get_language`
5. `from django.utils.translation import ugettext_lazy as _`
6. ``
7. `from simple_translation.utils import get_translation_queryset`
8. ``
9. ``
10. `class TransModelMixin(object):`
11. `"""Mixin that returns the translation object for a given parent model."""`
12. `def get_translation(self):`
13. `lang = get_language()`
14. `return get_translation_queryset(self).filter(language=lang)[0]`
15. ``
16. ``
17. `class Enquiry(TransModelMixin, models.Model):`
18. `"""`
19. `An enquiry has start and end dates and a question with several answers.`
20. ``
21. `For translateable fields see the ``EnquiryTrans`` model.`
22. ``
23. `:creation_date: The DateTime when this enquiry was created.`
24. `:created_by: The user who created this enquiry.`
25. `:start_date: The start date of this enquiry.`
26. `:end_date: The end date of this enquiry.`
27. `:allow_anonymous: If ``True`` anonymous user can participate, otherwise`
28. `users must be authenticated in order to vote.`
29. ``
30. `"""`
31. `def __unicode__(self):`
32. `return self.get_translation().question`
33. ``
34. ``
35. `class EnquiryTrans(models.Model):`
36. `"""`
37. `Translateable fields for the ``Enquiry`` model.`
38. ``
39. `:question: The title of this category.`
40. ``
41. `"""`
42. `# Needed by simple-translation`
43. `enquiry = models.ForeignKey(Enquiry, verbose_name=_('Enquiry'))`
44. `language = models.CharField(`
45. `max_length=2, verbose_name=_('Language'), choices=settings.LANGUAGES)`
46. ``
47. ``
48. `class Answer(models.Model):`
49. `"""`
50. `An answer belongs to an enquiry.`
51. ``
52. `For translateable fields see ``AnswerTrans`` model.`
53. ``
54. `:enquiry: FK to the enquiry this answer belongs to.`
55. ``
56. `"""`
57. `pass`
58. ``
59. `def __unicode__(self):`
60. `return self.get_translation().text`
61. ``
62. `def get_vote_count(self):`
63. `"""Returns the number of votes for this answer."""`
64. `pass`
65. ``
66. ``
67. `class AnswerTrans(models.Model):`
68. `"""`
69. `Translateable fields for the ``Answer`` model.`
70. ``
71. `:text: The text of this answer.`
72. ``
73. `"""`
74. `# Needed by simple-translation`
75. `answer = models.ForeignKey(Answer, verbose_name=_('Answer'))`
76. `language = models.CharField(`
77. `max_length=2, verbose_name=_('Language'), choices=settings.LANGUAGES)`
78. ``
79. ``
80. `class Vote(models.Model):`
81. `"""`
82. `A vote is being cast on an answer by a user.`
83. ``
84. `:answer: The answer this user has chosen.`
85. `:user: The user who cast this vote. Can be None if the user was anonymous.`
86. ``
87. `We also need to save something to identify anonymous users here. IP might`
88. `not be a good idea because those students might all access the portal`
89. `from within the campus and have the same IP.`
90. ``
91. `Maybe we are saving sessions in the database and we could save the session`
92. `PK here? But we are cleaning up the sessions regularily, so then the`
93. `PKs in this field would no longer be valid. Can't remember how we did this`
94. `with the FAQ app, please come up with a good idea.`
95. ``
96. `"""`
97. `pass`