Test coverage report: hero_slider.models

# hero_slider.models: 21 total statements, 100.0% covered

Generated: Thu 2013-04-18 14:15 SGT

Source file: /Users/martin/Repos/django-hero-slider/hero_slider/models.py

Stats: 14 executed, 0 missed, 7 excluded, 47 ignored

1. `"""Models for the ``hero_slider`` app."""`
2. `from django.contrib.contenttypes import generic`
3. `from django.contrib.contenttypes.models import ContentType`
4. `from django.db import models`
5. `from django.utils.translation import get_language`
6. `from django.utils.translation import ugettext_lazy as _`
7. ``
8. `from simple_translation.utils import get_preferred_translation_from_lang`
9. ``
10. ``
11. `from filer.fields.file import FilerFileField`
12. ``
13. ``
14. `class SliderItem(models.Model):`
15. `"""`
16. `Resembles an item that should be shown on the front page in a slider.`
17. ``
18. `For translateable fields see the ``SliderItemTitle`` model.`
19. ``
20. `:image: A filer file. This will be the image shown in the slider.`
21. `:position: Can be set in order to control the ordering of the slider items.`
22. `:content_type: The contenttype of the object this slider item links to.`
23. `:object_id: The PK of the object this slider item links to.`
24. ``
25. `"""`
26. `image = FilerFileField(`
27. `verbose_name=_('Image'),`
28. `)`
29. ``
30. `position = models.PositiveIntegerField(`
31. `verbose_name=_('Position'),`
32. `null=True, blank=True,`
33. `)`
34. ``
35. `# Generic foreign key`
36. `content_type = models.ForeignKey(ContentType)`
37. `object_id = models.PositiveIntegerField()`
38. `content_object = generic.GenericForeignKey('content_type', 'object_id')`
39. ``
40. `def get_trans(self):`
41. `"""Returns the translation object for this slider item."""`
42. `lang = get_language()`
43. `return get_preferred_translation_from_lang(self, lang)`
44. ``
45. ``
46. `class SliderItemTitle(models.Model):`
47. `"""`
48. `Translateable fields of the ``SliderItem`` model.`
49. ``
50. `:title: The title of this slider item.`
51. `:description: A short description of this slider item.`
52. ``
53. `"""`
54. `title = models.CharField(`
55. `max_length=256,`
56. `verbose_name=_('Title'),`
57. `blank=True,`
58. `)`
59. ``
60. `description = models.CharField(`
61. `max_length=512,`
62. `verbose_name=_('Description'),`
63. `blank=True,`
64. `)`
65. ``
66. `# Needed by simple-translation`
67. `slider_item = models.ForeignKey(SliderItem, verbose_name=_('Slider item'))`
68. `language = models.CharField(max_length=2, verbose_name=_('Language'))`