Test coverage report: subscribe.templatetags.subscribe_tags

# subscribe.templatetags.subscribe_tags: 18 total statements, 93.3% covered

Generated: Sat 2013-04-06 17:51 SGT

Source file: /Users/martin/Repos/django-subscribe/subscribe/templatetags/subscribe_tags.py

Stats: 14 executed, 1 missed, 3 excluded, 36 ignored

1. `"""Templatetags for the ``subscribe`` app."""`
2. `from django import template`
3. `from django.contrib.contenttypes.models import ContentType`
4. ``
5. `from ..models import Subscription`
6. ``
7. ``
8. `register = template.Library()`
9. ``
10. ``
11. `@register.assignment_tag`
12. `def get_ctype(obj):`
13. `"""`
14. `Returns the ``ContentType`` for the given object.`
15. ``
16. `:param obj: Any object.`
17. ``
18. `"""`
19. `return ContentType.objects.get_for_model(obj)`
20. ``
21. ``
22. `@register.assignment_tag`
23. `def get_subscribers(obj):`
24. `"""`
25. `Returns the subscribers for a given object.`
26. ``
27. `:param obj: Any object.`
28. ``
29. `"""`
30. `ctype = ContentType.objects.get_for_model(obj)`
31. `return Subscription.objects.filter(content_type=ctype, object_id=obj.pk)`
32. ``
33. ``
34. `@register.assignment_tag`
35. `def is_subscribed(user, obj):`
36. `"""`
37. `Returns ``True`` if the user is subscribed to the given object.`
38. ``
39. `:param user: A ``User`` instance.`
40. `:param obj: Any object.`
41. ``
42. `"""`
43. `if not user.is_authenticated():`
44. `return False`
45. ``
46. `ctype = ContentType.objects.get_for_model(obj)`
47. ``
48. `try:`
49. `Subscription.objects.get(`
50. `user=user, content_type=ctype, object_id=obj.pk)`
51. `except Subscription.DoesNotExist:`
52. `return False`
53. ``
54. `return True`