Test coverage report: people.models

# people.models: 49 total statements, 57.1% covered

Generated: Fri 2015-05-29 13:58 AST

Source file: /home/quincy/Code/valuehorizon-people/people/models.py

Stats: 24 executed, 18 missed, 7 excluded, 50 ignored

1. `from django.db import models`
2. `from countries.models import Country`
3. ``
4. ``
5. ``
6. `class Person(models.Model):`
7. `"""`
8. `Represents a person, such as John Doe, Joe Public, or Jiminy Cricket.`
9. `"""`
10. ``
11. `GENDER_CHOICES = (`
12. `(u'M', u'Male'),`
13. `(u'F', u'Female'),`
14. `)`
15. `gender = models.CharField(max_length=1, choices=GENDER_CHOICES)`
16. ``
17. `TITLE_CHOICES = (`
18. `(u'DR', u'Dr.'),`
19. `(u'MR', u'Mr.'),`
20. `(u'MS', u'Ms.'),`
21. `(u'MRS', u'Mrs.'),`
22. `(u'SIR', u'Sir'),`
23. `(u'LORD', u'Lord'),`
24. `)`
25. `title = models.CharField(max_length=10, choices=TITLE_CHOICES)`
26. ``
27. `first_name = models.CharField(max_length=255)`
28. `last_name = models.CharField(max_length=255)`
29. `other_names = models.CharField(max_length=255, blank=True, help_text="Middle names, comma separated")`
30. `date_of_birth = models.DateField(null=True, blank=True)`
31. `date_of_death = models.DateField(null=True, blank=True)`
32. `profile = models.TextField(blank=True, help_text="Description of Person")`
33. `is_deceased = models.BooleanField(default=False)`
34. `nationality = models.ManyToManyField(Country, blank=True, null=True, related_name="nationalities")`
35. ``
36. `# Cached Data`
37. `full_name = models.CharField(max_length=255, blank=True, editable=False)`
38. `date_modified = models.DateTimeField(null=True, blank=True, editable=False, auto_now=True)`
39. `date_created = models.DateTimeField(null=True, blank=True, editable=False, auto_now_add=True)`
40. ``
41. `class Meta:`
42. `verbose_name_plural = 'People'`
43. `verbose_name = 'Person'`
44. `ordering = ['last_name', 'first_name', 'date_of_birth']`
45. ``
46. `def __unicode__(self):`
47. `return u'%s' % (unicode(self.full_name))`
48. ``
49. `def age(self):`
50. `from datetime import date`
51. `if self.date_of_birth != None:`
52. `today = date.today()`
53. `dob = self.date_of_birth`
54. `if (today.month > dob.month) and (today.day > dob.day):`
55. `return (today.year - dob.year)`
56. `else:`
57. `return ((today.year - dob.year) -1)`
58. `else:`
59. `return None`
60. ``
61. `def name(self):`
62. `"""`
63. `Return the person's name. If we have special titles, use them, otherwise,`
64. `don't include the title.`
65. `"""`
66. ``
67. `if self.title == "DR" or self.title == "SIR" or self.title == "LORD":`
68. `return str(self.get_title_display()) + " " + str(self.first_name) + " " + str(self.last_name)`
69. `else:`
70. `return str(self.first_name) + " " + str(self.last_name)`
71. ``
72. `def get_absolute_url(self):`
73. `return ('person_profile', (), { 'person_id': self.id})`
74. `get_absolute_url = models.permalink(get_absolute_url)`
75. ``
76. ``
77. ``
78. ``
79. `def save(self, *args, **kwargs):`
80. `"""`
81. `If date of death is specified, set is_deceased to true`
82. `"""`
83. `if self.date_of_death != None:`
84. `self.is_deceased = True`
85. ``
86. `# Since we often copy and paste from strange sources, do some basic cleanup`
87. `self.first_name = self.first_name.strip()`
88. `self.last_name = self.last_name.strip()`
89. `self.other_names = self.other_names.strip()`
90. `self.full_name = str(self.name())`
91. `self.profile = self.profile.encode('ascii', 'ignore').encode('utf8')`
92. ``
93. ``
94. `# Call save method`
95. `super(Person, self).save(*args, **kwargs) # Call the "real" save() method.`
96. ``
97. ``
98. ``
99. ``